package com.axelor.meta.views;

import java.util.List;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;

@XmlType
@XmlTransient
@JsonTypeInfo(use = Id.NAME, include = As.PROPERTY, property = "viewType")
@JsonInclude(Include.NON_NULL)
@JsonSubTypes({
	@Type(GridView.class),
	@Type(FormView.class),
	@Type(TreeView.class),
	@Type(Portal.class),
	@Type(Search.class)
})
public abstract class AbstractView {

	@XmlAttribute
	private String name;
	
	@XmlAttribute
	private String title;
	
	@XmlAttribute
	private String model;
	
	@XmlAttribute
	private Boolean editable;
	
	@XmlElementWrapper
	@XmlElement(name = "button")
	private List<Button> toolbar;

	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getTitle() {
		return title;
	}
	
	public void setTitle(String title) {
		this.title = title;
	}
	
	public String getModel() {
		return model;
	}
	
	public void setModel(String model) {
		this.model = model;
	}
	
	public Boolean getEditable() {
		return editable;
	}
	
	public void setEditable(Boolean editable) {
		this.editable = editable;
	}
	
	public List<Button> getToolbar() {
		return toolbar;
	}
	
	public void setToolbar(List<Button> toolbar) {
		this.toolbar = toolbar;
	}
}

@@ -682,31 +682,71 @@
 Id;%0A
-%0A@XmlType%0A@XmlTransient
+import com.fasterxml.jackson.annotation.JsonTypeName;%0A%0A@XmlType
 %0A@Js
@@ -810,13 +810,9 @@
  = %22
-viewT
+t
 ype%22
@@ -1867,10 +1867,174 @@
 bar;%0A%09%7D%0A
+%09%0A%09@XmlTransient%0A%09public String getType() %7B%0A%09%09try %7B%0A%09%09%09return getClass().getAnnotation(JsonTypeName.class).value();%0A%09%09%7D catch(Exception e)%7B%7D%0A%09%09return %22unknown%22;%0A%09%7D%0A
 %7D%0A

Include type info.