diff --git a/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellFormulaQuickEditor.java b/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellFormulaQuickEditor.java index ff8a74e57..3abd0f3aa 100644 --- a/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellFormulaQuickEditor.java +++ b/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellFormulaQuickEditor.java @@ -9,7 +9,6 @@ import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.formula.FormulaFactory; import com.fr.design.formula.UIFormula; import com.fr.design.gui.ibutton.UIButton; -import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; @@ -20,6 +19,7 @@ import com.fr.grid.selection.CellSelection; import com.fr.quickeditor.CellQuickEditor; import com.fr.report.ReportHelper; import com.fr.report.cell.DefaultTemplateCellElement; +import com.fr.report.cell.TemplateCellElement; import com.fr.stable.ColumnRow; import com.fr.stable.StringUtils; @@ -56,6 +56,9 @@ public class CellFormulaQuickEditor extends CellQuickEditor { //默认值 private static final String DEFAULT_FORMULA = "="; + //正在编辑的单元格 + private TemplateCellElement editingCellElement; + private DocumentListener documentListener = new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { @@ -102,19 +105,27 @@ public class CellFormulaQuickEditor extends CellQuickEditor { formulaButton.setPreferredSize(new Dimension(20, formulaTextField.getPreferredSize().height)); formulaButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { - String text = formulaTextField.getText(); final UIFormula formulaPane = FormulaFactory.createFormulaPaneWhenReserveFormula(); - formulaPane.populate(BaseFormula.createFormulaBuilder().build(text)); + CellSelection cellSelection = (CellSelection) tc.getSelection(); + editingCellElement = tc.getEditingElementCase().getTemplateCellElement(cellSelection.getColumn(), cellSelection.getRow()); + Object object = editingCellElement.getValue(); + if (object instanceof BaseFormula) { + formulaPane.populate((BaseFormula) object); + } else { + String text = formulaTextField.getText(); + formulaPane.populate(BaseFormula.createFormulaBuilder().build(text)); + } formulaPane.showLargeWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { @Override public void doOk() { BaseFormula fm = formulaPane.update(); if (fm.getContent().length() <= 1) { + fm.setContent(DEFAULT_FORMULA); formulaTextField.setText(DEFAULT_FORMULA); } else { formulaTextField.setText(fm.getContent()); } - + editingCellElement.setValue(fm); } }).setVisible(true); }