Browse Source

新增控件接口

master
richie 5 years ago
parent
commit
007b31f992
  1. 30
      src/main/java/com/fanruan/api/report/form/BaseWidget.java
  2. 10
      src/main/java/com/fanruan/api/report/form/CustomWriteAbleRepeatEditor.java
  3. 64
      src/main/java/com/fanruan/api/report/form/category/TextWidget.java
  4. 78
      src/main/java/com/fanruan/api/report/form/describer/EditTextDescriber.java
  5. 51
      src/main/java/com/fanruan/api/report/form/describer/RepeatDescriber.java
  6. 83
      src/main/java/com/fanruan/api/report/form/describer/TextDescriber.java

30
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;
}
}

10
src/main/java/com/fanruan/api/report/form/CustomWriteAbleRepeatEditor.java

@ -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 {
}

64
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;
}
}

78
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();
}
}

51
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();
}
}

83
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);
}
}
Loading…
Cancel
Save