这是一个插件控件的开发示例,实现了一个基于ztree的参数树控件。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

97 lines
2.6 KiB

package com.fr.plugin.widget.ztree.core;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;
import com.fr.stable.xml.XMLable;
/**
* Created by richie on 15/11/18.
*/
public class ZTreeAttr implements XMLable {
public static final String XML_TAG = "ZTreeAttr";
private static final int DEFAULT_POPUP_HEIGHT = 240;
private ZTreeStyle style = ZTreeStyle.NONE;
private ZTreeCascade cascade = ZTreeCascade.DESCENDANT;
private int popupHeight = DEFAULT_POPUP_HEIGHT;
public ZTreeAttr() {
}
public ZTreeStyle getCheckStyle() {
return style;
}
public void setCheckStyle(ZTreeStyle checkStyle) {
this.style = checkStyle;
}
public ZTreeCascade getCascade() {
return cascade;
}
public void setCascade(ZTreeCascade cascade) {
this.cascade = cascade;
}
public int getPopupHeight() {
return popupHeight;
}
public void setPopupHeight(int popupHeight) {
this.popupHeight = popupHeight;
}
public void mixConfig(JSONObject jo) throws JSONException {
JSONObject settings = new JSONObject();
settings.put("data", new JSONObject().put("key", new JSONObject().put("name", "text")));
settings.put("check", new JSONObject().put("enable", style!= ZTreeStyle.NONE).put("chkStyle", style.toText()));
jo.put("setting", settings);
jo.put("cascade", cascade.toText());
jo.put("directEdit", false);
jo.put("popupHeight", popupHeight);
}
@Override
public void readXML(XMLableReader reader) {
if (reader.isChildNode()) {
String tagName = reader.getTagName();
if (tagName.equals("Attr")) {
style = ZTreeStyle.parser(reader.getAttrAsString("style", ""));
cascade = ZTreeCascade.parser(reader.getAttrAsString("cascade", ""));
popupHeight = reader.getAttrAsInt("popupHeight", DEFAULT_POPUP_HEIGHT);
}
}
}
@Override
public void writeXML(XMLPrintWriter writer) {
writer.startTAG("Attr");
if (style != ZTreeStyle.NONE) {
writer.attr("style", style.toText());
}
writer.attr("cascade", cascade.toText());
writer.attr("popupHeight", popupHeight);
writer.end();
}
@Override
public Object clone() throws CloneNotSupportedException {
ZTreeAttr cloned = (ZTreeAttr) super.clone();
cloned.style = style;
cloned.cascade = cascade;
cloned.popupHeight = popupHeight;
return super.clone();
}
}