Browse Source
Merge in DESIGN/design from ~HARRISON/design:final/10.0 to final/10.0 * commit 'b9bce1cff6b0bba44078921724d4817e4bb52d0f': REPORT-24268 增强公式编辑器插件问题 回滚代码, 现有逻辑不支持功能final/10.0
Kara
4 years ago
6 changed files with 81 additions and 275 deletions
@ -1,100 +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 = "="; |
||||
|
||||
private static final BaseFormula EMPTY_FORMULA = BaseFormula.createFormulaBuilder().build(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) { |
||||
|
||||
this.value = value; |
||||
if (this.value == null) { |
||||
this.value = createDefault(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 是需要设置不带 = 号,还是带 = 号。 |
||||
* |
||||
* @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 EMPTY_FORMULA; |
||||
} |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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()); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue