From 91fa55de6f802b33bbd10afd5e68dd76f8891d3e Mon Sep 17 00:00:00 2001 From: Harrison Date: Mon, 3 Aug 2020 18:03:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-24268=20=E5=A2=9E=E5=BC=BA=E5=85=AC?= =?UTF-8?q?=E5=BC=8F=E7=BC=96=E8=BE=91=E5=99=A8=E6=8F=92=E4=BB=B6=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20[reason]=20=E7=94=B1=E4=BA=8E=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=9B=86=E7=9B=B8=E5=85=B3=E6=B2=A1=E6=9C=89=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E5=85=AC=E5=BC=8F=E7=9A=84=E5=85=B7=E4=BD=93=E7=B1=BB,?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E9=87=8D=E6=96=B0=E6=89=93=E5=BC=80=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=20=E9=83=BD=E6=98=AF=E9=BB=98=E8=AE=A4=E7=9A=84?= =?UTF-8?q?=E5=85=AC=E5=BC=8F=E5=BD=A2=E6=80=81=E3=80=82=20[solution]=20?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E4=BF=9D=E5=AD=98=E5=85=AC=E5=BC=8F=E5=BD=A2?= =?UTF-8?q?=E6=80=81=EF=BC=8C=E8=80=8C=E4=B8=8D=E6=98=AF=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/formula/FormulaTextField.java | 63 +++++++++++++++ .../fr/design/formula/SortFormulaPane.java | 25 +++--- .../gui/itextfield/DictionaryTextField.java | 41 ++++++++++ .../design/dscolumn/DSColumnAdvancedPane.java | 80 +++++++++++-------- .../cellquick/CellDSColumnEditor.java | 64 ++++++++------- 5 files changed, 199 insertions(+), 74 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/formula/FormulaTextField.java create mode 100644 designer-base/src/main/java/com/fr/design/gui/itextfield/DictionaryTextField.java diff --git a/designer-base/src/main/java/com/fr/design/formula/FormulaTextField.java b/designer-base/src/main/java/com/fr/design/formula/FormulaTextField.java new file mode 100644 index 0000000000..e142662783 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/formula/FormulaTextField.java @@ -0,0 +1,63 @@ +package com.fr.design.formula; + +import com.fr.base.BaseFormula; +import com.fr.design.gui.itextfield.DictionaryTextField; +import com.fr.stable.StringUtils; + +import javax.swing.text.Document; + +/** + * created by Harrison on 2020/08/03 + **/ +public class FormulaTextField extends DictionaryTextField { + + private static final BaseFormula EMPTY_FORMULA = BaseFormula.createFormulaBuilder().build("="); + + public FormulaTextField() { + } + + public FormulaTextField(int columns) { + super(columns); + } + + public FormulaTextField(String text, int columns, BaseFormula value) { + super(text, columns, value); + } + + public FormulaTextField(String text, BaseFormula value) { + super(text, value); + } + + public FormulaTextField(Document doc, String text, int columns, BaseFormula value) { + super(doc, text, columns, value); + } + + @Override + public BaseFormula getValue() { + + if (this.value == null) { + this.value = createDefault(); + } + return this.value; + } + + @Override + public void setValue(BaseFormula value) { + + this.value = value; + if (this.value == null) { + this.value = createDefault(); + } + setText(this.value.getPureContent()); + } + + private BaseFormula createDefault() { + + String text = getText(); + if (StringUtils.isNotEmpty(text)) { + return BaseFormula.createFormulaBuilder().build(text); + } else { + return EMPTY_FORMULA; + } + } +} diff --git a/designer-base/src/main/java/com/fr/design/formula/SortFormulaPane.java b/designer-base/src/main/java/com/fr/design/formula/SortFormulaPane.java index 222aa90fec..4d598a7e25 100644 --- a/designer-base/src/main/java/com/fr/design/formula/SortFormulaPane.java +++ b/designer-base/src/main/java/com/fr/design/formula/SortFormulaPane.java @@ -7,12 +7,13 @@ import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icombobox.SortOrderComboBox; import com.fr.design.gui.ilable.UILabel; -import com.fr.design.gui.itextfield.UITextField; import com.fr.design.utils.gui.GUICoreUtils; - -import javax.swing.*; -import java.awt.*; +import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; +import java.awt.Dimension; +import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -20,7 +21,7 @@ public abstract class SortFormulaPane extends JPanel { protected static final String InsetText = " "; protected SortOrderComboBox sortOrderComboBox; - protected UITextField sortFormulaTextField; + protected FormulaTextField sortFormulaTextField; // 屏蔽掉“自定义比较规则”和“选择”按钮,只显示公式输入文本和公式按钮 protected UIButton sortFormulaTextFieldButton; @@ -35,7 +36,7 @@ public abstract class SortFormulaPane extends JPanel { } }); - sortFormulaTextField = new UITextField(16); + sortFormulaTextField = new FormulaTextField(16); //Lance:添加一公式编辑器按钮 sortFormulaTextFieldButton = new UIButton("..."); sortFormulaTextFieldButton.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula") + "..."); @@ -55,17 +56,15 @@ public abstract class SortFormulaPane extends JPanel { public abstract void formulaAction(); public void showFormulaDialog(String[] displayNames) { - String text = sortFormulaTextField.getText(); - final UIFormula formulaPane = FormulaFactory.createFormulaPaneWhenReserveFormula(); - formulaPane.populate(BaseFormula.createFormulaBuilder().build(text), new CustomVariableResolver(displayNames, true)); + BaseFormula value = sortFormulaTextField.getValue(); + final UIFormula formulaPane = FormulaFactory.createFormulaPaneWhenReserveFormula(); + formulaPane.populate(value, new CustomVariableResolver(displayNames, true)); formulaPane.showLargeWindow(SwingUtilities.getWindowAncestor(SortFormulaPane.this), new DialogActionAdapter() { public void doOk() { BaseFormula fm = formulaPane.update(); - if (fm.getContent().length() <= 1) { - sortFormulaTextField.setText(""); - } else { - sortFormulaTextField.setText(fm.getContent().substring(1)); + if (fm != null) { + sortFormulaTextField.setValue(fm); } } }).setVisible(true); diff --git a/designer-base/src/main/java/com/fr/design/gui/itextfield/DictionaryTextField.java b/designer-base/src/main/java/com/fr/design/gui/itextfield/DictionaryTextField.java new file mode 100644 index 0000000000..6d47cd090f --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/itextfield/DictionaryTextField.java @@ -0,0 +1,41 @@ +package com.fr.design.gui.itextfield; + +import javax.swing.text.Document; + +/** + * created by Harrison on 2020/08/03 + **/ +public class DictionaryTextField extends UITextField { + + protected T value; + + public DictionaryTextField() { + } + + public DictionaryTextField(int columns) { + super(columns); + } + + public DictionaryTextField(String text, int columns, T value) { + super(text, columns); + this.value = value; + } + + public DictionaryTextField(String text, T value) { + super(text); + this.value = value; + } + + public DictionaryTextField(Document doc, String text, int columns, T value) { + super(doc, text, columns); + this.value = value; + } + + public T getValue() { + return value; + } + + public void setValue(T value) { + this.value = value; + } +} diff --git a/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java b/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java index 0941b4b220..8fd8aaed05 100644 --- a/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java +++ b/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java @@ -7,6 +7,7 @@ import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.formula.CustomVariableResolver; import com.fr.design.formula.FormulaFactory; +import com.fr.design.formula.FormulaTextField; import com.fr.design.formula.SortFormulaPane; import com.fr.design.formula.UIFormula; import com.fr.design.gui.ibutton.UIButton; @@ -25,8 +26,17 @@ import com.fr.report.cell.cellattr.CellExpandAttr; import com.fr.report.cell.cellattr.core.group.DSColumn; import com.fr.report.cell.cellattr.core.group.SelectCount; -import javax.swing.*; -import java.awt.*; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -221,7 +231,7 @@ public class DSColumnAdvancedPane extends BasicPane { return; } Object value = cellElement.getValue(); - if (value == null || !(value instanceof DSColumn)) { + if (!(value instanceof DSColumn)) { return; } @@ -238,7 +248,7 @@ public class DSColumnAdvancedPane extends BasicPane { this.cellElement = cellElement; Object value = cellElement.getValue(); - if (value == null || !(value instanceof DSColumn)) { + if (!(value instanceof DSColumn)) { return; } DSColumn dSColumn = (DSColumn) value; @@ -246,8 +256,8 @@ public class DSColumnAdvancedPane extends BasicPane { int sort = dSColumn.getOrder(); this.sortOrderComboBox.setSortOrder(new SortOrder(sort)); - String sortFormula = dSColumn.getSortFormula(); - sortFormulaTextField.setText(sortFormula); + BaseFormula sortFormulaObject = dSColumn.getSortFormulaObject(); + sortFormulaTextField.setValue(sortFormulaObject); } public void update(CellElement cellElement) { @@ -263,15 +273,7 @@ public class DSColumnAdvancedPane extends BasicPane { dSColumn.setOrder(this.sortOrderComboBox.getSortOrder().getOrder()); //lance:sort formula - String sText = null; - if (!(sortFormulaTextField.getText() == null || sortFormulaTextField.getText().trim().equals("") || sortFormulaTextField.getText().trim().equals("$$$"))) { - sText = new String(sortFormulaTextField.getText()); - } - if (!(sText == null || sText.length() < 1)) { - dSColumn.setSortFormula(sText); - } else { - dSColumn.setSortFormula(null); - } + dSColumn.setSortFormulaObject(sortFormulaTextField.getValue()); } } @@ -367,9 +369,9 @@ public class DSColumnAdvancedPane extends BasicPane { int selectCountType = selectCount.getType(); this.selectCountComboBox.setSelectedIndex(selectCountType); if (selectCountType == TOP.getValue()) { - this.topFormulaPane.populate(selectCount.getFormulaCount()); + this.topFormulaPane.populateFormula(selectCount.getFormulaObject()); } else if (selectCountType == BOTTOM.getValue()) { - this.bottomFormulaPane.populate(selectCount.getFormulaCount()); + this.bottomFormulaPane.populateFormula(selectCount.getFormulaObject()); } else if (selectCountType == SPECIFY.getValue()) { this.serialTextField.setText(selectCount.getSerial()); } @@ -395,9 +397,9 @@ public class DSColumnAdvancedPane extends BasicPane { dSColumn.setSelectCount(selectCount); selectCount.setType(selectCountSelectIndex); if (selectCountSelectIndex == TOP.getValue()) { - selectCount.setFormulaCount(this.topFormulaPane.getFormulaText()); + selectCount.setFormulaObject(this.topFormulaPane.getFormula()); } else if (selectCountSelectIndex == BOTTOM.getValue()) { - selectCount.setFormulaCount(this.bottomFormulaPane.getFormulaText()); + selectCount.setFormulaObject(this.bottomFormulaPane.getFormula()); } else if (selectCountSelectIndex == SPECIFY.getValue()) { selectCount.setSerial(this.serialTextField.getText()); } @@ -407,7 +409,7 @@ public class DSColumnAdvancedPane extends BasicPane { private static class JFormulaField extends JPanel { private CellElement cellElement; - private UITextField formulaTextField; + private FormulaTextField formulaTextField; private String defaultValue; public JFormulaField(String defaultValue) { @@ -417,7 +419,7 @@ public class DSColumnAdvancedPane extends BasicPane { UILabel bottomLabel = new UILabel("="); bottomLabel.setFont(new Font("Dialog", Font.BOLD, 12)); this.add(bottomLabel); - formulaTextField = new UITextField(24); + formulaTextField = new FormulaTextField(24); this.add(formulaTextField); formulaTextField.setText(defaultValue); @@ -439,16 +441,25 @@ public class DSColumnAdvancedPane extends BasicPane { public String getFormulaText() { return this.formulaTextField.getText(); } + + public void populateFormula(BaseFormula baseFormula) { + + this.formulaTextField.setValue(baseFormula); + this.formulaTextField.setText(baseFormula.getPureContent()); + } + + public BaseFormula getFormula() { + + return this.formulaTextField.getValue(); + } private ActionListener formulaButtonActionListener = new ActionListener() { public void actionPerformed(ActionEvent evt) { - BaseFormula valueFormula = BaseFormula.createFormulaBuilder().build(); - String text = formulaTextField.getText(); - if (text == null || text.length() <= 0) { - valueFormula.setContent(defaultValue); - } else { - valueFormula.setContent(text); + + BaseFormula valueFormula = formulaTextField.getValue(); + if (valueFormula == null) { + valueFormula = BaseFormula.createFormulaBuilder().build(); } final UIFormula formulaPane = FormulaFactory.createFormulaPaneWhenReserveFormula(); @@ -457,7 +468,7 @@ public class DSColumnAdvancedPane extends BasicPane { return; } Object value = cellElement.getValue(); - if (value == null || !(value instanceof DSColumn)) { + if (!(value instanceof DSColumn)) { return; } DSColumn dsColumn = (DSColumn) value; @@ -472,7 +483,8 @@ public class DSColumnAdvancedPane extends BasicPane { if (valueFormula.getContent().length() <= 1) { formulaTextField.setText(defaultValue); } else { - formulaTextField.setText(valueFormula.getContent().substring(1)); + formulaTextField.setText(valueFormula.getPureContent()); + formulaTextField.setValue(valueFormula); } } }).setVisible(true); @@ -503,12 +515,12 @@ public class DSColumnAdvancedPane extends BasicPane { DSColumn dSColumn = (DSColumn) value; //formula - String valueFormula = dSColumn.getResult(); + BaseFormula valueFormula = dSColumn.getResultObject(); if (valueFormula == null) { - valueFormula = "$$$"; + valueFormula = BaseFormula.createFormulaBuilder().build("$$$"); } formulaField.populateElement(cellElement); - formulaField.populate(valueFormula); + formulaField.populateFormula(valueFormula); } public void update(CellElement cellElement) { @@ -516,13 +528,13 @@ public class DSColumnAdvancedPane extends BasicPane { return; } Object value = cellElement.getValue(); - if (value == null || !(value instanceof DSColumn)) { + if (!(value instanceof DSColumn)) { return; } DSColumn dSColumn = (DSColumn) (cellElement.getValue()); //formula - dSColumn.setResult(this.formulaField.getFormulaText()); + dSColumn.setResultObject(this.formulaField.getFormula()); } } diff --git a/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellDSColumnEditor.java b/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellDSColumnEditor.java index fb80e8891d..61223f1673 100644 --- a/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellDSColumnEditor.java +++ b/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellDSColumnEditor.java @@ -12,6 +12,7 @@ import com.fr.design.dscolumn.SelectedDataColumnPane; import com.fr.design.event.UIObserverListener; import com.fr.design.formula.CustomVariableResolver; import com.fr.design.formula.FormulaFactory; +import com.fr.design.formula.FormulaTextField; import com.fr.design.formula.UIFormula; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButtonGroup; @@ -645,6 +646,7 @@ public class CellDSColumnEditor extends CellQuickEditor { */ public class ResultSetSortConfigPane extends JPanel { private static final String DEFAULT_VALUE = "="; + private final BaseFormula DEFAULT_FORMULA = BaseFormula.createFormulaBuilder().build(); private JPanel contentPane; private UIButtonGroup sortTypePane; private JFormulaField formulaField; @@ -719,11 +721,11 @@ public class CellDSColumnEditor extends CellQuickEditor { centerPane.setPreferredSize(new Dimension(156, 20)); TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, VGAP); } - String sortFormula = dSColumn.getSortFormula(); - if (sortFormula != null && sortFormula.length() >= 1) { - this.formulaField.populate(sortFormula); + BaseFormula baseFormula = dSColumn.getSortFormulaObject(); + if (baseFormula == null) { + this.formulaField.populateFormula(DEFAULT_FORMULA); } else { - this.formulaField.populate(DEFAULT_VALUE); + this.formulaField.populateFormula(baseFormula); } } } @@ -740,7 +742,7 @@ public class CellDSColumnEditor extends CellQuickEditor { if (value instanceof DSColumn) { DSColumn dSColumn = (DSColumn) value; dSColumn.setOrder(this.sortTypePane.getSelectedIndex()); - dSColumn.setSortFormula(this.formulaField.getFormulaText()); + dSColumn.setSortFormulaObject(this.formulaField.getFormula()); } } } @@ -774,6 +776,7 @@ public class CellDSColumnEditor extends CellQuickEditor { */ public class ResultSetFilterConfigPane extends JPanel { private static final String DEFAULT_VALUE = "="; + private final BaseFormula DEFAULT_FORMULA = BaseFormula.createFormulaBuilder().build(DEFAULT_VALUE); private JPanel contentPane; private UIComboBox rsComboBox; @@ -918,8 +921,8 @@ public class CellDSColumnEditor extends CellQuickEditor { CardLayout setCardPaneLayout = (CardLayout) setCardPane.getLayout(); CardLayout tipCardPaneLayout = (CardLayout) tipCardPane.getLayout(); // 重置默认值 - this.topFormulaPane.populate(DEFAULT_VALUE); - this.bottomFormulaPane.populate(DEFAULT_VALUE); + this.topFormulaPane.populateFormula(DEFAULT_FORMULA); + this.bottomFormulaPane.populateFormula(DEFAULT_FORMULA); this.serialTextField.setText(StringUtils.EMPTY); if (selectCount != null) { @@ -927,7 +930,7 @@ public class CellDSColumnEditor extends CellQuickEditor { this.rsComboBox.setSelectedIndex(selectCountType); switch (FilterTypeEnum.getFilterByValue(selectCountType)) { case TOP: - this.topFormulaPane.populate(selectCount.getFormulaCount()); + this.topFormulaPane.populateFormula(selectCount.getFormulaObject()); //前N个 setCardPaneLayout.show(setCardPane, TOP.name()); tipCardPaneLayout.show(tipCardPane, TOP.name()); @@ -938,7 +941,7 @@ public class CellDSColumnEditor extends CellQuickEditor { TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 4, 0); break; case BOTTOM: - this.bottomFormulaPane.populate(selectCount.getFormulaCount()); + this.bottomFormulaPane.populateFormula(selectCount.getFormulaObject()); //后N个 setCardPaneLayout.show(setCardPane, BOTTOM.name()); tipCardPaneLayout.show(tipCardPane, BOTTOM.name()); @@ -1019,9 +1022,9 @@ public class CellDSColumnEditor extends CellQuickEditor { dSColumn.setSelectCount(selectCount); //noinspection Duplicates if (selectedFilterIndex == TOP.getValue()) { - selectCount.setFormulaCount(this.topFormulaPane.getFormulaText()); + selectCount.setFormulaObject(this.topFormulaPane.getFormula()); } else if (selectedFilterIndex == BOTTOM.getValue()) { - selectCount.setFormulaCount(this.bottomFormulaPane.getFormulaText()); + selectCount.setFormulaObject(this.bottomFormulaPane.getFormula()); } else if (selectedFilterIndex == SPECIFY.getValue()) { selectCount.setSerial(this.serialTextField.getText()); } @@ -1060,13 +1063,13 @@ public class CellDSColumnEditor extends CellQuickEditor { */ public class JFormulaField extends JPanel { private CellElement cellElement; - private UITextField formulaTextField; + private FormulaTextField formulaTextField; private String defaultValue; public JFormulaField(String defaultValue) { this.defaultValue = defaultValue; - formulaTextField = new UITextField(); + formulaTextField = new FormulaTextField(); formulaTextField.setText(defaultValue); JPanel textFieldPane = new JPanel(new BorderLayout()); textFieldPane.add(formulaTextField, BorderLayout.CENTER); @@ -1094,6 +1097,17 @@ public class CellDSColumnEditor extends CellQuickEditor { public String getFormulaText() { return this.formulaTextField.getText().trim(); } + + public void populateFormula(BaseFormula baseFormula) { + + this.formulaTextField.setValue(baseFormula); + this.formulaTextField.setText(baseFormula.getContent()); + } + + public BaseFormula getFormula() { + + return this.formulaTextField.getValue(); + } /** * 添加事件监听器 @@ -1114,16 +1128,14 @@ public class CellDSColumnEditor extends CellQuickEditor { private ActionListener formulaButtonActionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { - BaseFormula valueFormula = BaseFormula.createFormulaBuilder().build(); - String text = formulaTextField.getText(); - if (text == null || text.length() <= 0) { - valueFormula.setContent(defaultValue); - } else { - valueFormula.setContent(text); + + BaseFormula valueFormula = formulaTextField.getValue(); + if (valueFormula == null) { + valueFormula = BaseFormula.createFormulaBuilder().build(); } final UIFormula formulaPane = FormulaFactory.createFormulaPaneWhenReserveFormula(); if (cellElement != null) { - Object value = cellElement.getValue(); + final Object value = cellElement.getValue(); if (value instanceof DSColumn) { DSColumn dsColumn = (DSColumn) value; String[] displayNames = DesignTableDataManager.getSelectedColumnNames(DesignTableDataManager.getEditingTableDataSource(), dsColumn.getDSName()); @@ -1135,7 +1147,8 @@ public class CellDSColumnEditor extends CellQuickEditor { if (valueFormula.getContent().length() <= 1) { formulaTextField.setText(defaultValue); } else { - formulaTextField.setText(valueFormula.getContent()); + formulaTextField.setText(valueFormula.getPureContent()); + formulaTextField.setValue(valueFormula); } } }).setVisible(true); @@ -1171,11 +1184,9 @@ public class CellDSColumnEditor extends CellQuickEditor { if (value instanceof DSColumn) { DSColumn dSColumn = (DSColumn) value; //formula - String valueFormula = dSColumn.getResult(); + BaseFormula valueFormula = dSColumn.getResultObject(); if (valueFormula != null) { - formulaField.populate(valueFormula); - } else { - formulaField.populate(DEFAULT_VALUE); + formulaField.populateFormula(valueFormula); } formulaField.populateElement(cellElement); @@ -1188,8 +1199,7 @@ public class CellDSColumnEditor extends CellQuickEditor { Object value = cellElement.getValue(); if (value instanceof DSColumn) { DSColumn dSColumn = (DSColumn) (cellElement.getValue()); - dSColumn.setResult(StringUtils.isEmpty(this.formulaField.getFormulaText()) ? - null : this.formulaField.getFormulaText()); + dSColumn.setResultObject(this.formulaField.getFormula()); } } } From 2886d3b5d9d73eb90601f593510d25b68daebfde Mon Sep 17 00:00:00 2001 From: Harrison Date: Tue, 4 Aug 2020 19:42:16 +0800 Subject: [PATCH 2/2] =?UTF-8?q?1=E3=80=81=E6=9B=B4=E6=96=B0=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=202=E3=80=81=E4=BC=98=E5=8C=96=E4=B8=80=E4=B8=8B?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/formula/FormulaTextField.java | 10 ++++++++++ .../design/gui/itextfield/DictionaryTextField.java | 4 ++++ .../fr/design/dscolumn/DSColumnAdvancedPane.java | 8 +++----- .../quickeditor/cellquick/CellDSColumnEditor.java | 14 ++++++++------ 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/formula/FormulaTextField.java b/designer-base/src/main/java/com/fr/design/formula/FormulaTextField.java index e142662783..146085e3da 100644 --- a/designer-base/src/main/java/com/fr/design/formula/FormulaTextField.java +++ b/designer-base/src/main/java/com/fr/design/formula/FormulaTextField.java @@ -7,6 +7,11 @@ import com.fr.stable.StringUtils; import javax.swing.text.Document; /** + * 公式展示时使用。 + * 展示 String. + * 但实际保存的是 BaseFormula。 + * 从而保留公式的形态。 + * * created by Harrison on 2020/08/03 **/ public class FormulaTextField extends DictionaryTextField { @@ -41,6 +46,11 @@ public class FormulaTextField extends DictionaryTextField { return this.value; } + /** + * 设置值时,会将展示的公式值一同设置进去 + * + * @param value 公式值 + */ @Override public void setValue(BaseFormula value) { diff --git a/designer-base/src/main/java/com/fr/design/gui/itextfield/DictionaryTextField.java b/designer-base/src/main/java/com/fr/design/gui/itextfield/DictionaryTextField.java index 6d47cd090f..b8805b61dd 100644 --- a/designer-base/src/main/java/com/fr/design/gui/itextfield/DictionaryTextField.java +++ b/designer-base/src/main/java/com/fr/design/gui/itextfield/DictionaryTextField.java @@ -3,6 +3,10 @@ package com.fr.design.gui.itextfield; import javax.swing.text.Document; /** + * 文字 ui. + * 保存实际值,展示值。 + * 允许实际值和展示值不同。 + * * created by Harrison on 2020/08/03 **/ public class DictionaryTextField extends UITextField { diff --git a/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java b/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java index 8fd8aaed05..f25d730d0a 100644 --- a/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java +++ b/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java @@ -410,17 +410,16 @@ public class DSColumnAdvancedPane extends BasicPane { private static class JFormulaField extends JPanel { private CellElement cellElement; private FormulaTextField formulaTextField; - private String defaultValue; + private BaseFormula defaultFormula; public JFormulaField(String defaultValue) { - this.defaultValue = defaultValue; + this.defaultFormula = BaseFormula.createFormulaBuilder().build(defaultValue); this.setLayout(FRGUIPaneFactory.createBoxFlowLayout()); UILabel bottomLabel = new UILabel("="); bottomLabel.setFont(new Font("Dialog", Font.BOLD, 12)); this.add(bottomLabel); formulaTextField = new FormulaTextField(24); - this.add(formulaTextField); formulaTextField.setText(defaultValue); UIButton bottomFrmulaButton = new UIButton("..."); @@ -481,9 +480,8 @@ public class DSColumnAdvancedPane extends BasicPane { public void doOk() { BaseFormula valueFormula = formulaPane.update(); if (valueFormula.getContent().length() <= 1) { - formulaTextField.setText(defaultValue); + formulaTextField.setValue(defaultFormula); } else { - formulaTextField.setText(valueFormula.getPureContent()); formulaTextField.setValue(valueFormula); } } diff --git a/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellDSColumnEditor.java b/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellDSColumnEditor.java index 61223f1673..983fbb9da7 100644 --- a/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellDSColumnEditor.java +++ b/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellDSColumnEditor.java @@ -1064,13 +1064,14 @@ public class CellDSColumnEditor extends CellQuickEditor { public class JFormulaField extends JPanel { private CellElement cellElement; private FormulaTextField formulaTextField; - private String defaultValue; + private BaseFormula defaultFormula; public JFormulaField(String defaultValue) { - this.defaultValue = defaultValue; + this.defaultFormula = BaseFormula.createFormulaBuilder().build(defaultValue); formulaTextField = new FormulaTextField(); - formulaTextField.setText(defaultValue); + formulaTextField.setValue(defaultFormula); + JPanel textFieldPane = new JPanel(new BorderLayout()); textFieldPane.add(formulaTextField, BorderLayout.CENTER); textFieldPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); @@ -1101,7 +1102,6 @@ public class CellDSColumnEditor extends CellQuickEditor { public void populateFormula(BaseFormula baseFormula) { this.formulaTextField.setValue(baseFormula); - this.formulaTextField.setText(baseFormula.getContent()); } public BaseFormula getFormula() { @@ -1145,9 +1145,8 @@ public class CellDSColumnEditor extends CellQuickEditor { public void doOk() { BaseFormula valueFormula = formulaPane.update(); if (valueFormula.getContent().length() <= 1) { - formulaTextField.setText(defaultValue); + formulaTextField.setValue(defaultFormula); } else { - formulaTextField.setText(valueFormula.getPureContent()); formulaTextField.setValue(valueFormula); } } @@ -1165,6 +1164,7 @@ public class CellDSColumnEditor extends CellQuickEditor { */ public class CustomValuePane extends JPanel { private static final String DEFAULT_VALUE = "=$$$"; + private final BaseFormula DEFAULT_FORMULA = BaseFormula.createFormulaBuilder().build(DEFAULT_VALUE); private JFormulaField formulaField; @@ -1187,6 +1187,8 @@ public class CellDSColumnEditor extends CellQuickEditor { BaseFormula valueFormula = dSColumn.getResultObject(); if (valueFormula != null) { formulaField.populateFormula(valueFormula); + } else { + formulaField.populateFormula(DEFAULT_FORMULA); } formulaField.populateElement(cellElement);