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 6294a7a3bd..36cabec6bb 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 @@ -18,8 +18,6 @@ public class FormulaTextField extends DictionaryTextField { private static final String EMPTY_STRING = "="; - private static final BaseFormula EMPTY_FORMULA = BaseFormula.createFormulaBuilder().build(EMPTY_STRING); - public FormulaTextField() { } @@ -64,10 +62,10 @@ public class FormulaTextField extends DictionaryTextField { @Override public void setValue(BaseFormula value) { - this.value = value; - if (this.value == null) { - this.value = createDefault(); + if (value == null) { + value = createDefault(); } + this.value = value; } /** @@ -94,7 +92,8 @@ public class FormulaTextField extends DictionaryTextField { if (StringUtils.isNotEmpty(text)) { return BaseFormula.createFormulaBuilder().build(text); } else { - return EMPTY_FORMULA; + //防止默认值被修改, 每一次创建都是不一样的。 + return BaseFormula.createFormulaBuilder().build(EMPTY_STRING); } } } 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 58636917cd..b1273ce58d 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,10 +410,10 @@ public class DSColumnAdvancedPane extends BasicPane { private static class JFormulaField extends JPanel { private CellElement cellElement; private FormulaTextField formulaTextField; - private BaseFormula defaultFormula; + private String defaultValue; public JFormulaField(String defaultValue) { - this.defaultFormula = BaseFormula.createFormulaBuilder().build(defaultValue); + this.defaultValue = defaultValue; this.setLayout(FRGUIPaneFactory.createBoxFlowLayout()); UILabel bottomLabel = new UILabel("="); @@ -421,6 +421,7 @@ public class DSColumnAdvancedPane extends BasicPane { this.add(bottomLabel); formulaTextField = new FormulaTextField(24); this.add(formulaTextField); + BaseFormula defaultFormula = BaseFormula.createFormulaBuilder().build(this.defaultValue); formulaTextField.setValueAndText(defaultFormula, true); UIButton bottomFrmulaButton = new UIButton("..."); @@ -480,6 +481,7 @@ public class DSColumnAdvancedPane extends BasicPane { public void doOk() { BaseFormula valueFormula = formulaPane.update(); if (valueFormula.getContent().length() <= 1) { + BaseFormula defaultFormula = BaseFormula.createFormulaBuilder().build(defaultValue); formulaTextField.setValueAndText(defaultFormula, true); } else { formulaTextField.setValueAndText(valueFormula, true); 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 d9b8f1e7a0..248a274f57 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 @@ -646,7 +646,6 @@ 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; @@ -723,7 +722,8 @@ public class CellDSColumnEditor extends CellQuickEditor { } BaseFormula baseFormula = dSColumn.getSortFormulaObject(); if (baseFormula == null) { - this.formulaField.populateFormula(DEFAULT_FORMULA); + BaseFormula defaultFormula = BaseFormula.createFormulaBuilder().build(); + this.formulaField.populateFormula(defaultFormula); } else { this.formulaField.populateFormula(baseFormula); } @@ -1064,11 +1064,12 @@ public class CellDSColumnEditor extends CellQuickEditor { public class JFormulaField extends JPanel { private CellElement cellElement; private FormulaTextField formulaTextField; - private BaseFormula defaultFormula; + private String defaultValue; public JFormulaField(String defaultValue) { - - this.defaultFormula = BaseFormula.createFormulaBuilder().build(defaultValue); + + this.defaultValue = defaultValue; + BaseFormula defaultFormula = BaseFormula.createFormulaBuilder().build(this.defaultValue); formulaTextField = new FormulaTextField(); formulaTextField.setValueAndText(defaultFormula, false); @@ -1145,6 +1146,7 @@ public class CellDSColumnEditor extends CellQuickEditor { public void doOk() { BaseFormula valueFormula = formulaPane.update(); if (valueFormula.getContent().length() <= 1) { + BaseFormula defaultFormula = BaseFormula.createFormulaBuilder().build(defaultValue); formulaTextField.setValueAndText(defaultFormula, false); } else { formulaTextField.setValueAndText(valueFormula, false); @@ -1164,8 +1166,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; public CustomValuePane() { @@ -1188,7 +1189,8 @@ public class CellDSColumnEditor extends CellQuickEditor { if (valueFormula != null) { formulaField.populateFormula(valueFormula); } else { - formulaField.populateFormula(DEFAULT_FORMULA); + BaseFormula defaultFormula = BaseFormula.createFormulaBuilder().build(DEFAULT_VALUE); + formulaField.populateFormula(defaultFormula); } formulaField.populateElement(cellElement); @@ -1201,7 +1203,7 @@ public class CellDSColumnEditor extends CellQuickEditor { Object value = cellElement.getValue(); if (value instanceof DSColumn) { DSColumn dSColumn = (DSColumn) (cellElement.getValue()); - dSColumn.setResultObject(this.formulaField.getFormula()); + dSColumn.setResultObject(StringUtils.isEmpty(this.formulaField.getFormulaText()) ? null : this.formulaField.getFormula()); } } }