Browse Source

Pull request #6214: REPORT-59545 设计器很多报错提示弹窗的交互有问题

Merge in DESIGN/design from ~FANGLEI/design10.0:release/11.0 to release/11.0

* commit '10a55919ae344a8f8ee7dada36d0f0d892785160':
  REPORT-60900 视觉切图提供的有点问题,找视觉更新了切图
  REPORT-59545 设计器很多报错提示弹窗的交互有问题
bugfix/11.0
fanglei 3 years ago
parent
commit
f46959d561
  1. 17
      designer-base/src/main/java/com/fr/design/formula/FormulaChecker.java
  2. 11
      designer-base/src/main/java/com/fr/design/formula/FormulaCheckerException.java
  3. 60
      designer-base/src/main/java/com/fr/design/formula/FormulaPane.java
  4. BIN
      designer-form/src/main/resources/com/fr/design/form/layouts/images/simple_style_18.png

17
designer-base/src/main/java/com/fr/design/formula/FormulaChecker.java

@ -25,7 +25,7 @@ public class FormulaChecker {
private static final String INVALID_FORMULA = Toolkit.i18nText("Fine-Design_Basic_FormulaD_Invalid_Formula"); private static final String INVALID_FORMULA = Toolkit.i18nText("Fine-Design_Basic_FormulaD_Invalid_Formula");
public static final String COLON = ":"; public static final String COLON = ":";
public static String check(String formulaText) { public static String check(String formulaText) throws FormulaCheckerException {
StringReader in = new StringReader(formulaText); StringReader in = new StringReader(formulaText);
FRLexer lexer = new FRLexer(in); FRLexer lexer = new FRLexer(in);
@ -34,12 +34,15 @@ public class FormulaChecker {
try { try {
Expression expression = parser.parse(); Expression expression = parser.parse();
Node node = expression.getConditionalExpression(); Node node = expression.getConditionalExpression();
return FunctionCheckerDispatcher.getInstance() boolean valid = FunctionCheckerDispatcher.getInstance().getFunctionChecker(node).checkFunction(node);
.getFunctionChecker(node) if (valid) {
.checkFunction(node) ? VALID_FORMULA : INVALID_FORMULA; return VALID_FORMULA;
} else {
throw new FormulaCheckerException(INVALID_FORMULA);
}
} catch (ConditionCheckWrongException cce) { } catch (ConditionCheckWrongException cce) {
String functionName = cce.getFunctionName(); String functionName = cce.getFunctionName();
return functionName + Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Condition_Tips") + COLON; throw new FormulaCheckerException(functionName + Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Condition_Tips") + COLON);
} catch (FunctionCheckWrongException ce) { } catch (FunctionCheckWrongException ce) {
List<FunctionRule> rules = ce.getRules(); List<FunctionRule> rules = ce.getRules();
String functionName = ce.getFunctionName(); String functionName = ce.getFunctionName();
@ -60,10 +63,10 @@ public class FormulaChecker {
errorMsg.append(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Or")); errorMsg.append(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Or"));
} }
} }
return errorMsg.toString(); throw new FormulaCheckerException(errorMsg.toString());
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
return INVALID_FORMULA; throw new FormulaCheckerException(INVALID_FORMULA);
// alex:继续往下面走,expression为null时告知不合法公式 // alex:继续往下面走,expression为null时告知不合法公式
} }
} }

11
designer-base/src/main/java/com/fr/design/formula/FormulaCheckerException.java

@ -0,0 +1,11 @@
package com.fr.design.formula;
public class FormulaCheckerException extends Exception {
public FormulaCheckerException() {
}
public FormulaCheckerException(String message) {
super(message);
}
}

60
designer-base/src/main/java/com/fr/design/formula/FormulaPane.java

@ -650,12 +650,14 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
// Execute Formula default cell element. // Execute Formula default cell element.
String formulaText = formulaTextArea.getText().trim(); String formulaText = formulaTextArea.getText().trim();
String formulaValidMessage = FormulaChecker.check(formulaText); String formulaValidMessage;
FineJOptionPane.showMessageDialog( try {
FormulaPane.this, formulaValidMessage = FormulaChecker.check(formulaText);
formulaValidMessage + ".", showMessageDialog(formulaValidMessage + ".");
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), } catch (FormulaCheckerException e) {
JOptionPane.WARNING_MESSAGE); formulaValidMessage = e.getMessage();
showMessageDialog(formulaValidMessage + ".", false);
}
} }
}; };
@ -663,22 +665,26 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
String formulaText = formulaTextArea.getText().trim(); String formulaText = formulaTextArea.getText().trim();
String formulaValidMessage = FormulaChecker.check(formulaText);
;
String unSupportFormula = containsUnsupportedSimulationFormulas(formulaText); String unSupportFormula = containsUnsupportedSimulationFormulas(formulaText);
if (unSupportFormula != null) { if (unSupportFormula != null) {
FineJOptionPane.showMessageDialog( showMessageDialog(Toolkit.i18nText("Fine-Design_Basic_Formula_Unsupported_Formulas") + ":" + unSupportFormula, false);
FormulaPane.this,
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Unsupported_Formulas") + ":" + unSupportFormula,
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"),
JOptionPane.INFORMATION_MESSAGE);
return; return;
} }
String formulaValidMessage;
boolean formulaValid;
try {
formulaValidMessage = FormulaChecker.check(formulaText);
formulaValid = true;
} catch (FormulaCheckerException formulaCheckerException) {
formulaValidMessage = formulaCheckerException.getMessage();
formulaValid = false;
}
String messageTips; String messageTips;
if (formulaValidMessage.equals(INVALID_FORMULA)) { if (ComparatorUtils.equals(formulaValidMessage, INVALID_FORMULA)) {
messageTips = INVALID_FORMULA; messageTips = INVALID_FORMULA;
} else { } else {
messageTips = formulaValidMessage.equals(VALID_FORMULA) ? "" : formulaValidMessage + "\n"; messageTips = ComparatorUtils.equals(formulaValidMessage, VALID_FORMULA) ? "" : formulaValidMessage + "\n";
Map<String, Object> paramsMap = setParamsIfExist(formulaText); Map<String, Object> paramsMap = setParamsIfExist(formulaText);
Calculator calculator = Calculator.createCalculator(); Calculator calculator = Calculator.createCalculator();
ParameterMapNameSpace parameterMapNameSpace = ParameterMapNameSpace.create(paramsMap); ParameterMapNameSpace parameterMapNameSpace = ParameterMapNameSpace.create(paramsMap);
@ -699,19 +705,33 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
String result = objectToString.length() > DEFUAL_FOMULA_LENGTH ? String result = objectToString.length() > DEFUAL_FOMULA_LENGTH ?
objectToString.substring(0, DEFUAL_FOMULA_LENGTH - ELLIPSIS.length()) + ELLIPSIS : objectToString; objectToString.substring(0, DEFUAL_FOMULA_LENGTH - ELLIPSIS.length()) + ELLIPSIS : objectToString;
messageTips = messageTips + messageTips = messageTips +
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Cal_Result") + ":" + result; Toolkit.i18nText("Fine-Design_Basic_Formula_Cal_Result") + ":" + result;
FineLoggerFactory.getLogger().info("value:{}", value); FineLoggerFactory.getLogger().info("value:{}", value);
} catch (UtilEvalError utilEvalError) { } catch (UtilEvalError utilEvalError) {
FineLoggerFactory.getLogger().error("", utilEvalError); FineLoggerFactory.getLogger().error("", utilEvalError);
} }
} }
showMessageDialog(messageTips, formulaValid);
}
};
private void showMessageDialog(String message) {
showMessageDialog(message, true);
}
private void showMessageDialog(String message, boolean formulaValid) {
if (formulaValid) {
FineJOptionPane.showMessageDialog(
FormulaPane.this,
message);
} else {
FineJOptionPane.showMessageDialog( FineJOptionPane.showMessageDialog(
FormulaPane.this, FormulaPane.this,
messageTips, message,
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"),
JOptionPane.INFORMATION_MESSAGE); JOptionPane.WARNING_MESSAGE);
} }
}; }
private String containsUnsupportedSimulationFormulas(String formulaText) { private String containsUnsupportedSimulationFormulas(String formulaText) {
try { try {

BIN
designer-form/src/main/resources/com/fr/design/form/layouts/images/simple_style_18.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB

Loading…
Cancel
Save