|
|
|
package com.fr.plugin.widget.ztree.core;
|
|
|
|
|
|
|
|
import com.fanruan.api.i18n.I18nKit;
|
|
|
|
import com.fanruan.api.json.JSONKit;
|
|
|
|
import com.fanruan.api.net.NetworkKit;
|
|
|
|
import com.fanruan.api.report.form.CustomWriteAbleRepeatEditor;
|
|
|
|
import com.fanruan.api.runtime.PluginKit;
|
|
|
|
import com.fanruan.api.xml.XmlKit;
|
|
|
|
import com.fr.form.ui.DataControl;
|
|
|
|
import com.fr.form.ui.WidgetValue;
|
|
|
|
import com.fr.intelli.record.Focus;
|
|
|
|
import com.fr.json.JSONArray;
|
|
|
|
import com.fr.json.JSONException;
|
|
|
|
import com.fr.json.JSONObject;
|
|
|
|
import com.fr.record.analyzer.EnableMetrics;
|
|
|
|
import com.fr.script.Calculator;
|
|
|
|
import com.fr.stable.core.NodeVisitor;
|
|
|
|
import com.fr.stable.web.Repository;
|
|
|
|
import com.fr.stable.web.SessionProvider;
|
|
|
|
import com.fr.stable.xml.XMLPrintWriter;
|
|
|
|
import com.fr.stable.xml.XMLableReader;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by richie on 15/11/17.
|
|
|
|
*/
|
|
|
|
@EnableMetrics
|
|
|
|
public class ZTree extends CustomWriteAbleRepeatEditor implements DataControl {
|
|
|
|
|
|
|
|
private WidgetValue widgetValue;
|
|
|
|
|
|
|
|
private ZTreeNode treeNode;
|
|
|
|
|
|
|
|
private ZTreeAttr treeAttr = new ZTreeAttr();
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getFormatText() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getDataBindDefaultValue(Calculator calculator) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 控件初始值的可能类型
|
|
|
|
*
|
|
|
|
* @return 多种类型组成的数组
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public int[] getValueType() {
|
|
|
|
return new int[]{TYPE_STRING, TYPE_DATABINDING, TYPE_FORMULA};
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String[] supportedEvents() {
|
|
|
|
return new String[]{AFTEREDIT};
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setWidgetValue(WidgetValue value) {
|
|
|
|
widgetValue = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public WidgetValue getWidgetValue() {
|
|
|
|
return widgetValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ZTreeNode getTreeNode() {
|
|
|
|
return treeNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTreeNode(ZTreeNode treeNode) {
|
|
|
|
this.treeNode = treeNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSelectStyle(ZTreeStyle style) {
|
|
|
|
treeAttr.setCheckStyle(style);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ZTreeStyle getSelectStyle() {
|
|
|
|
return treeAttr.getCheckStyle();
|
|
|
|
}
|
|
|
|
|
|
|
|
public ZTreeCascade getCascade() {
|
|
|
|
return treeAttr.getCascade();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCascade(ZTreeCascade cascade) {
|
|
|
|
treeAttr.setCascade(cascade);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getPopupHeight() {
|
|
|
|
return treeAttr.getPopupHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPopupHeight(int popupHeight) {
|
|
|
|
treeAttr.setPopupHeight(popupHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void createValueResult(DataControl widget, Calculator widgetCalculator, JSONObject widgetResult, JSONObject attrSourceCache) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getXType() {
|
|
|
|
return "ztree";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Focus(id = "com.fr.plugin.widget.ztree", text = "Plugin-ZTree")
|
|
|
|
public JSONObject createJSONConfig(Repository repo, Calculator c, NodeVisitor toFindChart) throws JSONException {
|
|
|
|
JSONObject conf = super.createJSONConfig(repo, c, toFindChart);
|
|
|
|
if (treeAttr != null) {
|
|
|
|
treeAttr.mixConfig(conf);
|
|
|
|
}
|
|
|
|
return conf;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public JSONArray createJSONData(SessionProvider sessionIDInfor, Calculator c, HttpServletRequest req) {
|
|
|
|
if (treeNode == null) {
|
|
|
|
return JSONKit.createJSONArray();
|
|
|
|
}
|
|
|
|
if ((PluginKit.isCurrentPluginAvailable())) {
|
|
|
|
String pv = NetworkKit.getHTTPRequestParameter(req, "pv");
|
|
|
|
int level = NetworkKit.getHTTPRequestIntParameter(req, "level", ZTreeNode.ROOT_LEVEL);
|
|
|
|
String text = NetworkKit.getHTTPRequestParameter(req, "text");
|
|
|
|
String value = NetworkKit.getHTTPRequestParameter(req, "value");
|
|
|
|
boolean checked = NetworkKit.getHTTPRequestBoolParameter(req, "checked");
|
|
|
|
ZTreeNode node = treeNode.findNode(level);
|
|
|
|
if (node != null) {
|
|
|
|
return node.toJSONArray(c, level, text, value, pv, checked && treeAttr.getCascade().isCascade());
|
|
|
|
} else {
|
|
|
|
return new JSONArray();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
JSONArray errorMsg = JSONKit.createJSONArray();
|
|
|
|
errorMsg.put(JSONKit.create().put("text", I18nKit.getLocText("Plugin-ZTree_License_Expired")).put("value", I18nKit.getLocText("Plugin-ZTree_License_Expired")));
|
|
|
|
return errorMsg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readXML(XMLableReader reader) {
|
|
|
|
super.readXML(reader);
|
|
|
|
if (reader.isChildNode()) {
|
|
|
|
String tagName = reader.getTagName();
|
|
|
|
if (ZTreeNode.XML_TAG.equals(tagName)) {
|
|
|
|
treeNode = (ZTreeNode) XmlKit.readXMLable(reader);
|
|
|
|
} else if (ZTreeAttr.XML_TAG.equals(tagName)) {
|
|
|
|
treeAttr = (ZTreeAttr) XmlKit.readXMLable(reader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeXML(XMLPrintWriter writer) {
|
|
|
|
super.writeXML(writer);
|
|
|
|
if (treeNode != null) {
|
|
|
|
XmlKit.writeXMLable(writer, treeNode, ZTreeNode.XML_TAG);
|
|
|
|
}
|
|
|
|
if (treeAttr != null) {
|
|
|
|
XmlKit.writeXMLable(writer, treeAttr, ZTreeAttr.XML_TAG);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|