|
|
@ -16,7 +16,13 @@ import com.fr.design.dialog.BasicPane; |
|
|
|
import com.fr.design.dialog.DialogActionAdapter; |
|
|
|
import com.fr.design.dialog.DialogActionAdapter; |
|
|
|
import com.fr.design.dialog.FineJOptionPane; |
|
|
|
import com.fr.design.dialog.FineJOptionPane; |
|
|
|
import com.fr.design.file.HistoryTemplateListCache; |
|
|
|
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.ibutton.UIButton; |
|
|
|
|
|
|
|
import com.fr.design.gui.icheckbox.UICheckBox; |
|
|
|
import com.fr.design.gui.icontainer.UIScrollPane; |
|
|
|
import com.fr.design.gui.icontainer.UIScrollPane; |
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
|
|
import com.fr.design.gui.ilist.QuickList; |
|
|
|
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.report.core.namespace.SimpleCellValueNameSpace; |
|
|
|
import com.fr.script.Calculator; |
|
|
|
import com.fr.script.Calculator; |
|
|
|
import com.fr.script.ScriptConstants; |
|
|
|
import com.fr.script.ScriptConstants; |
|
|
|
|
|
|
|
import com.fr.script.checker.result.FormulaCheckResult; |
|
|
|
import com.fr.stable.EncodeConstants; |
|
|
|
import com.fr.stable.EncodeConstants; |
|
|
|
import com.fr.stable.EssentialUtils; |
|
|
|
import com.fr.stable.EssentialUtils; |
|
|
|
import com.fr.stable.ParameterProvider; |
|
|
|
import com.fr.stable.ParameterProvider; |
|
|
@ -65,6 +72,7 @@ import javax.swing.JList; |
|
|
|
import javax.swing.JOptionPane; |
|
|
|
import javax.swing.JOptionPane; |
|
|
|
import javax.swing.JPanel; |
|
|
|
import javax.swing.JPanel; |
|
|
|
import javax.swing.JPopupMenu; |
|
|
|
import javax.swing.JPopupMenu; |
|
|
|
|
|
|
|
import javax.swing.JScrollPane; |
|
|
|
import javax.swing.JTree; |
|
|
|
import javax.swing.JTree; |
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
import javax.swing.event.ListSelectionEvent; |
|
|
|
import javax.swing.event.ListSelectionEvent; |
|
|
@ -82,6 +90,8 @@ import java.awt.Component; |
|
|
|
import java.awt.Dimension; |
|
|
|
import java.awt.Dimension; |
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
import java.awt.event.ActionListener; |
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
|
|
|
import java.awt.event.FocusEvent; |
|
|
|
|
|
|
|
import java.awt.event.FocusListener; |
|
|
|
import java.awt.event.KeyAdapter; |
|
|
|
import java.awt.event.KeyAdapter; |
|
|
|
import java.awt.event.KeyEvent; |
|
|
|
import java.awt.event.KeyEvent; |
|
|
|
import java.awt.event.KeyListener; |
|
|
|
import java.awt.event.KeyListener; |
|
|
@ -112,17 +122,27 @@ import java.util.Set; |
|
|
|
* @since 2012-3-29下午1:50:53 |
|
|
|
* @since 2012-3-29下午1:50:53 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
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 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"); |
|
|
|
|
|
|
|
public static final int DEFUAL_FOMULA_LENGTH = 103; |
|
|
|
public static final int DEFUAL_FOMULA_LENGTH = 103; |
|
|
|
public static final String ELLIPSIS = "..."; |
|
|
|
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 VariableTreeAndDescriptionArea variableTreeAndDescriptionArea; |
|
|
|
private RSyntaxTextArea formulaTextArea; |
|
|
|
private RSyntaxTextArea formulaTextArea; |
|
|
|
private UITextField keyWordTextField = new UITextField(18); |
|
|
|
private UITextField keyWordTextField = new UITextField(18); |
|
|
|
private int currentPosition = 0; |
|
|
|
private int currentPosition = 0; |
|
|
|
private int beginPosition = 0; |
|
|
|
private int beginPosition = 0; |
|
|
|
private int insertPosition = 0; |
|
|
|
private int insertPosition = 0; |
|
|
|
|
|
|
|
protected static UICheckBox autoCompletionCheck; |
|
|
|
|
|
|
|
protected static UICheckBox checkBeforeColse; |
|
|
|
private JList tipsList; |
|
|
|
private JList tipsList; |
|
|
|
protected DefaultListModel listModel = new DefaultListModel(); |
|
|
|
protected DefaultListModel listModel = new DefaultListModel(); |
|
|
|
private int ifHasBeenWriten = 0; |
|
|
|
private int ifHasBeenWriten = 0; |
|
|
@ -131,6 +151,9 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
private DefaultListModel functionNameModel; |
|
|
|
private DefaultListModel functionNameModel; |
|
|
|
private JList functionNameList; |
|
|
|
private JList functionNameList; |
|
|
|
private UITableEditorPane<ParameterProvider> editor4CalPane; |
|
|
|
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() { |
|
|
|
public FormulaPane() { |
|
|
|
initComponents(); |
|
|
|
initComponents(); |
|
|
@ -139,6 +162,21 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
private void initFormulaTextAreaKeyListener() { |
|
|
|
private void initFormulaTextAreaKeyListener() { |
|
|
|
formulaTextArea.addKeyListener(this); |
|
|
|
formulaTextArea.addKeyListener(this); |
|
|
|
formulaTextArea.addKeyListener(new KeyAdapter() { |
|
|
|
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) { |
|
|
|
public void keyReleased(KeyEvent e) { |
|
|
|
formulaTextArea.setForeground(Color.black); |
|
|
|
formulaTextArea.setForeground(Color.black); |
|
|
|
String text = formulaTextArea.getText(); |
|
|
|
String text = formulaTextArea.getText(); |
|
|
@ -150,6 +188,9 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
insertPosition = 0; |
|
|
|
insertPosition = 0; |
|
|
|
formulaTextArea.setText(text); |
|
|
|
formulaTextArea.setText(text); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (e.getExtendedKeyCode() == KEY_CODE_$) { |
|
|
|
|
|
|
|
autoCompletion.doCompletion(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -174,7 +215,9 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
beginPosition = getBeginPosition(); |
|
|
|
beginPosition = getBeginPosition(); |
|
|
|
insertPosition = beginPosition; |
|
|
|
insertPosition = beginPosition; |
|
|
|
firstStepToFindTips(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) { |
|
|
|
if (e.getKeyCode() == KeyEvent.VK_ENTER) { |
|
|
|
String toFind = keyWordTextField.getText(); |
|
|
|
String toFind = keyWordTextField.getText(); |
|
|
|
search(toFind, false); |
|
|
|
search(toFind, false); |
|
|
|
fixFunctionNameList(); |
|
|
|
if (tipsList.getSelectedValue() != null) { |
|
|
|
|
|
|
|
fixFunctionNameList(tipsList.getSelectedValue().toString()); |
|
|
|
|
|
|
|
} |
|
|
|
e.consume(); |
|
|
|
e.consume(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -213,28 +258,26 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
|
|
|
|
|
|
|
|
private void initTipsPane() { |
|
|
|
private void initTipsPane() { |
|
|
|
// tipsPane
|
|
|
|
// 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); |
|
|
|
searchPane.add(keyWordTextField, BorderLayout.CENTER); |
|
|
|
UIButton searchButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_FormulaPane_Search")); |
|
|
|
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); |
|
|
|
searchPane.add(searchButton, BorderLayout.EAST); |
|
|
|
tipsPane.add(searchPane, BorderLayout.NORTH); |
|
|
|
searchPane.add(formulaLabel, BorderLayout.WEST); |
|
|
|
initKeyWordTextFieldKeyListener(); |
|
|
|
initKeyWordTextFieldKeyListener(); |
|
|
|
tipsList = new JList(listModel); |
|
|
|
tipsList = new JList(listModel); |
|
|
|
tipsList.addMouseListener(new DoubleClick()); |
|
|
|
tipsList.addMouseListener(new DoubleClick()); |
|
|
|
UIScrollPane tipsScrollPane = new UIScrollPane(tipsList); |
|
|
|
searchButton.addActionListener(e -> { |
|
|
|
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(); |
|
|
|
String toFind = keyWordTextField.getText(); |
|
|
|
search(toFind, false); |
|
|
|
search(toFind, false); |
|
|
|
|
|
|
|
popTips(); |
|
|
|
formulaTextArea.requestFocusInWindow(); |
|
|
|
formulaTextArea.requestFocusInWindow(); |
|
|
|
fixFunctionNameList(); |
|
|
|
if (tipsList.getSelectedValue() != null) { |
|
|
|
|
|
|
|
fixFunctionNameList(tipsList.getSelectedValue().toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -254,18 +297,13 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
|
|
|
|
|
|
|
|
private void initTextPane() { |
|
|
|
private void initTextPane() { |
|
|
|
// text
|
|
|
|
// text
|
|
|
|
|
|
|
|
|
|
|
|
JPanel textPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
|
|
JPanel textPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
|
|
this.add(textPane, BorderLayout.CENTER); |
|
|
|
this.add(textPane, BorderLayout.CENTER); |
|
|
|
JPanel checkBoxandbuttonPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); |
|
|
|
JPanel checkBoxandbuttonPane = FRGUIPaneFactory.createX_AXISBoxInnerContainer_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)); |
|
|
|
|
|
|
|
initFormulaTextArea(); |
|
|
|
initFormulaTextArea(); |
|
|
|
|
|
|
|
|
|
|
|
UIScrollPane formulaTextAreaScrollPane = new UIScrollPane(formulaTextArea); |
|
|
|
UIScrollPane formulaTextAreaScrollPane = new UIScrollPane(formulaTextArea); |
|
|
|
formulaTextAreaScrollPane.setBorder(null); |
|
|
|
formulaTextAreaScrollPane.setBorder(null); |
|
|
|
textPane.add(formulaLabel, BorderLayout.NORTH); |
|
|
|
|
|
|
|
textPane.add(formulaTextAreaScrollPane, BorderLayout.CENTER); |
|
|
|
textPane.add(formulaTextAreaScrollPane, BorderLayout.CENTER); |
|
|
|
textPane.add(checkBoxandbuttonPane, BorderLayout.SOUTH); |
|
|
|
textPane.add(checkBoxandbuttonPane, BorderLayout.SOUTH); |
|
|
|
|
|
|
|
|
|
|
@ -275,19 +313,105 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
checkValidButton.addActionListener(checkValidActionListener); |
|
|
|
checkValidButton.addActionListener(checkValidActionListener); |
|
|
|
calButton.addActionListener(calculateActionListener); |
|
|
|
calButton.addActionListener(calculateActionListener); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//靠左流式布局
|
|
|
|
JPanel checkBoxPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); |
|
|
|
JPanel checkBoxPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); |
|
|
|
checkBoxPane.setPreferredSize(new Dimension(450, 30)); |
|
|
|
|
|
|
|
checkBoxandbuttonPane.add(checkBoxPane, BorderLayout.WEST); |
|
|
|
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); |
|
|
|
extendCheckBoxPane(checkBoxPane); |
|
|
|
|
|
|
|
|
|
|
|
ParameterTableModel model = new ParameterTableModel(0); |
|
|
|
ParameterTableModel model = new ParameterTableModel(0); |
|
|
|
editor4CalPane = new UITableEditorPane<>(model); |
|
|
|
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) { |
|
|
|
protected void extendCheckBoxPane(JPanel checkBoxPane) { |
|
|
|
|
|
|
|
|
|
|
|
// do nothing
|
|
|
|
// do nothing
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -341,7 +465,9 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
private void singleClickActuator(String currentLineContent) { |
|
|
|
private void singleClickActuator(String currentLineContent) { |
|
|
|
refreshDescriptionTextArea(currentLineContent); |
|
|
|
refreshDescriptionTextArea(currentLineContent); |
|
|
|
formulaTextArea.requestFocusInWindow(); |
|
|
|
formulaTextArea.requestFocusInWindow(); |
|
|
|
fixFunctionNameList(); |
|
|
|
if (tipsList.getSelectedValue() != null) { |
|
|
|
|
|
|
|
fixFunctionNameList(tipsList.getSelectedValue().toString()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void doubleClickActuator(String currentLineContent) { |
|
|
|
private void doubleClickActuator(String currentLineContent) { |
|
|
@ -405,14 +531,15 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
beginPosition = getBeginPosition(); |
|
|
|
beginPosition = getBeginPosition(); |
|
|
|
insertPosition = beginPosition; |
|
|
|
insertPosition = beginPosition; |
|
|
|
firstStepToFindTips(beginPosition); |
|
|
|
firstStepToFindTips(beginPosition); |
|
|
|
fixFunctionNameList(); |
|
|
|
if (tipsList.getSelectedValue() != null) { |
|
|
|
|
|
|
|
fixFunctionNameList(tipsList.getSelectedValue().toString()); |
|
|
|
|
|
|
|
} |
|
|
|
ifHasBeenWriten = 1; |
|
|
|
ifHasBeenWriten = 1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void fixFunctionNameList() { |
|
|
|
private void fixFunctionNameList(String functionName) { |
|
|
|
if (tipsList.getSelectedValue() != null) { |
|
|
|
|
|
|
|
int signOfContinue = 1; |
|
|
|
int signOfContinue = 1; |
|
|
|
int indexOfFunction = 0; |
|
|
|
int indexOfFunction = 0; |
|
|
|
for (int i = 0; i < functionTypeListModel.size(); i++) { |
|
|
|
for (int i = 0; i < functionTypeListModel.size(); i++) { |
|
|
@ -421,7 +548,6 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
NameAndDescription[] nads = functionType.getDescriptions(); |
|
|
|
NameAndDescription[] nads = functionType.getDescriptions(); |
|
|
|
if (signOfContinue == 1) { |
|
|
|
if (signOfContinue == 1) { |
|
|
|
functionNameModel.removeAllElements(); |
|
|
|
functionNameModel.removeAllElements(); |
|
|
|
String functionName = ((String) tipsList.getSelectedValue()); |
|
|
|
|
|
|
|
for (int k = 0; k < nads.length; k++) { |
|
|
|
for (int k = 0; k < nads.length; k++) { |
|
|
|
functionNameModel.addElement(nads[k]); |
|
|
|
functionNameModel.addElement(nads[k]); |
|
|
|
if (functionName.equals(nads[k].getName()))//若相等,找出显示的函数的index,setSelectedIndex()
|
|
|
|
if (functionName.equals(nads[k].getName()))//若相等,找出显示的函数的index,setSelectedIndex()
|
|
|
@ -442,8 +568,6 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
functionNameList.ensureIndexIsVisible(indexOfFunction); |
|
|
|
functionNameList.ensureIndexIsVisible(indexOfFunction); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int getBeginPosition() { |
|
|
|
private int getBeginPosition() { |
|
|
|
int i = currentPosition; |
|
|
|
int i = currentPosition; |
|
|
|
String textArea = formulaTextArea.getText(); |
|
|
|
String textArea = formulaTextArea.getText(); |
|
|
@ -492,9 +616,17 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
// do nothing
|
|
|
|
// 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) { |
|
|
|
protected void search(String keyWord, boolean findDescription) { |
|
|
|
listModel.removeAllElements(); |
|
|
|
listModel.removeAllElements(); |
|
|
|
|
|
|
|
|
|
|
|
keyWord = removeAllSpace(keyWord); |
|
|
|
keyWord = removeAllSpace(keyWord); |
|
|
|
if (keyWord.length() != 0) { |
|
|
|
if (keyWord.length() != 0) { |
|
|
|
NameAndDescription[] descriptions = FunctionConstants.ALL.getDescriptions(); |
|
|
|
NameAndDescription[] descriptions = FunctionConstants.ALL.getDescriptions(); |
|
|
@ -610,7 +742,9 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
beginPosition = getBeginPosition(); |
|
|
|
beginPosition = getBeginPosition(); |
|
|
|
insertPosition = beginPosition; |
|
|
|
insertPosition = beginPosition; |
|
|
|
firstStepToFindTips(beginPosition); |
|
|
|
firstStepToFindTips(beginPosition); |
|
|
|
fixFunctionNameList(); |
|
|
|
if (tipsList.getSelectedValue() != null) { |
|
|
|
|
|
|
|
fixFunctionNameList(tipsList.getSelectedValue().toString()); |
|
|
|
|
|
|
|
} |
|
|
|
ifHasBeenWriten = 1; |
|
|
|
ifHasBeenWriten = 1; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.formulaTextArea.setText(content); |
|
|
|
this.formulaTextArea.setText(content); |
|
|
@ -618,7 +752,9 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
beginPosition = getBeginPosition(); |
|
|
|
beginPosition = getBeginPosition(); |
|
|
|
insertPosition = beginPosition; |
|
|
|
insertPosition = beginPosition; |
|
|
|
firstStepToFindTips(beginPosition); |
|
|
|
firstStepToFindTips(beginPosition); |
|
|
|
fixFunctionNameList(); |
|
|
|
if (tipsList.getSelectedValue() != null) { |
|
|
|
|
|
|
|
fixFunctionNameList(tipsList.getSelectedValue().toString()); |
|
|
|
|
|
|
|
} |
|
|
|
ifHasBeenWriten = 1; |
|
|
|
ifHasBeenWriten = 1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -650,17 +786,12 @@ 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; |
|
|
|
FormulaCheckResult checkResult = FormulaChecker.check(formulaText); |
|
|
|
try { |
|
|
|
confirmCheckResult(checkResult); |
|
|
|
formulaValidMessage = FormulaChecker.check(formulaText); |
|
|
|
|
|
|
|
showMessageDialog(formulaValidMessage + "."); |
|
|
|
|
|
|
|
} catch (FormulaCheckerException e) { |
|
|
|
|
|
|
|
formulaValidMessage = e.getMessage(); |
|
|
|
|
|
|
|
showMessageDialog(formulaValidMessage + ".", false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final ActionListener calculateActionListener = new ActionListener() { |
|
|
|
private final ActionListener calculateActionListener = new ActionListener() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
@ -671,20 +802,10 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
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 (ComparatorUtils.equals(formulaValidMessage, INVALID_FORMULA)) { |
|
|
|
FormulaCheckResult checkResult = FormulaChecker.check(formulaText); |
|
|
|
messageTips = INVALID_FORMULA; |
|
|
|
if (checkResult.isValid()) { |
|
|
|
} else { |
|
|
|
messageTips = checkResult.getTips() + NEWLINE; |
|
|
|
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); |
|
|
@ -704,19 +825,42 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
String objectToString = EssentialUtils.objectToString(value); |
|
|
|
String objectToString = EssentialUtils.objectToString(value); |
|
|
|
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 + 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.getMessage(), utilEvalError); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
messageTips = checkResult.getTips(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (checkResult.isValid()) { |
|
|
|
|
|
|
|
showMessageDialog(messageTips, checkResult.isValid()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
confirmCheckResult(checkResult); |
|
|
|
} |
|
|
|
} |
|
|
|
showMessageDialog(messageTips, formulaValid); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
private void showMessageDialog(String message) { |
|
|
|
private boolean confirmCheckResult(FormulaCheckResult checkResult) { |
|
|
|
showMessageDialog(message, true); |
|
|
|
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) { |
|
|
|
private void showMessageDialog(String message, boolean formulaValid) { |
|
|
@ -750,6 +894,18 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
return null; |
|
|
|
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) { |
|
|
|
private Map<String, Object> setParamsIfExist(String formulaText) { |
|
|
|
Map<String, Object> parameterMap = new HashMap<>(); |
|
|
|
Map<String, Object> parameterMap = new HashMap<>(); |
|
|
|
try { |
|
|
|
try { |
|
|
@ -990,7 +1146,8 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
|
|
|
|
|
|
|
|
private void initDescriptionTextArea() { |
|
|
|
private void initDescriptionTextArea() { |
|
|
|
// Description
|
|
|
|
// Description
|
|
|
|
descriptionTextArea = new UITextArea(16, 27); |
|
|
|
descriptionTextArea = new UITextArea(); |
|
|
|
|
|
|
|
descriptionTextArea.setPreferredSize(new Dimension(350, 200)); |
|
|
|
|
|
|
|
|
|
|
|
UIScrollPane desScrollPane = new UIScrollPane(descriptionTextArea); |
|
|
|
UIScrollPane desScrollPane = new UIScrollPane(descriptionTextArea); |
|
|
|
desScrollPane.setBorder(null); |
|
|
|
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) { |
|
|
|
public void populate(VariableResolver variableResolver) { |
|
|
|
// varibale tree.
|
|
|
|
// varibale tree.
|
|
|
|
DefaultTreeModel variableModel = (DefaultTreeModel) variablesTree.getModel(); |
|
|
|
DefaultTreeModel variableModel = (DefaultTreeModel) variablesTree.getModel(); |
|
|
@ -1326,12 +1487,12 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
buffer.append(name.toUpperCase()); |
|
|
|
buffer.append(name.toUpperCase()); |
|
|
|
buffer.append("\""); |
|
|
|
buffer.append("\""); |
|
|
|
buffer.append("|"); |
|
|
|
buffer.append("|"); |
|
|
|
buffer.append("\n"); |
|
|
|
buffer.append(NEWLINE); |
|
|
|
buffer.append("\""); |
|
|
|
buffer.append("\""); |
|
|
|
buffer.append(name.toLowerCase()); |
|
|
|
buffer.append(name.toLowerCase()); |
|
|
|
buffer.append("\""); |
|
|
|
buffer.append("\""); |
|
|
|
buffer.append("|"); |
|
|
|
buffer.append("|"); |
|
|
|
buffer.append("\n"); |
|
|
|
buffer.append(NEWLINE); |
|
|
|
} |
|
|
|
} |
|
|
|
FineLoggerFactory.getLogger().debug(buffer.toString()); |
|
|
|
FineLoggerFactory.getLogger().debug(buffer.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|