Browse Source

回滚代码, 现有逻辑不支持功能

feature/big-screen
Harrison 4 years ago
parent
commit
f23efebce3
  1. 99
      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. 28
      designer-base/src/test/java/com/fr/design/formula/FormulaTextFieldTest.java
  5. 84
      designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java
  6. 74
      designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellDSColumnEditor.java

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

@ -1,99 +0,0 @@
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 String EMPTY_STRING = "=";
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();
}
//保持联动
linkValueByText();
return value;
}
private void linkValueByText() {
String content = getText();
this.value.setContent(content);
}
/**
* 设置值时会将展示的公式值一同设置进去
*
* @param value 公式值
*/
@Override
public void setValue(BaseFormula value) {
if (value == null) {
value = createDefault();
}
this.value = value;
}
/**
* 是需要设置不带 = 还是带 =
*
* @param value
* @param isPure 带不带 = , = 不带 =
*/
public void setValueAndText(BaseFormula value, boolean isPure) {
setValue(value);
String content = null;
if (isPure) {
content = this.value.getPureContent();
} else {
content = this.value.getContent();
}
setText(content);
}
private BaseFormula createDefault() {
String text = getText();
if (StringUtils.isNotEmpty(text)) {
return BaseFormula.createFormulaBuilder().build(text);
} else {
//防止默认值被修改, 每一次创建都是不一样的。
return BaseFormula.createFormulaBuilder().build(EMPTY_STRING);
}
}
}

25
designer-base/src/main/java/com/fr/design/formula/SortFormulaPane.java

@ -7,13 +7,12 @@ 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.JComponent;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@ -21,7 +20,7 @@ public abstract class SortFormulaPane extends JPanel {
protected static final String InsetText = " ";
protected SortOrderComboBox sortOrderComboBox;
protected FormulaTextField sortFormulaTextField;
protected UITextField sortFormulaTextField;
// 屏蔽掉“自定义比较规则”和“选择”按钮,只显示公式输入文本和公式按钮
protected UIButton sortFormulaTextFieldButton;
@ -36,7 +35,7 @@ public abstract class SortFormulaPane extends JPanel {
}
});
sortFormulaTextField = new FormulaTextField(16);
sortFormulaTextField = new UITextField(16);
//Lance:添加一公式编辑器按钮
sortFormulaTextFieldButton = new UIButton("...");
sortFormulaTextFieldButton.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula") + "...");
@ -56,15 +55,17 @@ public abstract class SortFormulaPane extends JPanel {
public abstract void formulaAction();
public void showFormulaDialog(String[] displayNames) {
BaseFormula value = sortFormulaTextField.getValue();
final UIFormula formulaPane = FormulaFactory.createFormulaPaneWhenReserveFormula();
formulaPane.populate(value, new CustomVariableResolver(displayNames, true));
String text = sortFormulaTextField.getText();
final UIFormula formulaPane = FormulaFactory.createFormulaPaneWhenReserveFormula();
formulaPane.populate(BaseFormula.createFormulaBuilder().build(text), new CustomVariableResolver(displayNames, true));
formulaPane.showLargeWindow(SwingUtilities.getWindowAncestor(SortFormulaPane.this),
new DialogActionAdapter() {
public void doOk() {
BaseFormula fm = formulaPane.update();
if (fm != null) {
sortFormulaTextField.setValueAndText(fm, true);
if (fm.getContent().length() <= 1) {
sortFormulaTextField.setText("");
} else {
sortFormulaTextField.setText(fm.getContent().substring(1));
}
}
}).setVisible(true);

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

@ -1,45 +0,0 @@
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;
}
}

28
designer-base/src/test/java/com/fr/design/formula/FormulaTextFieldTest.java

@ -1,28 +0,0 @@
package com.fr.design.formula;
import com.fr.base.BaseFormula;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.*;
public class FormulaTextFieldTest {
@Test
public void testSet() {
FormulaTextField field = new FormulaTextField();
BaseFormula aaaa = BaseFormula.createFormulaBuilder().build("aaaa");
field.setValueAndText(aaaa, true);
Assert.assertEquals("aaaa", field.getText());
field.setValueAndText(aaaa, false);
Assert.assertEquals("=aaaa", field.getText());
field.setText("bbbb");
BaseFormula formula = field.getValue();
Assert.assertEquals("bbbb", formula.getPureContent());
}
}

84
designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java

@ -7,7 +7,6 @@ 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;
@ -26,17 +25,8 @@ 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.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 javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@ -231,7 +221,7 @@ public class DSColumnAdvancedPane extends BasicPane {
return;
}
Object value = cellElement.getValue();
if (!(value instanceof DSColumn)) {
if (value == null || !(value instanceof DSColumn)) {
return;
}
@ -248,7 +238,7 @@ public class DSColumnAdvancedPane extends BasicPane {
this.cellElement = cellElement;
Object value = cellElement.getValue();
if (!(value instanceof DSColumn)) {
if (value == null || !(value instanceof DSColumn)) {
return;
}
DSColumn dSColumn = (DSColumn) value;
@ -256,8 +246,8 @@ public class DSColumnAdvancedPane extends BasicPane {
int sort = dSColumn.getOrder();
this.sortOrderComboBox.setSortOrder(new SortOrder(sort));
BaseFormula sortFormulaObject = dSColumn.getSortFormulaObject();
sortFormulaTextField.setValueAndText(sortFormulaObject, true);
String sortFormula = dSColumn.getSortFormula();
sortFormulaTextField.setText(sortFormula);
}
public void update(CellElement cellElement) {
@ -273,7 +263,15 @@ public class DSColumnAdvancedPane extends BasicPane {
dSColumn.setOrder(this.sortOrderComboBox.getSortOrder().getOrder());
//lance:sort formula
dSColumn.setSortFormulaObject(sortFormulaTextField.getValue());
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);
}
}
}
@ -369,9 +367,9 @@ public class DSColumnAdvancedPane extends BasicPane {
int selectCountType = selectCount.getType();
this.selectCountComboBox.setSelectedIndex(selectCountType);
if (selectCountType == TOP.getValue()) {
this.topFormulaPane.populateFormula(selectCount.getFormulaObject());
this.topFormulaPane.populate(selectCount.getFormulaCount());
} else if (selectCountType == BOTTOM.getValue()) {
this.bottomFormulaPane.populateFormula(selectCount.getFormulaObject());
this.bottomFormulaPane.populate(selectCount.getFormulaCount());
} else if (selectCountType == SPECIFY.getValue()) {
this.serialTextField.setText(selectCount.getSerial());
}
@ -397,9 +395,9 @@ public class DSColumnAdvancedPane extends BasicPane {
dSColumn.setSelectCount(selectCount);
selectCount.setType(selectCountSelectIndex);
if (selectCountSelectIndex == TOP.getValue()) {
selectCount.setFormulaObject(this.topFormulaPane.getFormula());
selectCount.setFormulaCount(this.topFormulaPane.getFormulaText());
} else if (selectCountSelectIndex == BOTTOM.getValue()) {
selectCount.setFormulaObject(this.bottomFormulaPane.getFormula());
selectCount.setFormulaCount(this.bottomFormulaPane.getFormulaText());
} else if (selectCountSelectIndex == SPECIFY.getValue()) {
selectCount.setSerial(this.serialTextField.getText());
}
@ -409,7 +407,7 @@ public class DSColumnAdvancedPane extends BasicPane {
private static class JFormulaField extends JPanel {
private CellElement cellElement;
private FormulaTextField formulaTextField;
private UITextField formulaTextField;
private String defaultValue;
public JFormulaField(String defaultValue) {
@ -419,10 +417,9 @@ public class DSColumnAdvancedPane extends BasicPane {
UILabel bottomLabel = new UILabel("=");
bottomLabel.setFont(new Font("Dialog", Font.BOLD, 12));
this.add(bottomLabel);
formulaTextField = new FormulaTextField(24);
formulaTextField = new UITextField(24);
this.add(formulaTextField);
BaseFormula defaultFormula = BaseFormula.createFormulaBuilder().build(this.defaultValue);
formulaTextField.setValueAndText(defaultFormula, true);
formulaTextField.setText(defaultValue);
UIButton bottomFrmulaButton = new UIButton("...");
this.add(bottomFrmulaButton);
@ -442,24 +439,16 @@ public class DSColumnAdvancedPane extends BasicPane {
public String getFormulaText() {
return this.formulaTextField.getText();
}
public void populateFormula(BaseFormula baseFormula) {
this.formulaTextField.setValueAndText(baseFormula, true);
}
public BaseFormula getFormula() {
return this.formulaTextField.getValue();
}
private ActionListener formulaButtonActionListener = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
BaseFormula valueFormula = formulaTextField.getValue();
if (valueFormula == null) {
valueFormula = BaseFormula.createFormulaBuilder().build();
BaseFormula valueFormula = BaseFormula.createFormulaBuilder().build();
String text = formulaTextField.getText();
if (text == null || text.length() <= 0) {
valueFormula.setContent(defaultValue);
} else {
valueFormula.setContent(text);
}
final UIFormula formulaPane = FormulaFactory.createFormulaPaneWhenReserveFormula();
@ -468,7 +457,7 @@ public class DSColumnAdvancedPane extends BasicPane {
return;
}
Object value = cellElement.getValue();
if (!(value instanceof DSColumn)) {
if (value == null || !(value instanceof DSColumn)) {
return;
}
DSColumn dsColumn = (DSColumn) value;
@ -481,10 +470,9 @@ 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);
formulaTextField.setText(defaultValue);
} else {
formulaTextField.setValueAndText(valueFormula, true);
formulaTextField.setText(valueFormula.getContent().substring(1));
}
}
}).setVisible(true);
@ -515,12 +503,12 @@ public class DSColumnAdvancedPane extends BasicPane {
DSColumn dSColumn = (DSColumn) value;
//formula
BaseFormula valueFormula = dSColumn.getResultObject();
String valueFormula = dSColumn.getResult();
if (valueFormula == null) {
valueFormula = BaseFormula.createFormulaBuilder().build("$$$");
valueFormula = "$$$";
}
formulaField.populateElement(cellElement);
formulaField.populateFormula(valueFormula);
formulaField.populate(valueFormula);
}
public void update(CellElement cellElement) {
@ -528,13 +516,13 @@ public class DSColumnAdvancedPane extends BasicPane {
return;
}
Object value = cellElement.getValue();
if (!(value instanceof DSColumn)) {
if (value == null || !(value instanceof DSColumn)) {
return;
}
DSColumn dSColumn = (DSColumn) (cellElement.getValue());
//formula
dSColumn.setResultObject(this.formulaField.getFormula());
dSColumn.setResult(this.formulaField.getFormulaText());
}
}

74
designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellDSColumnEditor.java

@ -12,7 +12,6 @@ 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;
@ -720,12 +719,11 @@ public class CellDSColumnEditor extends CellQuickEditor {
centerPane.setPreferredSize(new Dimension(156, 20));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, VGAP);
}
BaseFormula baseFormula = dSColumn.getSortFormulaObject();
if (baseFormula == null) {
BaseFormula defaultFormula = BaseFormula.createFormulaBuilder().build();
this.formulaField.populateFormula(defaultFormula);
String sortFormula = dSColumn.getSortFormula();
if (sortFormula != null && sortFormula.length() >= 1) {
this.formulaField.populate(sortFormula);
} else {
this.formulaField.populateFormula(baseFormula);
this.formulaField.populate(DEFAULT_VALUE);
}
}
}
@ -742,7 +740,7 @@ public class CellDSColumnEditor extends CellQuickEditor {
if (value instanceof DSColumn) {
DSColumn dSColumn = (DSColumn) value;
dSColumn.setOrder(this.sortTypePane.getSelectedIndex());
dSColumn.setSortFormulaObject(this.formulaField.getFormula());
dSColumn.setSortFormula(this.formulaField.getFormulaText());
}
}
}
@ -776,7 +774,6 @@ 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;
@ -921,8 +918,8 @@ public class CellDSColumnEditor extends CellQuickEditor {
CardLayout setCardPaneLayout = (CardLayout) setCardPane.getLayout();
CardLayout tipCardPaneLayout = (CardLayout) tipCardPane.getLayout();
// 重置默认值
this.topFormulaPane.populateFormula(DEFAULT_FORMULA);
this.bottomFormulaPane.populateFormula(DEFAULT_FORMULA);
this.topFormulaPane.populate(DEFAULT_VALUE);
this.bottomFormulaPane.populate(DEFAULT_VALUE);
this.serialTextField.setText(StringUtils.EMPTY);
if (selectCount != null) {
@ -930,7 +927,7 @@ public class CellDSColumnEditor extends CellQuickEditor {
this.rsComboBox.setSelectedIndex(selectCountType);
switch (FilterTypeEnum.getFilterByValue(selectCountType)) {
case TOP:
this.topFormulaPane.populateFormula(selectCount.getFormulaObject());
this.topFormulaPane.populate(selectCount.getFormulaCount());
//前N个
setCardPaneLayout.show(setCardPane, TOP.name());
tipCardPaneLayout.show(tipCardPane, TOP.name());
@ -941,7 +938,7 @@ public class CellDSColumnEditor extends CellQuickEditor {
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 4, 0);
break;
case BOTTOM:
this.bottomFormulaPane.populateFormula(selectCount.getFormulaObject());
this.bottomFormulaPane.populate(selectCount.getFormulaCount());
//后N个
setCardPaneLayout.show(setCardPane, BOTTOM.name());
tipCardPaneLayout.show(tipCardPane, BOTTOM.name());
@ -1022,9 +1019,9 @@ public class CellDSColumnEditor extends CellQuickEditor {
dSColumn.setSelectCount(selectCount);
//noinspection Duplicates
if (selectedFilterIndex == TOP.getValue()) {
selectCount.setFormulaObject(this.topFormulaPane.getFormula());
selectCount.setFormulaCount(this.topFormulaPane.getFormulaText());
} else if (selectedFilterIndex == BOTTOM.getValue()) {
selectCount.setFormulaObject(this.bottomFormulaPane.getFormula());
selectCount.setFormulaCount(this.bottomFormulaPane.getFormulaText());
} else if (selectedFilterIndex == SPECIFY.getValue()) {
selectCount.setSerial(this.serialTextField.getText());
}
@ -1063,16 +1060,14 @@ public class CellDSColumnEditor extends CellQuickEditor {
*/
public class JFormulaField extends JPanel {
private CellElement cellElement;
private FormulaTextField formulaTextField;
private UITextField formulaTextField;
private String defaultValue;
public JFormulaField(String defaultValue) {
this.defaultValue = defaultValue;
BaseFormula defaultFormula = BaseFormula.createFormulaBuilder().build(this.defaultValue);
formulaTextField = new FormulaTextField();
formulaTextField.setValueAndText(defaultFormula, false);
formulaTextField = new UITextField();
formulaTextField.setText(defaultValue);
JPanel textFieldPane = new JPanel(new BorderLayout());
textFieldPane.add(formulaTextField, BorderLayout.CENTER);
textFieldPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
@ -1099,16 +1094,6 @@ public class CellDSColumnEditor extends CellQuickEditor {
public String getFormulaText() {
return this.formulaTextField.getText().trim();
}
public void populateFormula(BaseFormula baseFormula) {
this.formulaTextField.setValueAndText(baseFormula, false);
}
public BaseFormula getFormula() {
return this.formulaTextField.getValue();
}
/**
* 添加事件监听器
@ -1129,14 +1114,16 @@ public class CellDSColumnEditor extends CellQuickEditor {
private ActionListener formulaButtonActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
BaseFormula valueFormula = formulaTextField.getValue();
if (valueFormula == null) {
valueFormula = BaseFormula.createFormulaBuilder().build();
BaseFormula valueFormula = BaseFormula.createFormulaBuilder().build();
String text = formulaTextField.getText();
if (text == null || text.length() <= 0) {
valueFormula.setContent(defaultValue);
} else {
valueFormula.setContent(text);
}
final UIFormula formulaPane = FormulaFactory.createFormulaPaneWhenReserveFormula();
if (cellElement != null) {
final Object value = cellElement.getValue();
Object value = cellElement.getValue();
if (value instanceof DSColumn) {
DSColumn dsColumn = (DSColumn) value;
String[] displayNames = DesignTableDataManager.getSelectedColumnNames(DesignTableDataManager.getEditingTableDataSource(), dsColumn.getDSName());
@ -1146,10 +1133,9 @@ 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);
formulaTextField.setText(defaultValue);
} else {
formulaTextField.setValueAndText(valueFormula, false);
formulaTextField.setText(valueFormula.getContent());
}
}
}).setVisible(true);
@ -1166,7 +1152,7 @@ public class CellDSColumnEditor extends CellQuickEditor {
*/
public class CustomValuePane extends JPanel {
private static final String DEFAULT_VALUE = "=$$$";
private JFormulaField formulaField;
public CustomValuePane() {
@ -1185,12 +1171,11 @@ public class CellDSColumnEditor extends CellQuickEditor {
if (value instanceof DSColumn) {
DSColumn dSColumn = (DSColumn) value;
//formula
BaseFormula valueFormula = dSColumn.getResultObject();
String valueFormula = dSColumn.getResult();
if (valueFormula != null) {
formulaField.populateFormula(valueFormula);
formulaField.populate(valueFormula);
} else {
BaseFormula defaultFormula = BaseFormula.createFormulaBuilder().build(DEFAULT_VALUE);
formulaField.populateFormula(defaultFormula);
formulaField.populate(DEFAULT_VALUE);
}
formulaField.populateElement(cellElement);
@ -1203,7 +1188,8 @@ public class CellDSColumnEditor extends CellQuickEditor {
Object value = cellElement.getValue();
if (value instanceof DSColumn) {
DSColumn dSColumn = (DSColumn) (cellElement.getValue());
dSColumn.setResultObject(StringUtils.isEmpty(this.formulaField.getFormulaText()) ? null : this.formulaField.getFormula());
dSColumn.setResult(StringUtils.isEmpty(this.formulaField.getFormulaText()) ?
null : this.formulaField.getFormulaText());
}
}
}

Loading…
Cancel
Save