|
|
|
@ -16,7 +16,13 @@ import com.fr.design.dialog.BasicPane;
|
|
|
|
|
import com.fr.design.dialog.DialogActionAdapter; |
|
|
|
|
import com.fr.design.dialog.FineJOptionPane; |
|
|
|
|
import com.fr.design.file.HistoryTemplateListCache; |
|
|
|
|
import com.fr.design.gui.autocomplete.CompletionCellRenderer; |
|
|
|
|
import com.fr.design.gui.autocomplete.CompletionProvider; |
|
|
|
|
import com.fr.design.gui.autocomplete.DefaultCompletionProvider; |
|
|
|
|
import com.fr.design.gui.autocomplete.FormulaCompletion; |
|
|
|
|
import com.fr.design.gui.autocomplete.FormulaPaneAutoCompletion; |
|
|
|
|
import com.fr.design.gui.ibutton.UIButton; |
|
|
|
|
import com.fr.design.gui.icheckbox.UICheckBox; |
|
|
|
|
import com.fr.design.gui.icontainer.UIScrollPane; |
|
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
|
|
|
import com.fr.design.gui.ilist.QuickList; |
|
|
|
@ -43,6 +49,7 @@ import com.fr.parser.SheetIntervalLiteral;
|
|
|
|
|
import com.fr.report.core.namespace.SimpleCellValueNameSpace; |
|
|
|
|
import com.fr.script.Calculator; |
|
|
|
|
import com.fr.script.ScriptConstants; |
|
|
|
|
import com.fr.script.checker.result.FormulaCheckResult; |
|
|
|
|
import com.fr.stable.EncodeConstants; |
|
|
|
|
import com.fr.stable.EssentialUtils; |
|
|
|
|
import com.fr.stable.ParameterProvider; |
|
|
|
@ -65,6 +72,7 @@ import javax.swing.JList;
|
|
|
|
|
import javax.swing.JOptionPane; |
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
import javax.swing.JPopupMenu; |
|
|
|
|
import javax.swing.JScrollPane; |
|
|
|
|
import javax.swing.JTree; |
|
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
|
import javax.swing.event.ListSelectionEvent; |
|
|
|
@ -82,6 +90,8 @@ import java.awt.Component;
|
|
|
|
|
import java.awt.Dimension; |
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
import java.awt.event.FocusEvent; |
|
|
|
|
import java.awt.event.FocusListener; |
|
|
|
|
import java.awt.event.KeyAdapter; |
|
|
|
|
import java.awt.event.KeyEvent; |
|
|
|
|
import java.awt.event.KeyListener; |
|
|
|
@ -112,17 +122,27 @@ import java.util.Set;
|
|
|
|
|
* @since 2012-3-29下午1:50:53 |
|
|
|
|
*/ |
|
|
|
|
public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
|
|
|
|
|
|
public static final String VALID_FORMULA = Toolkit.i18nText("Fine-Design_Basic_FormulaD_Valid_Formula"); |
|
|
|
|
public static final String INVALID_FORMULA = Toolkit.i18nText("Fine-Design_Basic_FormulaD_Invalid_Formula"); |
|
|
|
|
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); |
|
|
|
|
private int currentPosition = 0; |
|
|
|
|
private int beginPosition = 0; |
|
|
|
|
private int insertPosition = 0; |
|
|
|
|
protected static UICheckBox autoCompletionCheck; |
|
|
|
|
protected static UICheckBox checkBeforeColse; |
|
|
|
|
private JList tipsList; |
|
|
|
|
protected DefaultListModel listModel = new DefaultListModel(); |
|
|
|
|
private int ifHasBeenWriten = 0; |
|
|
|
@ -131,6 +151,9 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
|
|
|
|
|
private DefaultListModel functionNameModel; |
|
|
|
|
private JList functionNameList; |
|
|
|
|
private UITableEditorPane<ParameterProvider> editor4CalPane; |
|
|
|
|
private FormulaPaneAutoCompletion autoCompletion; |
|
|
|
|
private static DefaultCompletionProvider COMPLETION_PROVIDER = null; |
|
|
|
|
private static final Map<String, String> PARAM_PREFIX_MAP = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
public FormulaPane() { |
|
|
|
|
initComponents(); |
|
|
|
@ -139,6 +162,21 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
|
|
|
|
|
private void initFormulaTextAreaKeyListener() { |
|
|
|
|
formulaTextArea.addKeyListener(this); |
|
|
|
|
formulaTextArea.addKeyListener(new KeyAdapter() { |
|
|
|
|
//用来判断一下是不是组合键
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void keyTyped(KeyEvent e) { |
|
|
|
|
if (inKeyCodeRange(e) && autoCompletionCheck.isSelected()) { |
|
|
|
|
autoCompletion.doCompletion(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean inKeyCodeRange(KeyEvent e) { |
|
|
|
|
//|| e.getExtendedKeyCode() ==
|
|
|
|
|
return (e.getExtendedKeyCode() > KEY_CODE_A && e.getExtendedKeyCode() < KEY_CODE_Z); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void keyReleased(KeyEvent e) { |
|
|
|
|
formulaTextArea.setForeground(Color.black); |
|
|
|
|
String text = formulaTextArea.getText(); |
|
|
|
@ -150,6 +188,9 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
|
|
|
|
|
insertPosition = 0; |
|
|
|
|
formulaTextArea.setText(text); |
|
|
|
|
} |
|
|
|
|
if (e.getExtendedKeyCode() == KEY_CODE_$) { |
|
|
|
|
autoCompletion.doCompletion(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
@ -174,7 +215,9 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
|
|
|
|
|
beginPosition = getBeginPosition(); |
|
|
|
|
insertPosition = beginPosition; |
|
|
|
|
firstStepToFindTips(beginPosition); |
|
|
|
|
fixFunctionNameList(); |
|
|
|
|
if (tipsList.getSelectedValue() != null) { |
|
|
|
|
fixFunctionNameList(tipsList.getSelectedValue().toString()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
@ -204,7 +247,9 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
|
|
|
|
|
if (e.getKeyCode() == KeyEvent.VK_ENTER) { |
|
|
|
|
String toFind = keyWordTextField.getText(); |
|
|
|
|
search(toFind, false); |
|
|
|
|
fixFunctionNameList(); |
|
|
|
|
if (tipsList.getSelectedValue() != null) { |
|
|
|
|
fixFunctionNameList(tipsList.getSelectedValue().toString()); |
|
|
|
|
} |
|
|
|
|
e.consume(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -213,28 +258,26 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
|
|
|
|
|
|
|
|
|
|
private void initTipsPane() { |
|
|
|
|
// tipsPane
|
|
|
|
|
JPanel tipsPane = new JPanel(new BorderLayout(4, 4)); |
|
|
|
|
this.add(tipsPane, BorderLayout.EAST); |
|
|
|
|
|
|
|
|
|
JPanel searchPane = new JPanel(new BorderLayout(4, 4)); |
|
|
|
|
JPanel searchPane = new JPanel(new BorderLayout(4, 1)); |
|
|
|
|
this.add(searchPane, BorderLayout.NORTH); |
|
|
|
|
searchPane.add(keyWordTextField, BorderLayout.CENTER); |
|
|
|
|
UIButton searchButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_FormulaPane_Search")); |
|
|
|
|
UILabel formulaLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_FormulaD_Input_Formula_In_The_Text_Area_Below") + ":" |
|
|
|
|
+ " "); |
|
|
|
|
formulaLabel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); |
|
|
|
|
searchPane.add(searchButton, BorderLayout.EAST); |
|
|
|
|
tipsPane.add(searchPane, BorderLayout.NORTH); |
|
|
|
|
searchPane.add(formulaLabel, BorderLayout.WEST); |
|
|
|
|
initKeyWordTextFieldKeyListener(); |
|
|
|
|
tipsList = new JList(listModel); |
|
|
|
|
tipsList.addMouseListener(new DoubleClick()); |
|
|
|
|
UIScrollPane tipsScrollPane = new UIScrollPane(tipsList); |
|
|
|
|
tipsScrollPane.setPreferredSize(new Dimension(170, 75)); |
|
|
|
|
tipsScrollPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, UIConstants.ARC)); |
|
|
|
|
tipsPane.add(tipsScrollPane, BorderLayout.CENTER); |
|
|
|
|
searchButton.addActionListener(new ActionListener() { |
|
|
|
|
@Override |
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
String toFind = keyWordTextField.getText(); |
|
|
|
|
search(toFind, false); |
|
|
|
|
formulaTextArea.requestFocusInWindow(); |
|
|
|
|
fixFunctionNameList(); |
|
|
|
|
searchButton.addActionListener(e -> { |
|
|
|
|
String toFind = keyWordTextField.getText(); |
|
|
|
|
search(toFind, false); |
|
|
|
|
popTips(); |
|
|
|
|
formulaTextArea.requestFocusInWindow(); |
|
|
|
|
if (tipsList.getSelectedValue() != null) { |
|
|
|
|
fixFunctionNameList(tipsList.getSelectedValue().toString()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
@ -254,18 +297,13 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
|
|
|
|
|
|
|
|
|
|
private void initTextPane() { |
|
|
|
|
// text
|
|
|
|
|
|
|
|
|
|
JPanel textPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
|
|
|
this.add(textPane, BorderLayout.CENTER); |
|
|
|
|
JPanel checkBoxandbuttonPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); |
|
|
|
|
UILabel formulaLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_FormulaD_Input_Formula_In_The_Text_Area_Below") + ":" |
|
|
|
|
+ " "); |
|
|
|
|
formulaLabel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); |
|
|
|
|
JPanel checkBoxandbuttonPane = FRGUIPaneFactory.createX_AXISBoxInnerContainer_S_Pane(); |
|
|
|
|
initFormulaTextArea(); |
|
|
|
|
|
|
|
|
|
UIScrollPane formulaTextAreaScrollPane = new UIScrollPane(formulaTextArea); |
|
|
|
|
formulaTextAreaScrollPane.setBorder(null); |
|
|
|
|
textPane.add(formulaLabel, BorderLayout.NORTH); |
|
|
|
|
textPane.add(formulaTextAreaScrollPane, BorderLayout.CENTER); |
|
|
|
|
textPane.add(checkBoxandbuttonPane, BorderLayout.SOUTH); |
|
|
|
|
|
|
|
|
@ -275,19 +313,105 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
|
|
|
|
|
checkValidButton.addActionListener(checkValidActionListener); |
|
|
|
|
calButton.addActionListener(calculateActionListener); |
|
|
|
|
|
|
|
|
|
//靠左流式布局
|
|
|
|
|
JPanel checkBoxPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); |
|
|
|
|
checkBoxPane.setPreferredSize(new Dimension(450, 30)); |
|
|
|
|
checkBoxandbuttonPane.add(checkBoxPane, BorderLayout.WEST); |
|
|
|
|
checkBoxandbuttonPane.add(checkValidButton, BorderLayout.EAST); |
|
|
|
|
checkBoxandbuttonPane.add(calButton, BorderLayout.EAST); |
|
|
|
|
//靠右流式布局
|
|
|
|
|
JPanel buttonPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); |
|
|
|
|
buttonPane.add(checkValidButton, BorderLayout.EAST); |
|
|
|
|
buttonPane.add(calButton, BorderLayout.EAST); |
|
|
|
|
checkBoxandbuttonPane.add(buttonPane, BorderLayout.EAST); |
|
|
|
|
if (autoCompletionCheck == null) { |
|
|
|
|
autoCompletionCheck = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_AutoCompletion")); |
|
|
|
|
autoCompletionCheck.setSelected(true); |
|
|
|
|
} |
|
|
|
|
if (checkBeforeColse == null) { |
|
|
|
|
checkBeforeColse = new UICheckBox(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Before_Closed")); |
|
|
|
|
checkBeforeColse.setSelected(true); |
|
|
|
|
} |
|
|
|
|
checkBoxPane.add(autoCompletionCheck, BorderLayout.WEST); |
|
|
|
|
checkBoxPane.add(checkBeforeColse, BorderLayout.WEST); |
|
|
|
|
extendCheckBoxPane(checkBoxPane); |
|
|
|
|
|
|
|
|
|
ParameterTableModel model = new ParameterTableModel(0); |
|
|
|
|
editor4CalPane = new UITableEditorPane<>(model); |
|
|
|
|
formulaTextArea.addFocusListener(new FocusListener() { |
|
|
|
|
@Override |
|
|
|
|
public void focusGained(FocusEvent e) { |
|
|
|
|
// 获得焦点时 安装
|
|
|
|
|
if (autoCompletion == null && autoCompletionCheck.isSelected()) { |
|
|
|
|
CompletionProvider provider = createCompletionProvider(); |
|
|
|
|
autoCompletion = new FormulaPaneAutoCompletion(provider); |
|
|
|
|
autoCompletion.setListCellRenderer(new CompletionCellRenderer()); |
|
|
|
|
autoCompletion.install(formulaTextArea); |
|
|
|
|
autoCompletion.installVariableTree(variableTreeAndDescriptionArea); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void focusLost(FocusEvent e) { |
|
|
|
|
// 失去焦点时 卸载
|
|
|
|
|
uninstallAutoCompletion(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private CompletionProvider createCompletionProvider() { |
|
|
|
|
if (COMPLETION_PROVIDER == null) { |
|
|
|
|
COMPLETION_PROVIDER = new DefaultCompletionProvider(); |
|
|
|
|
NameAndDescription[] nameAndDescriptions = FunctionConstants.ALL.getDescriptions(); |
|
|
|
|
for (NameAndDescription nameAndDescription : nameAndDescriptions) { |
|
|
|
|
COMPLETION_PROVIDER.addCompletion(new FormulaCompletion(COMPLETION_PROVIDER, nameAndDescription.getName(), BaseUtils.readIcon(FORMULA_ICON))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
VariableResolver variableResolver = VariableResolver.DEFAULT; |
|
|
|
|
List<String> allParameters = new ArrayList<>(); |
|
|
|
|
allParameters.addAll(Arrays.asList(variableResolver.resolveCurReportVariables())); |
|
|
|
|
allParameters.addAll(Arrays.asList(variableResolver.resolveColumnNames())); |
|
|
|
|
allParameters.addAll(Arrays.asList(variableResolver.resolveGlobalParameterVariables())); |
|
|
|
|
allParameters.addAll(Arrays.asList(variableResolver.resolveReportParameterVariables())); |
|
|
|
|
allParameters.addAll(Arrays.asList(variableResolver.resolveTableDataParameterVariables())); |
|
|
|
|
|
|
|
|
|
//先把参数前缀拿出来
|
|
|
|
|
for (String parameter : allParameters) { |
|
|
|
|
String paramWithoutPre; |
|
|
|
|
if (parameter.startsWith("$$")) { |
|
|
|
|
paramWithoutPre = parameter.substring(2); |
|
|
|
|
PARAM_PREFIX_MAP.put(paramWithoutPre, "$$"); |
|
|
|
|
} else if (parameter.startsWith("$")) { |
|
|
|
|
paramWithoutPre = parameter.substring(1); |
|
|
|
|
PARAM_PREFIX_MAP.put(paramWithoutPre, "$"); |
|
|
|
|
} else { |
|
|
|
|
paramWithoutPre = parameter; |
|
|
|
|
PARAM_PREFIX_MAP.put(paramWithoutPre, StringUtils.EMPTY); |
|
|
|
|
} |
|
|
|
|
COMPLETION_PROVIDER.addCompletion(new FormulaCompletion(COMPLETION_PROVIDER, paramWithoutPre, BaseUtils.readIcon(PARAM_ICON))); |
|
|
|
|
} |
|
|
|
|
COMPLETION_PROVIDER.addCompletion(new FormulaCompletion(COMPLETION_PROVIDER, "$$$", BaseUtils.readIcon(PARAM_ICON))); |
|
|
|
|
|
|
|
|
|
return COMPLETION_PROVIDER; |
|
|
|
|
} |
|
|
|
|
return COMPLETION_PROVIDER; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static boolean containsParam(String param) { |
|
|
|
|
return PARAM_PREFIX_MAP.containsKey(param); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static String getParamPrefix(String param) { |
|
|
|
|
return PARAM_PREFIX_MAP.getOrDefault(param, StringUtils.EMPTY); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void uninstallAutoCompletion() { |
|
|
|
|
if (autoCompletion != null) { |
|
|
|
|
autoCompletion.uninstall(); |
|
|
|
|
autoCompletion = null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void extendCheckBoxPane(JPanel checkBoxPane) { |
|
|
|
|
|
|
|
|
|
// do nothing
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -341,7 +465,9 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
|
|
|
|
|
private void singleClickActuator(String currentLineContent) { |
|
|
|
|
refreshDescriptionTextArea(currentLineContent); |
|
|
|
|
formulaTextArea.requestFocusInWindow(); |
|
|
|
|
fixFunctionNameList(); |
|
|
|
|
if (tipsList.getSelectedValue() != null) { |
|
|
|
|
fixFunctionNameList(tipsList.getSelectedValue().toString()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void doubleClickActuator(String currentLineContent) { |
|
|
|
@ -405,43 +531,41 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
|
|
|
|
|
beginPosition = getBeginPosition(); |
|
|
|
|
insertPosition = beginPosition; |
|
|
|
|
firstStepToFindTips(beginPosition); |
|
|
|
|
fixFunctionNameList(); |
|
|
|
|
if (tipsList.getSelectedValue() != null) { |
|
|
|
|
fixFunctionNameList(tipsList.getSelectedValue().toString()); |
|
|
|
|
} |
|
|
|
|
ifHasBeenWriten = 1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void fixFunctionNameList() { |
|
|
|
|
if (tipsList.getSelectedValue() != null) { |
|
|
|
|
int signOfContinue = 1; |
|
|
|
|
int indexOfFunction = 0; |
|
|
|
|
for (int i = 0; i < functionTypeListModel.size(); i++) { |
|
|
|
|
int signOfType = 0; |
|
|
|
|
FunctionGroup functionType = (FunctionGroup) functionTypeListModel.getElementAt(i); |
|
|
|
|
NameAndDescription[] nads = functionType.getDescriptions(); |
|
|
|
|
if (signOfContinue == 1) { |
|
|
|
|
functionNameModel.removeAllElements(); |
|
|
|
|
String functionName = ((String) tipsList.getSelectedValue()); |
|
|
|
|
for (int k = 0; k < nads.length; k++) { |
|
|
|
|
functionNameModel.addElement(nads[k]); |
|
|
|
|
if (functionName.equals(nads[k].getName()))//若相等,找出显示的函数的index,setSelectedIndex()
|
|
|
|
|
{ |
|
|
|
|
signOfType = 1; |
|
|
|
|
signOfContinue = 0; |
|
|
|
|
indexOfFunction = k; |
|
|
|
|
} |
|
|
|
|
private void fixFunctionNameList(String functionName) { |
|
|
|
|
int signOfContinue = 1; |
|
|
|
|
int indexOfFunction = 0; |
|
|
|
|
for (int i = 0; i < functionTypeListModel.size(); i++) { |
|
|
|
|
int signOfType = 0; |
|
|
|
|
FunctionGroup functionType = (FunctionGroup) functionTypeListModel.getElementAt(i); |
|
|
|
|
NameAndDescription[] nads = functionType.getDescriptions(); |
|
|
|
|
if (signOfContinue == 1) { |
|
|
|
|
functionNameModel.removeAllElements(); |
|
|
|
|
for (int k = 0; k < nads.length; k++) { |
|
|
|
|
functionNameModel.addElement(nads[k]); |
|
|
|
|
if (functionName.equals(nads[k].getName()))//若相等,找出显示的函数的index,setSelectedIndex()
|
|
|
|
|
{ |
|
|
|
|
signOfType = 1; |
|
|
|
|
signOfContinue = 0; |
|
|
|
|
indexOfFunction = k; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (signOfType == 1) { |
|
|
|
|
functionTypeList.setSelectedIndex(i); |
|
|
|
|
signOfType = 0; |
|
|
|
|
} |
|
|
|
|
if (signOfType == 1) { |
|
|
|
|
functionTypeList.setSelectedIndex(i); |
|
|
|
|
signOfType = 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
functionNameList.setSelectedIndex(indexOfFunction); |
|
|
|
|
functionNameList.ensureIndexIsVisible(indexOfFunction); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
functionNameList.setSelectedIndex(indexOfFunction); |
|
|
|
|
functionNameList.ensureIndexIsVisible(indexOfFunction); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private int getBeginPosition() { |
|
|
|
@ -492,9 +616,17 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
|
|
|
|
|
// do nothing
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void popTips() { |
|
|
|
|
JPopupMenu popupMenu = new JPopupMenu(); |
|
|
|
|
JScrollPane tipsScrollPane = new JScrollPane(tipsList); |
|
|
|
|
popupMenu.add(tipsScrollPane); |
|
|
|
|
tipsScrollPane.setPreferredSize(new Dimension(240, 146)); |
|
|
|
|
tipsScrollPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, UIConstants.ARC)); |
|
|
|
|
popupMenu.show(keyWordTextField, 0, 23); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void search(String keyWord, boolean findDescription) { |
|
|
|
|
listModel.removeAllElements(); |
|
|
|
|
|
|
|
|
|
keyWord = removeAllSpace(keyWord); |
|
|
|
|
if (keyWord.length() != 0) { |
|
|
|
|
NameAndDescription[] descriptions = FunctionConstants.ALL.getDescriptions(); |
|
|
|
@ -610,7 +742,9 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
|
|
|
|
|
beginPosition = getBeginPosition(); |
|
|
|
|
insertPosition = beginPosition; |
|
|
|
|
firstStepToFindTips(beginPosition); |
|
|
|
|
fixFunctionNameList(); |
|
|
|
|
if (tipsList.getSelectedValue() != null) { |
|
|
|
|
fixFunctionNameList(tipsList.getSelectedValue().toString()); |
|
|
|
|
} |
|
|
|
|
ifHasBeenWriten = 1; |
|
|
|
|
} else { |
|
|
|
|
this.formulaTextArea.setText(content); |
|
|
|
@ -618,7 +752,9 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
|
|
|
|
|
beginPosition = getBeginPosition(); |
|
|
|
|
insertPosition = beginPosition; |
|
|
|
|
firstStepToFindTips(beginPosition); |
|
|
|
|
fixFunctionNameList(); |
|
|
|
|
if (tipsList.getSelectedValue() != null) { |
|
|
|
|
fixFunctionNameList(tipsList.getSelectedValue().toString()); |
|
|
|
|
} |
|
|
|
|
ifHasBeenWriten = 1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -650,17 +786,12 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
|
|
|
|
|
public void actionPerformed(ActionEvent evt) { |
|
|
|
|
// Execute Formula default cell element.
|
|
|
|
|
String formulaText = formulaTextArea.getText().trim(); |
|
|
|
|
String formulaValidMessage; |
|
|
|
|
try { |
|
|
|
|
formulaValidMessage = FormulaChecker.check(formulaText); |
|
|
|
|
showMessageDialog(formulaValidMessage + "."); |
|
|
|
|
} catch (FormulaCheckerException e) { |
|
|
|
|
formulaValidMessage = e.getMessage(); |
|
|
|
|
showMessageDialog(formulaValidMessage + ".", false); |
|
|
|
|
} |
|
|
|
|
FormulaCheckResult checkResult = FormulaChecker.check(formulaText); |
|
|
|
|
confirmCheckResult(checkResult); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final ActionListener calculateActionListener = new ActionListener() { |
|
|
|
|
@Override |
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
@ -671,20 +802,10 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String formulaValidMessage; |
|
|
|
|
boolean formulaValid; |
|
|
|
|
try { |
|
|
|
|
formulaValidMessage = FormulaChecker.check(formulaText); |
|
|
|
|
formulaValid = true; |
|
|
|
|
} catch (FormulaCheckerException formulaCheckerException) { |
|
|
|
|
formulaValidMessage = formulaCheckerException.getMessage(); |
|
|
|
|
formulaValid = false; |
|
|
|
|
} |
|
|
|
|
String messageTips; |
|
|
|
|
if (ComparatorUtils.equals(formulaValidMessage, INVALID_FORMULA)) { |
|
|
|
|
messageTips = INVALID_FORMULA; |
|
|
|
|
} else { |
|
|
|
|
messageTips = ComparatorUtils.equals(formulaValidMessage, VALID_FORMULA) ? "" : formulaValidMessage + "\n"; |
|
|
|
|
FormulaCheckResult checkResult = FormulaChecker.check(formulaText); |
|
|
|
|
if (checkResult.isValid()) { |
|
|
|
|
messageTips = checkResult.getTips() + NEWLINE; |
|
|
|
|
Map<String, Object> paramsMap = setParamsIfExist(formulaText); |
|
|
|
|
Calculator calculator = Calculator.createCalculator(); |
|
|
|
|
ParameterMapNameSpace parameterMapNameSpace = ParameterMapNameSpace.create(paramsMap); |
|
|
|
@ -704,19 +825,42 @@ 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 + |
|
|
|
|
Toolkit.i18nText("Fine-Design_Basic_Formula_Cal_Result") + ":" + result; |
|
|
|
|
messageTips = messageTips + CAL_RESULT + ":" + result; |
|
|
|
|
FineLoggerFactory.getLogger().info("value:{}", value); |
|
|
|
|
} catch (UtilEvalError utilEvalError) { |
|
|
|
|
FineLoggerFactory.getLogger().error("", utilEvalError); |
|
|
|
|
FineLoggerFactory.getLogger().error(utilEvalError.getMessage(), utilEvalError); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
messageTips = checkResult.getTips(); |
|
|
|
|
} |
|
|
|
|
if (checkResult.isValid()) { |
|
|
|
|
showMessageDialog(messageTips, checkResult.isValid()); |
|
|
|
|
} else { |
|
|
|
|
confirmCheckResult(checkResult); |
|
|
|
|
} |
|
|
|
|
showMessageDialog(messageTips, formulaValid); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
private void showMessageDialog(String message) { |
|
|
|
|
showMessageDialog(message, true); |
|
|
|
|
private boolean confirmCheckResult(FormulaCheckResult checkResult) { |
|
|
|
|
if (checkResult.isValid()) { |
|
|
|
|
showMessageDialog(checkResult.getTips(), checkResult.isValid()); |
|
|
|
|
} else { |
|
|
|
|
int confirmDialog = FineJOptionPane.showConfirmDialog( |
|
|
|
|
FormulaPane.this, |
|
|
|
|
checkResult.getTips() + ", " + ERROR_POSITION + ":" + (checkResult.getFormulaCoordinates().getColumns()) + ".", |
|
|
|
|
CONFIRM_DIALOG_TITLE, |
|
|
|
|
JOptionPane.YES_NO_OPTION, |
|
|
|
|
JOptionPane.WARNING_MESSAGE, |
|
|
|
|
null, |
|
|
|
|
new String[]{CHECK_RESULT, CONTINUE}, |
|
|
|
|
CHECK_RESULT); |
|
|
|
|
if (confirmDialog == 0) { |
|
|
|
|
formulaTextArea.setCaretPosition(checkResult.getFormulaCoordinates().getColumns()); |
|
|
|
|
formulaTextArea.requestFocus(); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void showMessageDialog(String message, boolean formulaValid) { |
|
|
|
@ -750,6 +894,18 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean confirmContinueBeforeDoOK() { |
|
|
|
|
if (checkBeforeColse.isSelected()) { |
|
|
|
|
String formula = formulaTextArea.getText().trim(); |
|
|
|
|
FormulaCheckResult checkResult = FormulaChecker.check(formula); |
|
|
|
|
if (!checkResult.isValid()) { |
|
|
|
|
return confirmCheckResult(checkResult); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Map<String, Object> setParamsIfExist(String formulaText) { |
|
|
|
|
Map<String, Object> parameterMap = new HashMap<>(); |
|
|
|
|
try { |
|
|
|
@ -990,7 +1146,8 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
|
|
|
|
|
|
|
|
|
|
private void initDescriptionTextArea() { |
|
|
|
|
// Description
|
|
|
|
|
descriptionTextArea = new UITextArea(16, 27); |
|
|
|
|
descriptionTextArea = new UITextArea(); |
|
|
|
|
descriptionTextArea.setPreferredSize(new Dimension(350, 200)); |
|
|
|
|
|
|
|
|
|
UIScrollPane desScrollPane = new UIScrollPane(descriptionTextArea); |
|
|
|
|
desScrollPane.setBorder(null); |
|
|
|
@ -1191,6 +1348,10 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
public void refreshText(String line) { |
|
|
|
|
refreshDescriptionTextArea(line); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void populate(VariableResolver variableResolver) { |
|
|
|
|
// varibale tree.
|
|
|
|
|
DefaultTreeModel variableModel = (DefaultTreeModel) variablesTree.getModel(); |
|
|
|
@ -1326,12 +1487,12 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
|
|
|
|
|
buffer.append(name.toUpperCase()); |
|
|
|
|
buffer.append("\""); |
|
|
|
|
buffer.append("|"); |
|
|
|
|
buffer.append("\n"); |
|
|
|
|
buffer.append(NEWLINE); |
|
|
|
|
buffer.append("\""); |
|
|
|
|
buffer.append(name.toLowerCase()); |
|
|
|
|
buffer.append("\""); |
|
|
|
|
buffer.append("|"); |
|
|
|
|
buffer.append("\n"); |
|
|
|
|
buffer.append(NEWLINE); |
|
|
|
|
} |
|
|
|
|
FineLoggerFactory.getLogger().debug(buffer.toString()); |
|
|
|
|
} |
|
|
|
|