From 007b31f99233cdfa46c5e8f9eec4b2fd348c0eed Mon Sep 17 00:00:00 2001 From: richie Date: Thu, 12 Sep 2019 12:42:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=A7=E4=BB=B6=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fanruan/api/report/form/BaseWidget.java | 30 +++++++ .../form/CustomWriteAbleRepeatEditor.java | 10 --- .../api/report/form/category/TextWidget.java | 64 ++++++++++++++ .../form/describer/EditTextDescriber.java | 78 +++++++++++++++++ .../form/describer/RepeatDescriber.java | 51 ++++++++++++ .../report/form/describer/TextDescriber.java | 83 +++++++++++++++++++ 6 files changed, 306 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/fanruan/api/report/form/BaseWidget.java delete mode 100644 src/main/java/com/fanruan/api/report/form/CustomWriteAbleRepeatEditor.java create mode 100644 src/main/java/com/fanruan/api/report/form/category/TextWidget.java create mode 100644 src/main/java/com/fanruan/api/report/form/describer/EditTextDescriber.java create mode 100644 src/main/java/com/fanruan/api/report/form/describer/RepeatDescriber.java create mode 100644 src/main/java/com/fanruan/api/report/form/describer/TextDescriber.java diff --git a/src/main/java/com/fanruan/api/report/form/BaseWidget.java b/src/main/java/com/fanruan/api/report/form/BaseWidget.java new file mode 100644 index 0000000..c9100c2 --- /dev/null +++ b/src/main/java/com/fanruan/api/report/form/BaseWidget.java @@ -0,0 +1,30 @@ +package com.fanruan.api.report.form; + +import com.fr.data.act.Describer; +import com.fr.form.ui.Widget; +import com.fr.json.JSONException; +import com.fr.json.JSONObject; +import com.fr.script.Calculator; +import com.fr.stable.core.NodeVisitor; +import com.fr.stable.web.Repository; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-09-10 + * 控件的插件接口 + */ +public abstract class BaseWidget extends Widget implements Describer { + + @Override + public boolean isEditor() { + return false; + } + + @Override + public JSONObject createJSONConfig(Repository repository, Calculator calculator, NodeVisitor nodeVisitor) throws JSONException { + JSONObject jo = super.createJSONConfig(repository, calculator, nodeVisitor); + mixinJSON(repository, calculator, jo); + return jo; + } +} diff --git a/src/main/java/com/fanruan/api/report/form/CustomWriteAbleRepeatEditor.java b/src/main/java/com/fanruan/api/report/form/CustomWriteAbleRepeatEditor.java deleted file mode 100644 index 42de2d0..0000000 --- a/src/main/java/com/fanruan/api/report/form/CustomWriteAbleRepeatEditor.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.fanruan.api.report.form; - -/** - * 允许自定义值的、允许直接编辑的、带重复的 --- 下拉框 下拉复选框 下拉树 - * @author Kalven - * @version 10.0 - * Created by Kalven on 2019/9/4 - */ -public abstract class CustomWriteAbleRepeatEditor extends com.fr.form.ui.CustomWriteAbleRepeatEditor { -} diff --git a/src/main/java/com/fanruan/api/report/form/category/TextWidget.java b/src/main/java/com/fanruan/api/report/form/category/TextWidget.java new file mode 100644 index 0000000..4caab03 --- /dev/null +++ b/src/main/java/com/fanruan/api/report/form/category/TextWidget.java @@ -0,0 +1,64 @@ +package com.fanruan.api.report.form.category; + +import com.fanruan.api.report.form.BaseWidget; +import com.fanruan.api.report.form.describer.TextDescriber; +import com.fanruan.api.util.ArrayKit; +import com.fanruan.api.xml.XmlKit; +import com.fr.stable.script.CalculatorProvider; +import com.fr.stable.xml.XMLPrintWriter; +import com.fr.stable.xml.XMLableReader; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-09-10 + */ +public abstract class TextWidget extends BaseWidget { + + private TextDescriber textDescriber; + + /** + * 获取联动参数 + * + * @param c 当前算子 + * @return 放回当前控件依赖的参数 + */ + public String[] dependence(CalculatorProvider c) { + return ArrayKit.EMPTY_STRING_ARRAY; + } + + /** + * 获取支持的事件 + * + * @return 当前控件支持的事件 + */ + public String[] supportedEvents() { + return new String[]{AFTERINIT, BEFOREEDIT, AFTEREDIT, STOPEDIT}; + } + + @Override + public void readXML(XMLableReader reader) { + if (reader.isChildNode()) { + String tagName = reader.getTagName(); + if (TextDescriber.XML_TAG.equals(tagName)) { + textDescriber = (TextDescriber) XmlKit.readXMLable(reader); + } + } + } + + @Override + public void writeXML(XMLPrintWriter writer) { + if (textDescriber != null) { + XmlKit.writeXMLable(writer, textDescriber, TextDescriber.XML_TAG); + } + } + + @Override + public Object clone() throws CloneNotSupportedException { + TextWidget cloned = (TextWidget) super.clone(); + if (textDescriber != null) { + cloned.textDescriber = (TextDescriber) textDescriber.clone(); + } + return cloned; + } +} diff --git a/src/main/java/com/fanruan/api/report/form/describer/EditTextDescriber.java b/src/main/java/com/fanruan/api/report/form/describer/EditTextDescriber.java new file mode 100644 index 0000000..1b01cfb --- /dev/null +++ b/src/main/java/com/fanruan/api/report/form/describer/EditTextDescriber.java @@ -0,0 +1,78 @@ +package com.fanruan.api.report.form.describer; + +import com.fanruan.api.cal.FormulaKit; +import com.fanruan.api.log.LogKit; +import com.fanruan.api.util.GeneralKit; +import com.fanruan.api.util.StringKit; +import com.fr.data.act.Describer; +import com.fr.json.JSONObject; +import com.fr.stable.script.CalculatorProvider; +import com.fr.stable.web.Repository; +import com.fr.stable.xml.XMLPrintWriter; +import com.fr.stable.xml.XMLable; +import com.fr.stable.xml.XMLableReader; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-09-10 + */ +public class EditTextDescriber implements Describer, XMLable { + + public static final String XML_TAG = "EditTextDescriber"; + + private boolean directEdit = true; + + private String waterMark; + + public EditTextDescriber() { + + } + + public boolean isDirectEdit() { + return this.directEdit; + } + + public void setDirectEdit(boolean directEdit) { + this.directEdit = directEdit; + } + + public void setWaterMark(String waterMark) { + this.waterMark = waterMark; + } + + public String getWaterMark() { + return waterMark; + } + + @Override + public void mixinJSON(Repository repo, CalculatorProvider c, JSONObject jo) { + jo.put("directEdit", directEdit); + if (StringKit.isNotBlank(waterMark)) { + if (FormulaKit.canBeFormula(waterMark)) { + try { + jo.put("watermark", GeneralKit.objectToString(FormulaKit.newFormula(waterMark).eval(c))); + } catch (Exception e) { + LogKit.error(e.getMessage(), e); + } + } else { + jo.put("watermark", waterMark); + } + } + } + + @Override + public void readXML(XMLableReader xmLableReader) { + + } + + @Override + public void writeXML(XMLPrintWriter xmlPrintWriter) { + + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } +} diff --git a/src/main/java/com/fanruan/api/report/form/describer/RepeatDescriber.java b/src/main/java/com/fanruan/api/report/form/describer/RepeatDescriber.java new file mode 100644 index 0000000..89ebee4 --- /dev/null +++ b/src/main/java/com/fanruan/api/report/form/describer/RepeatDescriber.java @@ -0,0 +1,51 @@ +package com.fanruan.api.report.form.describer; + +import com.fr.data.act.Describer; +import com.fr.json.JSONObject; +import com.fr.stable.script.CalculatorProvider; +import com.fr.stable.web.Repository; +import com.fr.stable.xml.XMLPrintWriter; +import com.fr.stable.xml.XMLable; +import com.fr.stable.xml.XMLableReader; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-09-10 + */ +public class RepeatDescriber implements Describer, XMLable { + + public static final String XML_TAG = "RepeatDescriber"; + + private boolean removeRepeat = true; + + public boolean isRemoveRepeat() { + return this.removeRepeat; + } + + public void setRemoveRepeat(boolean removeRepeat) { + this.removeRepeat = removeRepeat; + } + + @Override + public void mixinJSON(Repository repo, CalculatorProvider c, JSONObject jo) { + if (removeRepeat) { + jo.put("norepeat", true); + } + } + + @Override + public void readXML(XMLableReader xmLableReader) { + + } + + @Override + public void writeXML(XMLPrintWriter xmlPrintWriter) { + + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } +} diff --git a/src/main/java/com/fanruan/api/report/form/describer/TextDescriber.java b/src/main/java/com/fanruan/api/report/form/describer/TextDescriber.java new file mode 100644 index 0000000..2a817e1 --- /dev/null +++ b/src/main/java/com/fanruan/api/report/form/describer/TextDescriber.java @@ -0,0 +1,83 @@ +package com.fanruan.api.report.form.describer; + +import com.fanruan.api.util.StringKit; +import com.fr.data.act.Describer; +import com.fr.json.JSONObject; +import com.fr.stable.StringUtils; +import com.fr.stable.script.CalculatorProvider; +import com.fr.stable.web.Repository; +import com.fr.stable.xml.XMLPrintWriter; +import com.fr.stable.xml.XMLable; +import com.fr.stable.xml.XMLableReader; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-09-10 + */ +public class TextDescriber implements Describer, XMLable { + + public static final String XML_TAG = "TextDescriber"; + + private boolean allowBlank = true; + private String errorMessage; + private int fontSize = 12; + + public TextDescriber() { + + } + + public TextDescriber(boolean allowBlank) { + this.allowBlank = allowBlank; + } + + public boolean isAllowBlank() { + return this.allowBlank; + } + + public void setAllowBlank(boolean allowBlank) { + this.allowBlank = allowBlank; + } + + public int getFontSize() { + return this.fontSize; + } + + public void setFontSize(int size) { + this.fontSize = size; + } + + public String getErrorMessage() { + return errorMessage == null ? StringUtils.EMPTY : errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + @Override + public void readXML(XMLableReader xmLableReader) { + + } + + @Override + public void writeXML(XMLPrintWriter xmlPrintWriter) { + + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + @Override + public void mixinJSON(Repository repo, CalculatorProvider c, JSONObject jo) { + if (!allowBlank) { + jo.put("allowBlank", true); + } + if (StringKit.isNotEmpty(errorMessage)) { + jo.put("errorMessage", errorMessage); + } + jo.put("fontSize", this.fontSize); + } +}