|
|
|
@ -1,41 +1,46 @@
|
|
|
|
|
package com.fr.solution.plugin.design.formula.ui; |
|
|
|
|
|
|
|
|
|
import com.fanruan.api.cal.CalculatorKit; |
|
|
|
|
import com.fanruan.api.cal.ParameterKit; |
|
|
|
|
import com.fanruan.api.design.DesignKit; |
|
|
|
|
import com.fanruan.api.design.macro.UIConstants; |
|
|
|
|
import com.fanruan.api.design.ui.action.UpdateAction; |
|
|
|
|
import com.fanruan.api.design.ui.component.UIButton; |
|
|
|
|
import com.fanruan.api.design.ui.component.UILabel; |
|
|
|
|
import com.fanruan.api.design.ui.component.UIQuickList; |
|
|
|
|
import com.fanruan.api.design.ui.component.UIRoundedBorder; |
|
|
|
|
import com.fanruan.api.design.ui.component.UITextArea; |
|
|
|
|
import com.fanruan.api.design.ui.component.UITextField; |
|
|
|
|
import com.fanruan.api.design.ui.container.BasicPane; |
|
|
|
|
import com.fanruan.api.design.ui.container.UIScrollPane; |
|
|
|
|
import com.fanruan.api.design.util.GUICoreKit; |
|
|
|
|
import com.fanruan.api.design.work.ParameterInputPane; |
|
|
|
|
import com.fanruan.api.log.LogKit; |
|
|
|
|
import com.fanruan.api.macro.EncodeConstants; |
|
|
|
|
import com.fanruan.api.util.ArrayKit; |
|
|
|
|
import com.fanruan.api.util.GeneralKit; |
|
|
|
|
import com.fanruan.api.util.IOKit; |
|
|
|
|
import com.fanruan.api.util.StringKit; |
|
|
|
|
import com.fr.base.BaseFormula; |
|
|
|
|
import com.fr.base.BaseUtils; |
|
|
|
|
import com.fr.base.FRContext; |
|
|
|
|
import com.fr.base.Parameter; |
|
|
|
|
import com.fr.base.ParameterMapNameSpace; |
|
|
|
|
import com.fr.base.io.IOFile; |
|
|
|
|
import com.fr.data.TableDataSource; |
|
|
|
|
import com.fr.design.actions.UpdateAction; |
|
|
|
|
import com.fr.design.border.UIRoundedBorder; |
|
|
|
|
import com.fr.design.constants.UIConstants; |
|
|
|
|
import com.fr.design.dialog.BasicDialog; |
|
|
|
|
import com.fr.design.dialog.BasicPane; |
|
|
|
|
import com.fr.design.dialog.DialogActionAdapter; |
|
|
|
|
import com.fr.design.file.HistoryTemplateListPane; |
|
|
|
|
import com.fr.design.formula.FunctionGroup; |
|
|
|
|
import com.fr.design.formula.NameAndDescription; |
|
|
|
|
import com.fr.design.formula.UIFormula; |
|
|
|
|
import com.fr.design.formula.VariableResolver; |
|
|
|
|
import com.fr.design.gui.ibutton.UIButton; |
|
|
|
|
import com.fr.design.gui.icontainer.UIScrollPane; |
|
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
|
|
|
import com.fr.design.gui.ilist.QuickList; |
|
|
|
|
import com.fr.design.gui.itextarea.UITextArea; |
|
|
|
|
import com.fr.design.gui.itextfield.UITextField; |
|
|
|
|
import com.fr.design.layout.FRGUIPaneFactory; |
|
|
|
|
import com.fr.design.mainframe.DesignerContext; |
|
|
|
|
import com.fr.design.mainframe.JTemplate; |
|
|
|
|
import com.fr.design.parameter.ParameterInputPane; |
|
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
|
import com.fr.general.FRLogger; |
|
|
|
|
import com.fr.general.GeneralUtils; |
|
|
|
|
import com.fr.report.core.namespace.SimpleCellValueNameSpace; |
|
|
|
|
import com.fr.script.Calculator; |
|
|
|
|
import com.fr.solution.plugin.design.formula.compat.DesignToolkit; |
|
|
|
|
import com.fr.solution.plugin.design.formula.compat.FunctionConstants; |
|
|
|
|
import com.fr.solution.plugin.design.formula.ui.evt.OperateListener; |
|
|
|
|
import com.fr.solution.plugin.design.formula.ui.type.CategoryFormulaPane; |
|
|
|
|
import com.fr.stable.ParameterProvider; |
|
|
|
|
import com.fr.stable.script.CalculatorProvider; |
|
|
|
|
import com.fr.stable.ArrayUtils; |
|
|
|
|
import com.fr.stable.EncodeConstants; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
import com.fr.stable.UtilEvalError; |
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
|
import javax.swing.event.ListSelectionEvent; |
|
|
|
@ -64,10 +69,6 @@ import java.io.StringReader;
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.Locale; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.Comparator; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 组合了普通公式和脚本公式的编辑器面板 |
|
|
|
@ -84,7 +85,7 @@ public class GroupFormulaPane extends BasicPane implements UIFormula, OperateLis
|
|
|
|
|
private DefaultListModel listModel = new DefaultListModel(); |
|
|
|
|
|
|
|
|
|
private DefaultListModel functionTypeListModel = new DefaultListModel(); |
|
|
|
|
private UIQuickList functionTypeList; |
|
|
|
|
private QuickList functionTypeList; |
|
|
|
|
private DefaultListModel functionNameModel; |
|
|
|
|
private JList functionNameList; |
|
|
|
|
|
|
|
|
@ -119,9 +120,9 @@ public class GroupFormulaPane extends BasicPane implements UIFormula, OperateLis
|
|
|
|
|
protected void initComponents() { |
|
|
|
|
this.setLayout(new BorderLayout(4, 4)); |
|
|
|
|
// text
|
|
|
|
|
JPanel textPane = GUICoreKit.createBorderLayoutPane(); |
|
|
|
|
JPanel textPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
|
|
|
this.add(textPane, BorderLayout.CENTER); |
|
|
|
|
JPanel checkBoxAndButtonPane = GUICoreKit.createFlowPane(); |
|
|
|
|
JPanel checkBoxAndButtonPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); |
|
|
|
|
UILabel formulaLabel = new UILabel(DesignToolkit.getLocText("Plugin-Design_Basic_FormulaD_Input_Formula_In_The_Text_Area_Below") + ":" |
|
|
|
|
+ " "); |
|
|
|
|
formulaLabel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); |
|
|
|
@ -141,10 +142,10 @@ public class GroupFormulaPane extends BasicPane implements UIFormula, OperateLis
|
|
|
|
|
UIButton calculateButton = new UIButton(DesignToolkit.getLocText("Plugin-Design_Group_Formula_Calculate")); |
|
|
|
|
calculateButton.addActionListener(calculateActionListener); |
|
|
|
|
|
|
|
|
|
JPanel checkBoxPane = GUICoreKit.createFlowPane(); |
|
|
|
|
checkBoxPane.setPreferredSize(new Dimension(440, 30)); |
|
|
|
|
JPanel checkBoxPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); |
|
|
|
|
checkBoxPane.setPreferredSize(new Dimension(450, 30)); |
|
|
|
|
checkBoxAndButtonPane.add(checkBoxPane, BorderLayout.WEST); |
|
|
|
|
checkBoxAndButtonPane.add(GUICoreKit.createFlowPane(checkValidButton, calculateButton), BorderLayout.CENTER); |
|
|
|
|
checkBoxAndButtonPane.add(GUICoreUtils.createFlowPane(checkValidButton, calculateButton), BorderLayout.EAST); |
|
|
|
|
extendCheckBoxPane(checkBoxPane); |
|
|
|
|
variableTreeAndDescriptionArea = new VariableTreeAndDescriptionArea(); |
|
|
|
|
this.add(variableTreeAndDescriptionArea, BorderLayout.SOUTH); |
|
|
|
@ -247,19 +248,15 @@ public class GroupFormulaPane extends BasicPane implements UIFormula, OperateLis
|
|
|
|
|
if (keyWord.length() != 0) { |
|
|
|
|
NameAndDescription[] descriptions = FunctionConstants.ALL.getDescriptions(); |
|
|
|
|
int lengthOfDes = descriptions.length; |
|
|
|
|
List<String> list = new ArrayList<String>(); |
|
|
|
|
for (int i = 0; i < lengthOfDes; i++) { |
|
|
|
|
NameAndDescription and = descriptions[i]; |
|
|
|
|
|
|
|
|
|
String functionName = and.searchResult(keyWord, findDescription); |
|
|
|
|
if (StringKit.isNotBlank(functionName)) { |
|
|
|
|
list.add(functionName); |
|
|
|
|
if (StringUtils.isNotBlank(functionName)) { |
|
|
|
|
listModel.addElement(functionName); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Collections.sort(list, new SimilarComparator(keyWord)); |
|
|
|
|
for (String name : list) { |
|
|
|
|
listModel.addElement(name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!listModel.isEmpty()) { |
|
|
|
|
tipsList.setSelectedIndex(0); |
|
|
|
|
refreshDescriptionTextArea((String) listModel.getElementAt(0)); |
|
|
|
@ -325,54 +322,41 @@ public class GroupFormulaPane extends BasicPane implements UIFormula, OperateLis
|
|
|
|
|
private ActionListener calculateActionListener = new ActionListener() { |
|
|
|
|
@Override |
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
CalculatorProvider calculator = CalculatorKit.createCalculator(); |
|
|
|
|
JTemplate<?, ?> template = DesignKit.getCurrentEditingTemplate(); |
|
|
|
|
Calculator calculator = Calculator.createCalculator(); |
|
|
|
|
JTemplate<?, ?> template = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); |
|
|
|
|
if (template != null) { |
|
|
|
|
TableDataSource file = (TableDataSource) template.getTarget(); |
|
|
|
|
IOFile file = (IOFile) template.getTarget(); |
|
|
|
|
calculator.setAttribute(TableDataSource.class, file); |
|
|
|
|
calculator.pushNameSpace(CalculatorKit.createSimpleCellValueNameSpace()); |
|
|
|
|
calculator.pushNameSpace(SimpleCellValueNameSpace.getInstance()); |
|
|
|
|
} |
|
|
|
|
BaseFormula formula = GroupFormulaPane.this.update(); |
|
|
|
|
String message = calculate(formula, formulaPane.analyze4Parameters(calculator), calculator); |
|
|
|
|
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(GroupFormulaPane.this), message); |
|
|
|
|
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), message); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
private String calculate(BaseFormula formula, ParameterProvider[] parameters, CalculatorProvider calculator) { |
|
|
|
|
private String calculate(BaseFormula formula, Parameter[] parameters, Calculator calculator) { |
|
|
|
|
final Map<String, Object> parameterMap = new HashMap<String, Object>(); |
|
|
|
|
if (ArrayKit.isNotEmpty(parameters)) { |
|
|
|
|
if (ArrayUtils.isNotEmpty(parameters)) { |
|
|
|
|
final ParameterInputPane pPane = new ParameterInputPane(parameters); |
|
|
|
|
pPane.showSmallWindow(DesignKit.getDesignerFrame(), new DialogActionAdapter() { |
|
|
|
|
pPane.showSmallWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { |
|
|
|
|
@Override |
|
|
|
|
public void doOk() { |
|
|
|
|
parameterMap.putAll(pPane.update()); |
|
|
|
|
} |
|
|
|
|
}).setVisible(true); |
|
|
|
|
} |
|
|
|
|
calculator.pushNameSpace(ParameterKit.createParameterMapNameSpace(realMap(parameterMap))); |
|
|
|
|
calculator.pushNameSpace(ParameterMapNameSpace.create(parameterMap)); |
|
|
|
|
String message; |
|
|
|
|
try { |
|
|
|
|
Object result = formula.evalValue(calculator); |
|
|
|
|
message = DesignToolkit.getLocText("Plugin-Design_Group_Formula_Result") + ":" + GeneralKit.objectToString(result); |
|
|
|
|
} catch (Exception utilEvalError) { |
|
|
|
|
message = DesignToolkit.getLocText("Plugin-Design_Group_Formula_Result") + ":" + GeneralUtils.objectToString(result); |
|
|
|
|
} catch (UtilEvalError utilEvalError) { |
|
|
|
|
message = DesignToolkit.getLocText("Plugin-Design_Group_Formula_Calculate_Error") + ":" + utilEvalError.getMessage(); |
|
|
|
|
} |
|
|
|
|
return message; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Map<String, Object> realMap(Map<String, Object> source) { |
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>(); |
|
|
|
|
for (Map.Entry<String, Object> entry : source.entrySet()) { |
|
|
|
|
String name = entry.getKey(); |
|
|
|
|
if (name.startsWith("$")) { |
|
|
|
|
map.put(name.substring(1), entry.getValue()); |
|
|
|
|
} else { |
|
|
|
|
map.put(name, entry.getValue()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return map; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public class VariableTreeAndDescriptionArea extends JPanel { |
|
|
|
|
|
|
|
|
|
private JTree variablesTree; |
|
|
|
@ -383,7 +367,7 @@ public class GroupFormulaPane extends BasicPane implements UIFormula, OperateLis
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void initFunctionTypeList(JPanel functionPane) { |
|
|
|
|
functionTypeList = new UIQuickList(functionTypeListModel); |
|
|
|
|
functionTypeList = new QuickList(functionTypeListModel); |
|
|
|
|
UIScrollPane functionTypeScrollPane = new UIScrollPane(functionTypeList); |
|
|
|
|
functionTypeScrollPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, UIConstants.ARC)); |
|
|
|
|
functionTypeScrollPane.setPreferredSize(new Dimension(140, 200)); |
|
|
|
@ -490,7 +474,7 @@ public class GroupFormulaPane extends BasicPane implements UIFormula, OperateLis
|
|
|
|
|
popupMenu.add(lookDetailAction); |
|
|
|
|
|
|
|
|
|
// peter: 只有弹出菜单有子菜单的时候,才需要弹出来.
|
|
|
|
|
GUICoreKit.showPopupMenu(popupMenu, functionNameList, evt.getX() - 1, evt.getY() - 1); |
|
|
|
|
GUICoreUtils.showPopupMenu(popupMenu, functionNameList, evt.getX() - 1, evt.getY() - 1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
@ -534,7 +518,7 @@ public class GroupFormulaPane extends BasicPane implements UIFormula, OperateLis
|
|
|
|
|
private StringBuilder getText(TextUserObject selectedValue, String path) throws IOException { |
|
|
|
|
Reader desReader; |
|
|
|
|
StringBuilder desBuf = new StringBuilder(); |
|
|
|
|
InputStream desInputStream = IOKit.readResource(path + (selectedValue).displayText + ".txt"); |
|
|
|
|
InputStream desInputStream = BaseUtils.readResource(path + (selectedValue).displayText + ".txt"); |
|
|
|
|
if (desInputStream == null) { |
|
|
|
|
String description = ""; |
|
|
|
|
desReader = new StringReader(description); |
|
|
|
@ -564,7 +548,7 @@ public class GroupFormulaPane extends BasicPane implements UIFormula, OperateLis
|
|
|
|
|
StringBuilder desBuf = new StringBuilder(); |
|
|
|
|
try { |
|
|
|
|
String path; |
|
|
|
|
Locale locale = GeneralKit.getLocale(); |
|
|
|
|
Locale locale = FRContext.getLocale(); |
|
|
|
|
if (locale.equals(Locale.CHINA)) { |
|
|
|
|
path = "/com/fr/design/insert/formula/variable/cn/"; |
|
|
|
|
} else { |
|
|
|
@ -574,7 +558,7 @@ public class GroupFormulaPane extends BasicPane implements UIFormula, OperateLis
|
|
|
|
|
desBuf = getText((TextUserObject) selectedValue, path); |
|
|
|
|
} |
|
|
|
|
} catch (IOException exp) { |
|
|
|
|
LogKit.error(exp.getMessage(), exp); |
|
|
|
|
FRLogger.getLogger().error(exp.getMessage(), exp); |
|
|
|
|
} |
|
|
|
|
descriptionTextArea.setText(desBuf.toString()); |
|
|
|
|
descriptionTextArea.moveCaretPosition(0); |
|
|
|
@ -619,7 +603,7 @@ public class GroupFormulaPane extends BasicPane implements UIFormula, OperateLis
|
|
|
|
|
public LookDetailAction() { |
|
|
|
|
this.setName(DesignToolkit.getLocText("Plugin-Design_Basic_FormulaPane_Function_Detail")); |
|
|
|
|
this.setMnemonic('L'); |
|
|
|
|
this.setSmallIcon(IOKit.readIcon("/com/fr/design/images/m_file/preview.png")); |
|
|
|
|
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/preview.png")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 弹出的窗口中显示函数的用法明细
|
|
|
|
@ -635,11 +619,12 @@ public class GroupFormulaPane extends BasicPane implements UIFormula, OperateLis
|
|
|
|
|
return DesignToolkit.getLocText("Plugin-Design_Basic_FormulaPane_Function_Detail"); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
basicPane.setLayout(new BorderLayout()); |
|
|
|
|
basicPane.setLayout(FRGUIPaneFactory.createBorderLayout()); |
|
|
|
|
UITextArea desArea = new UITextArea(); |
|
|
|
|
// desArea。setEnabled(false);
|
|
|
|
|
desArea.setText(this.getTextAreaText()); |
|
|
|
|
basicPane.add(new UIScrollPane(desArea), BorderLayout.CENTER); |
|
|
|
|
BasicDialog dialog = basicPane.showWindow(DesignKit.getDesignerFrame()); |
|
|
|
|
BasicDialog dialog = basicPane.showWindow(DesignerContext.getDesignerFrame()); |
|
|
|
|
dialog.setVisible(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -721,24 +706,24 @@ public class GroupFormulaPane extends BasicPane implements UIFormula, OperateLis
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
rootNode.add(new TextFolderUserObject(DesignToolkit.getLocText("Plugin-Design_Basic_FormulaD_Data_Fields"), |
|
|
|
|
IOKit.readIcon("/com/fr/design/images/dialog/table.png"), |
|
|
|
|
BaseUtils.readIcon("/com/fr/design/images/dialog/table.png"), |
|
|
|
|
variableResolver.resolveColumnNames()).createMutableTreeNode()); |
|
|
|
|
|
|
|
|
|
// Set cutReport Variable
|
|
|
|
|
rootNode.add(new TextFolderUserObject(DesignToolkit.getLocText("Plugin-Design_Basic_FormulaPane_Variables"), |
|
|
|
|
IOKit.readIcon("/com/fr/design/images/dialog/variable.png"), |
|
|
|
|
BaseUtils.readIcon("/com/fr/design/images/dialog/variable.png"), |
|
|
|
|
variableResolver.resolveCurReportVariables()).createMutableTreeNode()); |
|
|
|
|
|
|
|
|
|
rootNode.add(new TextFolderUserObject(DesignToolkit.getLocText("Plugin-Design_Basic_Parameter_Source_Type_Tabledata"), |
|
|
|
|
IOKit.readIcon("/com/fr/design/images/dialog/parameter.gif"), |
|
|
|
|
BaseUtils.readIcon("/com/fr/design/images/dialog/parameter.gif"), |
|
|
|
|
variableResolver.resolveTableDataParameterVariables()).createMutableTreeNode()); |
|
|
|
|
|
|
|
|
|
rootNode.add(new TextFolderUserObject(DesignToolkit.getLocText("Plugin-Design_Basic_ParameterD_Report_Parameter"), |
|
|
|
|
IOKit.readIcon("/com/fr/design/images/m_report/p.gif"), |
|
|
|
|
BaseUtils.readIcon("/com/fr/design/images/m_report/p.gif"), |
|
|
|
|
variableResolver.resolveReportParameterVariables()).createMutableTreeNode()); |
|
|
|
|
|
|
|
|
|
rootNode.add(new TextFolderUserObject(DesignToolkit.getLocText("Plugin-Design_Basic_M_Server_Global_Parameters"), |
|
|
|
|
IOKit.readIcon("/com/fr/design/images/dialog/parameter.gif"), |
|
|
|
|
BaseUtils.readIcon("/com/fr/design/images/dialog/parameter.gif"), |
|
|
|
|
variableResolver.resolveGlobalParameterVariables()).createMutableTreeNode()); |
|
|
|
|
|
|
|
|
|
variableModel.reload(); |
|
|
|
@ -780,26 +765,6 @@ public class GroupFormulaPane extends BasicPane implements UIFormula, OperateLis
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static class SimilarComparator implements Comparator<String> { |
|
|
|
|
|
|
|
|
|
private String searchKey; |
|
|
|
|
|
|
|
|
|
public SimilarComparator(String searchKey) { |
|
|
|
|
this.searchKey = searchKey.toLowerCase(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int compare(String o1, String o2) { |
|
|
|
|
if (o1.toLowerCase().startsWith(searchKey)) { |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
if (o2.toLowerCase().startsWith(searchKey)) { |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
return o2.compareTo(o1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static class TextUserObject { |
|
|
|
|
|
|
|
|
|
public TextUserObject(String text) { |
|
|
|
|