Browse Source

REPORT-60163 公式编辑器优化2.0

1.修改了国际化的位置
feature/x
Hoky 3 years ago
parent
commit
105d7308ec
  1. 32
      designer-base/src/main/java/com/fr/design/formula/FormulaPane.java
  2. 17
      designer-base/src/main/java/com/fr/design/formula/exception/function/FormulaCheckConstants.java
  3. 29
      designer-base/src/main/java/com/fr/design/formula/exception/function/MismatchedCharFunction.java
  4. 37
      designer-base/src/main/java/com/fr/design/formula/exception/function/MismatchedTokenFunction.java
  5. 3
      designer-base/src/main/java/com/fr/design/formula/exception/function/NoViableAltForCharFunction.java
  6. 7
      designer-base/src/main/java/com/fr/design/formula/exception/function/NoViableAltFunction.java

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

@ -122,19 +122,13 @@ import java.util.Set;
* @since 2012-3-29下午1:50:53
*/
public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
private final static String CONFIRM_DIALOG_TITLE = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Confirm");
public static final int DEFUAL_FOMULA_LENGTH = 103;
public static final String ELLIPSIS = "...";
public static final int KEY_CODE_A = 64;
public static final int KEY_CODE_Z = 91;
public static final String CHECK_RESULT = Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Result");
public static final String CONTINUE = Toolkit.i18nText("Fine-Design_Basic_Formula_Continue");
public static final String CAL_RESULT = Toolkit.i18nText("Fine-Design_Basic_Formula_Cal_Result");
public static final String NEWLINE = "\n";
public static final String ERROR_POSITION = Toolkit.i18nText("Fine-Design_Basic_Formula_Error_Position");
public static final String FORMULA_ICON = "/com/fr/design/images/m_file/formula.png";
public static final String PARAM_ICON = "/com/fr/design/images/m_file/param.png";
public static final int KEY_CODE_$ = 515;
private VariableTreeAndDescriptionArea variableTreeAndDescriptionArea;
private RSyntaxTextArea formulaTextArea;
private UITextField keyWordTextField = new UITextField(18);
@ -152,7 +146,7 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
private JList functionNameList;
private UITableEditorPane<ParameterProvider> editor4CalPane;
private FormulaPaneAutoCompletion autoCompletion;
private static DefaultCompletionProvider COMPLETION_PROVIDER = null;
private DefaultCompletionProvider completionProvider;
private static final Map<String, String> PARAM_PREFIX_MAP = new HashMap<>();
public FormulaPane() {
@ -353,11 +347,11 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
}
private CompletionProvider createCompletionProvider() {
if (COMPLETION_PROVIDER == null) {
COMPLETION_PROVIDER = new DefaultCompletionProvider();
if (completionProvider == null) {
completionProvider = new DefaultCompletionProvider();
NameAndDescription[] nameAndDescriptions = FunctionConstants.ALL.getDescriptions();
for (NameAndDescription nameAndDescription : nameAndDescriptions) {
COMPLETION_PROVIDER.addCompletion(new FormulaCompletion(COMPLETION_PROVIDER, nameAndDescription.getName(), BaseUtils.readIcon(FORMULA_ICON)));
completionProvider.addCompletion(new FormulaCompletion(completionProvider, nameAndDescription.getName(), BaseUtils.readIcon(FORMULA_ICON)));
}
VariableResolver variableResolver = VariableResolver.DEFAULT;
@ -381,13 +375,13 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
paramWithoutPre = parameter;
PARAM_PREFIX_MAP.put(paramWithoutPre, StringUtils.EMPTY);
}
COMPLETION_PROVIDER.addCompletion(new FormulaCompletion(COMPLETION_PROVIDER, paramWithoutPre, BaseUtils.readIcon(PARAM_ICON)));
completionProvider.addCompletion(new FormulaCompletion(completionProvider, paramWithoutPre, BaseUtils.readIcon(PARAM_ICON)));
}
COMPLETION_PROVIDER.addCompletion(new FormulaCompletion(COMPLETION_PROVIDER, "$$$", BaseUtils.readIcon(PARAM_ICON)));
completionProvider.addCompletion(new FormulaCompletion(completionProvider, "$$$", BaseUtils.readIcon(PARAM_ICON)));
return COMPLETION_PROVIDER;
return completionProvider;
}
return COMPLETION_PROVIDER;
return completionProvider;
}
public static boolean containsParam(String param) {
@ -821,7 +815,7 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
String objectToString = EssentialUtils.objectToString(value);
String result = objectToString.length() > DEFUAL_FOMULA_LENGTH ?
objectToString.substring(0, DEFUAL_FOMULA_LENGTH - ELLIPSIS.length()) + ELLIPSIS : objectToString;
messageTips = messageTips + CAL_RESULT + ":" + result;
messageTips = messageTips + Toolkit.i18nText("Fine-Design_Basic_Formula_Cal_Result") + ":" + result;
FineLoggerFactory.getLogger().info("value:{}", value);
} catch (UtilEvalError utilEvalError) {
FineLoggerFactory.getLogger().error(utilEvalError.getMessage(), utilEvalError);
@ -843,13 +837,13 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
} else {
int confirmDialog = FineJOptionPane.showConfirmDialog(
FormulaPane.this,
checkResult.getTips() + ", " + ERROR_POSITION + ":" + (checkResult.getFormulaCoordinates().getColumns()) + ".",
CONFIRM_DIALOG_TITLE,
checkResult.getTips() + ", " + Toolkit.i18nText("Fine-Design_Basic_Formula_Error_Position") + ":" + (checkResult.getFormulaCoordinates().getColumns()) + ".",
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Confirm"),
JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE,
null,
new String[]{CHECK_RESULT, CONTINUE},
CHECK_RESULT);
new String[]{Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Result"), Toolkit.i18nText("Fine-Design_Basic_Formula_Continue")},
Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Result"));
if (confirmDialog == 0) {
formulaTextArea.setCaretPosition(checkResult.getFormulaCoordinates().getColumns());
formulaTextArea.requestFocus();

17
designer-base/src/main/java/com/fr/design/formula/exception/function/FormulaCheckConstants.java

@ -1,27 +1,10 @@
package com.fr.design.formula.exception.function;
import com.fr.design.i18n.Toolkit;
/**
* @author Hoky
* @date 2021/10/28
*/
public class FormulaCheckConstants {
public final static String EXPECTING = Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Expecting") + ": ";
public final static String FOUND = Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Found");
public final static String EXPECTING_ANYTHING = Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Expecting_Anything");
public final static String GOT_IT_ANYWAY = Toolkit.i18nText("Fine-Design_Basic_Formula_Check_GotItAnyway");
public final static String TOKEN = Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Token");
public final static String IN_RANGE = Toolkit.i18nText("Fine-Design_Basic_Formula_Check_In_Range");
public final static String CHECK_NOT = Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Not");
public final static String ONE_OF = Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ONE_OF");
public final static String UNEXPECTED_TOKEN = Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Unexpected_Token");
public final static String UNEXPECTED_CHAR = Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Unexpected_Char");
public final static String UNEXPECTED_END_OF_SUBTREE = Toolkit.i18nText("Fine-Design_Basic_Formula_Check_End_Of_Subtree");
public final static String UNEXPECTED_AST_NODE = Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Unexpected_AST_Node");
public final static String MISMATCHED_TOKEN = Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Mismatched_Token");
public final static String MISMATCHED_CHAR = Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Mismatched_Char");
public final static String MISMATCHED_EOF = Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Mismatched_EOF");
public static final String COLON = ":";
public static final String LEFT = "(";
public static final String COMMON = ",";

29
designer-base/src/main/java/com/fr/design/formula/exception/function/MismatchedCharFunction.java

@ -1,6 +1,7 @@
package com.fr.design.formula.exception.function;
import com.fr.design.formula.FormulaChecker;
import com.fr.design.i18n.Toolkit;
import com.fr.script.checker.result.FormulaCheckResult;
import com.fr.script.checker.result.FormulaCoordinates;
import com.fr.third.antlr.MismatchedCharException;
@ -32,50 +33,50 @@ public class MismatchedCharFunction implements Function<Exception, FormulaCheckR
StringBuffer sb = new StringBuffer();
switch (charException.mismatchType) {
case 1:
sb.append(FormulaCheckConstants.EXPECTING);
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Expecting") + ": ");
appendCharName(sb, charException.expecting);
sb.append(FormulaCheckConstants.COMMON)
.append(FormulaCheckConstants.BLANK)
.append(FormulaCheckConstants.FOUND);
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Found"));
appendCharName(sb, charException.foundChar);
break;
case 2:
sb.append(FormulaCheckConstants.EXPECTING_ANYTHING)
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Expecting_Anything") + ": ")
.append(FormulaCheckConstants.BLANK)
.append(FormulaCheckConstants.SINGLE_QUOTES);
appendCharName(sb, charException.expecting);
sb.append("';").append(FormulaCheckConstants.GOT_IT_ANYWAY);
sb.append("';").append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_GotItAnyway"));
break;
case 3:
case 4:
sb.append(FormulaCheckConstants.EXPECTING).append(FormulaCheckConstants.TOKEN);
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Expecting") + ": ").append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Token"));
if (charException.mismatchType == 4) {
sb.append(FormulaCheckConstants.CHECK_NOT);
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Not"));
}
sb.append(FormulaCheckConstants.IN_RANGE).append(": ");
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_In_Range")).append(": ");
appendCharName(sb, charException.expecting);
sb.append("..");
appendCharName(sb, charException.upper);
sb.append(", ").append(FormulaCheckConstants.FOUND);
sb.append(", ").append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Found"));
appendCharName(sb, charException.foundChar);
break;
case 5:
case 6:
sb.append(FormulaCheckConstants.EXPECTING)
.append(charException.mismatchType == 6 ? FormulaCheckConstants.CHECK_NOT : FormulaCheckConstants.BLANK)
.append(FormulaCheckConstants.ONE_OF).append(" (");
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Expecting") + ": ")
.append(charException.mismatchType == 6 ? Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Not") : FormulaCheckConstants.BLANK)
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ONE_OF")).append(" (");
int[] elems = charException.set.toArray();
for (int i = 0; i < elems.length; ++i) {
appendCharName(sb, elems[i]);
}
sb.append("), ").append(FormulaCheckConstants.FOUND);
sb.append("), ").append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Found"));
appendCharName(sb, charException.foundChar);
break;
default:
sb.append(FormulaCheckConstants.MISMATCHED_CHAR);
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Mismatched_Char"));
}
return sb.toString();
@ -93,7 +94,7 @@ public class MismatchedCharFunction implements Function<Exception, FormulaCheckR
sb.append("'\\r'");
break;
case 65535:
sb.append(FormulaCheckConstants.MISMATCHED_EOF);
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Mismatched_EOF"));
break;
default:
sb.append((char) c);

37
designer-base/src/main/java/com/fr/design/formula/exception/function/MismatchedTokenFunction.java

@ -1,6 +1,7 @@
package com.fr.design.formula.exception.function;
import com.fr.design.formula.FormulaChecker;
import com.fr.design.i18n.Toolkit;
import com.fr.log.FineLoggerFactory;
import com.fr.script.checker.result.FormulaCheckResult;
import com.fr.script.checker.result.FormulaCoordinates;
@ -38,50 +39,50 @@ public class MismatchedTokenFunction implements Function<Exception, FormulaCheck
String tokenText = fieldValue == null ? NULL_STRING : fieldValue.toString();
switch (exception.mismatchType) {
case 1:
sb.append(FormulaCheckConstants.EXPECTING)
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Expecting") + ": ")
.append(tokenName(exception.expecting, exception))
.append(", ")
.append(FormulaCheckConstants.FOUND)
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Found"))
.append(FormulaCheckConstants.BLANK + FormulaCheckConstants.SINGLE_QUOTES)
.append(tokenText).append("'");
break;
case 2:
sb.append(FormulaCheckConstants.EXPECTING_ANYTHING)
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Expecting_Anything") + ": ")
.append(tokenName(exception.expecting, exception))
.append("; ")
.append(FormulaCheckConstants.GOT_IT_ANYWAY);
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_GotItAnyway"));
break;
case 3:
sb.append(FormulaCheckConstants.EXPECTING)
.append(FormulaCheckConstants.TOKEN)
.append(FormulaCheckConstants.IN_RANGE)
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Expecting") + ": ")
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Token"))
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_In_Range"))
.append(": ")
.append(tokenName(exception.expecting, exception))
.append("..")
.append(tokenName(exception.upper, exception))
.append(", ").append(FormulaCheckConstants.FOUND)
.append(", ").append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Found"))
.append("'").append(tokenText).append("'");
break;
case 4:
sb.append(FormulaCheckConstants.EXPECTING)
.append(FormulaCheckConstants.TOKEN)
.append(FormulaCheckConstants.CHECK_NOT)
.append(FormulaCheckConstants.IN_RANGE)
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Expecting") + ": ")
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Token"))
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Not"))
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_In_Range"))
.append(": ")
.append(tokenName(exception.expecting, exception))
.append("..")
.append(tokenName(exception.upper, exception))
.append(",").
append(FormulaCheckConstants.FOUND)
append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Found"))
.append(" '")
.append(tokenText)
.append("'");
break;
case 5:
case 6:
sb.append(FormulaCheckConstants.EXPECTING)
.append(exception.mismatchType == 6 ? FormulaCheckConstants.CHECK_NOT : FormulaCheckConstants.BLANK)
.append(FormulaCheckConstants.ONE_OF).append("(");
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Expecting") + ": ")
.append(exception.mismatchType == 6 ? Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Not") : FormulaCheckConstants.BLANK)
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ONE_OF")).append("(");
int[] elms = exception.set.toArray();
for (int i = 0; i < elms.length; ++i) {
@ -90,13 +91,13 @@ public class MismatchedTokenFunction implements Function<Exception, FormulaCheck
}
sb.append("),")
.append(FormulaCheckConstants.FOUND)
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Found"))
.append("'")
.append(tokenText)
.append("'");
break;
default:
sb.append(FormulaCheckConstants.MISMATCHED_TOKEN);
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Mismatched_Token"));
}
return sb.toString();

3
designer-base/src/main/java/com/fr/design/formula/exception/function/NoViableAltForCharFunction.java

@ -1,6 +1,7 @@
package com.fr.design.formula.exception.function;
import com.fr.design.formula.FormulaChecker;
import com.fr.design.i18n.Toolkit;
import com.fr.script.checker.result.FormulaCheckResult;
import com.fr.script.checker.result.FormulaCoordinates;
import com.fr.third.antlr.NoViableAltForCharException;
@ -29,7 +30,7 @@ public class NoViableAltForCharFunction implements Function<Exception, FormulaCh
}
public String getMessage(NoViableAltForCharException exception) {
String mesg = FormulaCheckConstants.UNEXPECTED_CHAR + ": ";
String mesg = Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Unexpected_Char") + ": ";
if (exception.foundChar >= ' ' && exception.foundChar <= '~') {
mesg = mesg + '\'';
mesg = mesg + exception.foundChar;

7
designer-base/src/main/java/com/fr/design/formula/exception/function/NoViableAltFunction.java

@ -1,6 +1,7 @@
package com.fr.design.formula.exception.function;
import com.fr.design.formula.FormulaChecker;
import com.fr.design.i18n.Toolkit;
import com.fr.script.checker.result.FormulaCheckResult;
import com.fr.script.checker.result.FormulaCoordinates;
import com.fr.third.antlr.NoViableAltException;
@ -31,10 +32,10 @@ public class NoViableAltFunction implements Function<Exception, FormulaCheckResu
public String getMessage(NoViableAltException exception) {
if (exception.token != null) {
return FormulaCheckConstants.UNEXPECTED_TOKEN + ": " + exception.token.getText();
return Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Unexpected_Token") + ": " + exception.token.getText();
} else {
return exception.node == TreeParser.ASTNULL ? FormulaCheckConstants.UNEXPECTED_END_OF_SUBTREE :
FormulaCheckConstants.UNEXPECTED_AST_NODE + ": " + exception.node.toString();
return exception.node == TreeParser.ASTNULL ? Toolkit.i18nText("Fine-Design_Basic_Formula_Check_End_Of_Subtree") :
Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Unexpected_AST_Node") + ": " + exception.node.toString();
}
}
}
Loading…
Cancel
Save