Browse Source

Pull request #1982: REPORT-24268 增强公式编辑器插件问题

Merge in DESIGN/design from ~HARRISON/design:release/10.0 to release/10.0

* commit '2886d3b5d9d73eb90601f593510d25b68daebfde':
  1、更新注释 2、优化一下代码结构
  REPORT-24268 增强公式编辑器插件问题 [reason] 由于数据集相关没有保存公式的具体类,导致重新打开时, 都是默认的公式形态。 [solution] 直接保存公式形态,而不是字符串
feature/big-screen
Harrison 4 years ago
parent
commit
3804ce1342
  1. 73
      designer-base/src/main/java/com/fr/design/formula/FormulaTextField.java
  2. 25
      designer-base/src/main/java/com/fr/design/formula/SortFormulaPane.java
  3. 45
      designer-base/src/main/java/com/fr/design/gui/itextfield/DictionaryTextField.java
  4. 86
      designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java
  5. 72
      designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellDSColumnEditor.java

73
designer-base/src/main/java/com/fr/design/formula/FormulaTextField.java

@ -0,0 +1,73 @@
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;
/**
* 公式展示时使用
* 展示 String.
* 但实际保存的是 BaseFormula
* 从而保留公式的形态
*
* created by Harrison on 2020/08/03
**/
public class FormulaTextField extends DictionaryTextField<BaseFormula> {
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;
}
/**
* 设置值时会将展示的公式值一同设置进去
*
* @param 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;
}
}
}

25
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);

45
designer-base/src/main/java/com/fr/design/gui/itextfield/DictionaryTextField.java

@ -0,0 +1,45 @@
package com.fr.design.gui.itextfield;
import javax.swing.text.Document;
/**
* 文字 ui.
* 保存实际值展示值
* 允许实际值和展示值不同
*
* created by Harrison on 2020/08/03
**/
public class DictionaryTextField<T> 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;
}
}

86
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,18 +409,17 @@ public class DSColumnAdvancedPane extends BasicPane {
private static class JFormulaField extends JPanel {
private CellElement cellElement;
private UITextField formulaTextField;
private String defaultValue;
private FormulaTextField formulaTextField;
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 UITextField(24);
this.add(formulaTextField);
formulaTextField = new FormulaTextField(24);
formulaTextField.setText(defaultValue);
UIButton bottomFrmulaButton = new UIButton("...");
@ -440,15 +441,24 @@ public class DSColumnAdvancedPane extends BasicPane {
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 +467,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;
@ -470,9 +480,9 @@ 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.getContent().substring(1));
formulaTextField.setValue(valueFormula);
}
}
}).setVisible(true);
@ -503,12 +513,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 +526,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());
}
}

72
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,14 +1063,15 @@ public class CellDSColumnEditor extends CellQuickEditor {
*/
public class JFormulaField extends JPanel {
private CellElement cellElement;
private UITextField formulaTextField;
private String defaultValue;
private FormulaTextField formulaTextField;
private BaseFormula defaultFormula;
public JFormulaField(String defaultValue) {
this.defaultValue = defaultValue;
formulaTextField = new UITextField();
formulaTextField.setText(defaultValue);
this.defaultFormula = BaseFormula.createFormulaBuilder().build(defaultValue);
formulaTextField = new FormulaTextField();
formulaTextField.setValue(defaultFormula);
JPanel textFieldPane = new JPanel(new BorderLayout());
textFieldPane.add(formulaTextField, BorderLayout.CENTER);
textFieldPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
@ -1095,6 +1099,16 @@ public class CellDSColumnEditor extends CellQuickEditor {
return this.formulaTextField.getText().trim();
}
public void populateFormula(BaseFormula baseFormula) {
this.formulaTextField.setValue(baseFormula);
}
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());
@ -1133,9 +1145,9 @@ 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.getContent());
formulaTextField.setValue(valueFormula);
}
}
}).setVisible(true);
@ -1152,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;
@ -1171,11 +1184,11 @@ 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);
formulaField.populateFormula(valueFormula);
} else {
formulaField.populate(DEFAULT_VALUE);
formulaField.populateFormula(DEFAULT_FORMULA);
}
formulaField.populateElement(cellElement);
@ -1188,8 +1201,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());
}
}
}

Loading…
Cancel
Save