From 9763c1be29837d7e3511cdcda861041c4c6e2bf4 Mon Sep 17 00:00:00 2001 From: richie Date: Sun, 12 Jun 2016 13:02:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A1=AB=E6=8A=A5=E6=A0=A1=E9=AA=8C=E6=94=B9?= =?UTF-8?q?=E8=BF=9B,designer=E6=9A=82=E6=97=B6=E4=BE=9D=E8=B5=96engine-wr?= =?UTF-8?q?ite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- designer/designer.iml | 1 + .../fr/design/report/BuildInVerifierPane.java | 35 ++++++ .../fr/design/report/CustomVerifierPane.java | 37 ++++++ .../design/report/ValueVerifierEditPane.java | 113 +++--------------- .../fr/design/report/VerifierListPane.java | 2 +- 5 files changed, 92 insertions(+), 96 deletions(-) create mode 100644 designer/src/com/fr/design/report/BuildInVerifierPane.java create mode 100644 designer/src/com/fr/design/report/CustomVerifierPane.java diff --git a/designer/designer.iml b/designer/designer.iml index c798a6fe0..796f2413b 100644 --- a/designer/designer.iml +++ b/designer/designer.iml @@ -17,5 +17,6 @@ + \ No newline at end of file diff --git a/designer/src/com/fr/design/report/BuildInVerifierPane.java b/designer/src/com/fr/design/report/BuildInVerifierPane.java new file mode 100644 index 000000000..895b7fb34 --- /dev/null +++ b/designer/src/com/fr/design/report/BuildInVerifierPane.java @@ -0,0 +1,35 @@ +package com.fr.design.report; + +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.report.write.ValueVerifier; + +import java.awt.*; + +/** + * Created by richie on 16/6/12. + */ +public class BuildInVerifierPane extends BasicBeanPane { + private ValueVerifierEditPane valueVerifierEditPane; + + public BuildInVerifierPane() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + valueVerifierEditPane = new ValueVerifierEditPane(); + this.add(valueVerifierEditPane, BorderLayout.CENTER); + } + + @Override + public void populateBean(ValueVerifier ob) { + valueVerifierEditPane.populate(ob); + } + + @Override + public ValueVerifier updateBean() { + return valueVerifierEditPane.update(); + } + + @Override + protected String title4PopupWindow() { + return "BuiltIn"; + } +} diff --git a/designer/src/com/fr/design/report/CustomVerifierPane.java b/designer/src/com/fr/design/report/CustomVerifierPane.java new file mode 100644 index 000000000..99cadedd5 --- /dev/null +++ b/designer/src/com/fr/design/report/CustomVerifierPane.java @@ -0,0 +1,37 @@ +package com.fr.design.report; + +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.report.write.WClassVerifier; + +import java.awt.*; + +/** + * Created by richie on 16/6/12. + */ +public class CustomVerifierPane extends BasicBeanPane { + private CustomVerifyJobPane pane; + + public CustomVerifierPane() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + pane = new CustomVerifyJobPane(); + this.add(pane, BorderLayout.CENTER); + } + + @Override + public void populateBean(WClassVerifier ob) { + this.pane.populateBean(ob.getClassVerifyJob()); + } + + @Override + public WClassVerifier updateBean() { + WClassVerifier verifier = new WClassVerifier(); + verifier.setClassVerifyJob(this.pane.updateBean()); + return verifier; + } + + @Override + protected String title4PopupWindow() { + return "custom"; + } +} diff --git a/designer/src/com/fr/design/report/ValueVerifierEditPane.java b/designer/src/com/fr/design/report/ValueVerifierEditPane.java index 497d7abda..09da8b85f 100644 --- a/designer/src/com/fr/design/report/ValueVerifierEditPane.java +++ b/designer/src/com/fr/design/report/ValueVerifierEditPane.java @@ -2,11 +2,15 @@ package com.fr.design.report; import com.fr.base.Formula; import com.fr.data.Verifier; +import com.fr.data.VerifyItem; import com.fr.design.gui.itableeditorpane.ActionStyle; import com.fr.design.gui.itableeditorpane.UIArrayTableModel; import com.fr.design.gui.itableeditorpane.UITableEditorPane; import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.general.GeneralUtils; import com.fr.general.Inter; +import com.fr.report.write.ValueVerifier; +import com.fr.stable.FormulaProvider; import com.fr.stable.bridge.StableFactory; import com.fr.write.ReportWriteAttrProvider; import com.fr.write.ValueVerifierProvider; @@ -32,116 +36,35 @@ public class ValueVerifierEditPane extends JPanel { /** * populate */ - public void populate(ReportWriteAttrProvider reportWriteAttr) { - if (reportWriteAttr == null) { + public void populate(ValueVerifier valueVerifier) { + if (valueVerifier == null) { return; } - int rowCount = reportWriteAttr.getVerifierCount(); - Object[][] os = new Object[reportWriteAttr.getValueVerifierCount()][]; - int cnt = 0; - for (int i = 0; i < rowCount; i++) { - if (!(reportWriteAttr.getVerifier(i) instanceof ValueVerifierProvider)) { - continue; - } - Formula formula = ((ValueVerifierProvider)reportWriteAttr.getVerifier(i)).getFormula(); + int rowCount = valueVerifier.getVerifyItemsCount(); + Object[][] os = new Object[rowCount][]; + int tableDataCount = 0; + for (int i = 0; i < rowCount; i ++) { + VerifyItem item = valueVerifier.getVerifyItem(i); + FormulaProvider formula = item.getFormula(); if (formula == null) { continue; } - String formulaContent = formula.getContent().substring(1); - String message = reportWriteAttr.getVerifier(i).getMessage(); - os[cnt++] = new Object[] { formulaContent, message }; + os[tableDataCount++] = new Object[]{formula.getPureContent(), item.getMessage()}; } this.tableEditorPane.populate(os); } - /** - * update - */ - public void update(ReportWriteAttrProvider reportWriteAttr, String name) { + public ValueVerifier update() { + ValueVerifier valueVerifier = new ValueVerifier(); java.util.List list = tableEditorPane.update(); - reportWriteAttr.clearVerifiers(true); for (int i = 0; i < list.size(); i++) { Object[] o = list.get(i); if (o == null || o[0] == null) { continue; } - ValueVerifierProvider p = StableFactory.getMarkedInstanceObjectFromClass(ValueVerifierProvider.TAG, ValueVerifierProvider.class); - p.setFormula(new Formula(readValueVerifyObject(o[0]))); - p.setMessage(readValueVerifyObject(o[1])); - reportWriteAttr.addVerifier(name, (Verifier) p); -// reportWriteAttr.addVerifier(name, new ValueVerifier(readValueVerifyObject(o[0]), readValueVerifyObject(o[1]))); + VerifyItem item = new VerifyItem(new Formula(GeneralUtils.objectToString(o[0])), GeneralUtils.objectToString(o[1])); + valueVerifier.addVerifyItem(item); } - } - - private String readValueVerifyObject(Object obj) { - if (obj == null) { - return null; - } - return obj.toString(); + return valueVerifier; } } - - -//public class ValueVerifierEditPane extends BasicBeanPane { -// private ValueVerifier valueVerifier; -// private UITextArea formula = new UITextArea(); -// private UITextArea message = new UITextArea(); -// private int col = 60; -// private int row = 5; -// -// public ValueVerifierEditPane() { -// valueVerifier = new ValueVerifier(); -// -// this.setLayout(new FlowLayout()); -// -// JPanel formulaPane = new JPanel(); -// UIScrollPane formulaScrollPane = new UIScrollPane(formula); -// formula.setRows(row); -// formula.setColumns(col); -// formula.setLineWrap(true); -// formula.setToolTipText(Inter.getLocText("Verify-ToolTips")); -// UILabel fl = new UILabel(Inter.getLocText("Verify-Verify_Formula")); -// fl.setPreferredSize(new Dimension(80, 20)); -// formulaPane.add(fl); -// formulaPane.add(formulaScrollPane); -// -// JPanel messagePane = new JPanel(); -// UIScrollPane messageScrollPane = new UIScrollPane(message); -// message.setRows(row); -// message.setColumns(col); -// message.setLineWrap(true); -// UILabel ml = new UILabel(Inter.getLocText("Verify-Error_Information")); -// ml.setPreferredSize(new Dimension(80, 20)); -// messagePane.add(ml); -// messagePane.add(messageScrollPane); -// -// this.add(formulaPane); -// this.add(messagePane); -// } -// -// @Override -// public void populateBean(ValueVerifier ob) { -// valueVerifier = ob; -// if (ob != null) { -// if (ob.getFormula() != null) { -// String content = ob.getFormula().getContent(); -// formula.setText(content.startsWith("=") ? content.substring(1) : content); -// } else { -// formula.setText(""); -// } -// message.setText(ob.getMessage()); -// } -// } -// -// @Override -// public ValueVerifier updateBean() { -// valueVerifier.setFormula(new Formula(formula.getText())); -// valueVerifier.setMessage(message.getText()); -// return valueVerifier; -// } -// -// @Override -// protected String title4PopupWindow() { -// return "valueVerifierPane"; -// } -//} \ No newline at end of file diff --git a/designer/src/com/fr/design/report/VerifierListPane.java b/designer/src/com/fr/design/report/VerifierListPane.java index e48995324..939de1ff4 100644 --- a/designer/src/com/fr/design/report/VerifierListPane.java +++ b/designer/src/com/fr/design/report/VerifierListPane.java @@ -1 +1 @@ -package com.fr.design.report; import com.fr.data.Verifier; import com.fr.design.ExtraDesignClassManager; import com.fr.design.beans.BasicBeanPane; import com.fr.design.fun.VerifyDefineProvider; import com.fr.design.gui.controlpane.NameObjectCreator; import com.fr.design.gui.controlpane.NameableCreator; import com.fr.design.gui.controlpane.ObjectJControlPane; import com.fr.design.gui.ilist.JNameEdList; import com.fr.design.gui.ilist.ListModelElement; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.ElementCasePane; import com.fr.general.Inter; import com.fr.general.NameObject; import com.fr.stable.ArrayUtils; import com.fr.stable.Nameable; import com.fr.stable.bridge.StableFactory; import com.fr.write.ReportWriteAttrProvider; import com.fr.write.ValueVerifierProvider; import com.fr.write.WClassVerifierProvider; import javax.swing.*; import java.awt.*; import java.util.ArrayList; /** * Author : Shockway * Date: 13-7-29 * Time: 下午5:11 */ public class VerifierListPane extends ObjectJControlPane { public VerifierListPane(ElementCasePane ePane) { super(ePane); } /** * 创建选项 * * @return 选项 */ public NameableCreator[] createNameableCreators() { NameableCreator[] creators = new NameableCreator[]{ new NameObjectCreator(Inter.getLocText(new String[]{"BuildIn", "Verify"}), "/com/fr/web/images/reportlet.png", StableFactory.getRegisteredClass(ReportWriteAttrProvider.XML_TAG), BuildInVerifierPane.class) }; for (VerifyDefineProvider provider : ExtraDesignClassManager.getInstance().getVerifyDefineProviders()) { creators = ArrayUtils.add(creators, new NameObjectCreator( provider.nameForVerifier(), provider.iconPath(), provider.classForVerifier(), provider.appearanceForVerifier() ) { }); } creators = ArrayUtils.add(creators, new NameObjectCreator( Inter.getLocText(new String[]{"Custom", "Verify"}), "/com/fr/web/images/reportlet.png", StableFactory.getRegisteredClass(WClassVerifierProvider.TAG), CustomVerifierPane.class)); return creators; } @Override protected String title4PopupWindow() { return null; } public void populate(ReportWriteAttrProvider reportWriteAttr) { if (reportWriteAttr == null) { return; } java.util.List nameObjectList = new ArrayList(); int verifierCount = reportWriteAttr.getVerifierCount(); boolean addedVVObject = false; for (int i = 0; i < verifierCount; i++) { Verifier verifier = reportWriteAttr.getVerifier(i); String name = reportWriteAttr.getVerifierNameList(i); // 内置的校验ValueVerifier只要加在一个面板中 if (verifier instanceof ValueVerifierProvider) { if (!addedVVObject) { nameObjectList.add(new NameObject(name, reportWriteAttr)); addedVVObject = true; } } else { nameObjectList.add(new NameObject(name, verifier)); } } this.populate(nameObjectList.toArray(new NameObject[nameObjectList.size()])); } private static String valueVerifyName = Inter.getLocText("Verify-Data_Verify"); /** * 更新报表填报属性 * * @param reportWriteAttr 报表填报属性 */ public void updateReportWriteAttr(ReportWriteAttrProvider reportWriteAttr) { JNameEdList nameEdList = VerifierListPane.this.nameableList; DefaultListModel model = (DefaultListModel) nameEdList.getModel(); for (int i = 0; i < model.size(); i++) { NameObject no = (NameObject) ((ListModelElement) model.get(i)).wrapper; if (no.getObject() instanceof ReportWriteAttrProvider) { valueVerifyName = no.getName(); break; } } Nameable[] res = this.update(); NameObject[] res_array = new NameObject[res.length]; java.util.Arrays.asList(res).toArray(res_array); reportWriteAttr.clearVerifiers(); for (int i = 0; i < res_array.length; i++) { NameObject nameObject = res_array[i]; if (nameObject.getObject() instanceof Verifier) { reportWriteAttr.addVerifier(nameObject.getName(), (Verifier) nameObject.getObject()); } else if (nameObject.getObject() instanceof ReportWriteAttrProvider) { ReportWriteAttrProvider ra = (ReportWriteAttrProvider) nameObject.getObject(); for (int k = 0; k < ra.getValueVerifierCount(); k++) { reportWriteAttr.addVerifier(nameObject.getName(), ra.getVerifier(k)); } } } } /** * 添加 * * @param nameable 添加的Nameable * @param index 序号 */ public void addNameable(Nameable nameable, int index) { JNameEdList nameEdList = VerifierListPane.this.nameableList; DefaultListModel model = (DefaultListModel) nameEdList.getModel(); // 内置的数据校验大框架只加一个 if (((NameObject) nameable).getObject() instanceof ReportWriteAttrProvider) { setToolbarDefEnable(0, 0, false); for (int i = 0; i < model.size(); i++) { if (isBuildInVerifier(((NameObject) ((ListModelElement) model.get(i)).wrapper).getObject())) { nameableList.setSelectedIndex(i); } } } ListModelElement el = new ListModelElement(nameable); model.add(index, el); nameableList.setSelectedIndex(index); nameableList.ensureIndexIsVisible(index); nameEdList.repaint(); } /** * 检查btn的状态 */ public void checkButtonEnabled() { super.checkButtonEnabled(); if (!hasBuildInVerifier()) { setToolbarDefEnable(0, 0, true); } } private boolean hasBuildInVerifier() { JNameEdList nameEdList = VerifierListPane.this.nameableList; DefaultListModel model = (DefaultListModel) nameEdList.getModel(); for (int i = 0; i < model.size(); i++) { if (isBuildInVerifier(((NameObject) ((ListModelElement) model.get(i)).wrapper).getObject())) { return true; } } return false; } public static class BuildInVerifierPane extends BasicBeanPane { private ValueVerifierEditPane valueVerifierEditPane; public BuildInVerifierPane() { this.setLayout(FRGUIPaneFactory.createBorderLayout()); valueVerifierEditPane = new ValueVerifierEditPane(); this.add(valueVerifierEditPane, BorderLayout.CENTER); } @Override public void populateBean(ReportWriteAttrProvider ob) { valueVerifierEditPane.populate(ob); } @Override public ReportWriteAttrProvider updateBean() { ReportWriteAttrProvider ra = StableFactory.getMarkedInstanceObjectFromClass(ReportWriteAttrProvider.XML_TAG, ReportWriteAttrProvider.class); valueVerifierEditPane.update(ra, VerifierListPane.valueVerifyName); return ra; } @Override protected String title4PopupWindow() { return null; } } public static class CustomVerifierPane extends BasicBeanPane { private CustomVerifyJobPane pane; public CustomVerifierPane() { this.setLayout(FRGUIPaneFactory.createBorderLayout()); pane = new CustomVerifyJobPane(); this.add(pane, BorderLayout.CENTER); } @Override public void populateBean(WClassVerifierProvider ob) { this.pane.populateBean(ob.getClassVerifyJob()); } @Override public WClassVerifierProvider updateBean() { WClassVerifierProvider cs = StableFactory.getMarkedInstanceObjectFromClass(WClassVerifierProvider.TAG, WClassVerifierProvider.class); cs.setClassVerifyJob(this.pane.updateBean()); return cs; } @Override protected String title4PopupWindow() { return "custom"; } } private boolean isBuildInVerifier(Object obj) { return obj instanceof ReportWriteAttrProvider; } } \ No newline at end of file +package com.fr.design.report; import com.fr.data.Verifier; import com.fr.design.ExtraDesignClassManager; import com.fr.design.fun.VerifyDefineProvider; import com.fr.design.gui.controlpane.NameObjectCreator; import com.fr.design.gui.controlpane.NameableCreator; import com.fr.design.gui.controlpane.ObjectJControlPane; import com.fr.design.mainframe.ElementCasePane; import com.fr.general.Inter; import com.fr.general.NameObject; import com.fr.report.write.ValueVerifier; import com.fr.report.write.WClassVerifier; import com.fr.stable.ArrayUtils; import com.fr.stable.Nameable; import com.fr.write.ReportWriteAttrProvider; import java.util.ArrayList; /** * 校验列表 */ public class VerifierListPane extends ObjectJControlPane { public VerifierListPane(ElementCasePane ePane) { super(ePane); } /** * 创建选项 * * @return 选项 */ public NameableCreator[] createNameableCreators() { NameableCreator[] creators = new NameableCreator[]{ new NameObjectCreator(Inter.getLocText(new String[]{"BuildIn", "Verify"}), "/com/fr/web/images/reportlet.png", ValueVerifier.class, BuildInVerifierPane.class) }; for (VerifyDefineProvider provider : ExtraDesignClassManager.getInstance().getVerifyDefineProviders()) { creators = ArrayUtils.add(creators, new NameObjectCreator( provider.nameForVerifier(), provider.iconPath(), provider.classForVerifier(), provider.appearanceForVerifier() ) { }); } creators = ArrayUtils.add(creators, new NameObjectCreator( Inter.getLocText(new String[]{"Custom", "Verify"}), "/com/fr/web/images/reportlet.png", WClassVerifier.class, CustomVerifierPane.class)); return creators; } @Override protected String title4PopupWindow() { return "Verify Collections"; } public void populate(ReportWriteAttrProvider reportWriteAttr) { if (reportWriteAttr == null) { return; } java.util.List nameObjectList = new ArrayList<>(); int verifierCount = reportWriteAttr.getVerifierCount(); for (int i = 0; i < verifierCount; i++) { Verifier verifier = reportWriteAttr.getVerifier(i); nameObjectList.add(new NameObject(verifier.getName(), verifier)); } this.populate(nameObjectList.toArray(new NameObject[nameObjectList.size()])); } public void updateReportWriteAttr(ReportWriteAttrProvider reportWriteAttr) { // Nameable[]居然不能强转成NameObject[],一定要这么写... Nameable[] res = this.update(); NameObject[] res_array = new NameObject[res.length]; java.util.Arrays.asList(res).toArray(res_array); reportWriteAttr.clearVerifiers(); for (int i = 0; i < res_array.length; i++) { NameObject nameObject = res_array[i]; if (nameObject.getObject() instanceof Verifier) { Verifier verifier = (Verifier) nameObject.getObject(); verifier.setName(nameObject.getName()); reportWriteAttr.addVerifier(nameObject.getName(), verifier); } } } } \ No newline at end of file