From 452531bd0c0c66565a82b377745669cf2c1a125d Mon Sep 17 00:00:00 2001 From: "Bruce.Deng" Date: Fri, 5 Nov 2021 11:42:43 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-58836=20=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E4=BA=8C=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../javascript/ExportJavaScriptPane.java | 950 ++++++++++++++---- 1 file changed, 758 insertions(+), 192 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/javascript/ExportJavaScriptPane.java b/designer-base/src/main/java/com/fr/design/javascript/ExportJavaScriptPane.java index 460e838c51..6c2e46e985 100644 --- a/designer-base/src/main/java/com/fr/design/javascript/ExportJavaScriptPane.java +++ b/designer-base/src/main/java/com/fr/design/javascript/ExportJavaScriptPane.java @@ -3,6 +3,7 @@ package com.fr.design.javascript; import com.fr.base.BaseFormula; import com.fr.base.Parameter; import com.fr.base.extension.FileExtension; +import com.fr.design.border.UITitledBorder; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.DialogActionAdapter; @@ -15,6 +16,10 @@ import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.icombobox.UIComboBoxRenderer; import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itableeditorpane.ParameterTableModel; +import com.fr.design.gui.itableeditorpane.UITableEditAction; +import com.fr.design.gui.itableeditorpane.UITableEditorPane; +import com.fr.design.gui.itableeditorpane.UITableModelAdapter; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.gui.itree.filetree.TemplateFileTree; import com.fr.design.hyperlink.AbstractHyperLinkPane; @@ -23,32 +28,40 @@ import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.DesignerContext; -import com.fr.design.scrollruler.ModLineBorder; import com.fr.file.filetree.IOFileNodeFilter; import com.fr.general.GeneralUtils; import com.fr.js.ExportJavaScript; +import com.fr.js.SingleJavaScript; import com.fr.stable.ParameterProvider; import com.fr.stable.StringUtils; import javax.swing.AbstractButton; +import javax.swing.AbstractCellEditor; import javax.swing.BorderFactory; import javax.swing.ButtonGroup; import javax.swing.DefaultComboBoxModel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.JTable; import javax.swing.SwingUtilities; +import javax.swing.event.CellEditorListener; +import javax.swing.event.ChangeEvent; import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelListener; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Component; -import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -59,21 +72,20 @@ public class ExportJavaScriptPane extends AbstractHyperLinkPane EXPORT_TYPES_MAP = new HashMap<>(); - private static final String CURRENT_TEMPLATE = "current"; - private static final String DEFAULT_FILENAME = "default"; - + private static final Map FILENAME_TYPE_MAP = new HashMap<>(); + private static final Map PARAMETER_TYPE_MAP = new HashMap<>(); + private static final String DEFAULT = "default"; + private static final String CUSTOM = "custom"; + private static final String CURRENT_TEMPLATE = "cur"; + private static final String OTHER_TEMPLATE = "other"; + private static final UILabel EMPTY_LABEL = new UILabel(); static { EXPORT_TYPES_MAP.put(ExportJavaScript.EXPORT_PDF, Toolkit.i18nText("Fine-Design_Basic_Export_JS_PDF")); @@ -82,135 +94,703 @@ public class ExportJavaScriptPane extends AbstractHyperLinkPane" + Toolkit.i18nText("Fine-Design_Basic_Export_JS_Title_Tip_Front") + "\\/:*?\"<>|" + Toolkit.i18nText("Fine-Design_Basic_Export_JS_Title_Tip_Back") + ""); + fileNameTipLabel.setVisible(false); + fileNameRadioGroup.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (defaultNameRadio.isSelected()) { + fileNameFormulaEditor.setVisible(false); + fileNameFormulaEditor.setEnabled(false); + fileNameTipLabel.setVisible(false); + } else { + fileNameFormulaEditor.setVisible(true); + fileNameFormulaEditor.setEnabled(true); + fileNameTipLabel.setVisible(true); + } + } + }); + Component[][] components = new Component[][]{{nameLabel, defaultNameRadio, customNameRadio, fileNameFormulaEditor}}; + JPanel fileNameRadioPane = TableLayoutHelper.createTableLayoutPane(components, new double[]{p}, new double[]{p, p, p, p}); + + JPanel fileNameTipPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + fileNameTipPane.add(fileNameTipLabel); + + JPanel fileNamePane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + fileNamePane.add(fileNameRadioPane, BorderLayout.NORTH); + fileNamePane.add(fileNameTipPane, BorderLayout.CENTER); + fileNameTipPane.setBorder(BorderFactory.createEmptyBorder(5, 2, 5, 2)); + fileNamePane.setBorder(BorderFactory.createEmptyBorder(5, 2, 5, 2)); + return fileNamePane; + } + public void updateSingleJavaScript(SingleJavaScript js){ + js.setTemplatePath(DEFAULT); + js.setExportType(GeneralUtils.objectToString(exportTypeComboBox.getSelectedItem())); + js.setDefaultFileName(defaultNameRadio.isSelected()); + js.setFileName(getFileName()); + js.setExtendParameters(extendParametersCheckBox.isSelected()); + if (extendParametersCheckBox.isSelected()) { + js.setParameters(null); + } else { + if (parameterViewPane != null) { + List parameterList = parameterViewPane.update(); + if (!parameterList.isEmpty()) { + Parameter[] parameters = new Parameter[parameterList.size()]; + parameterList.toArray(parameters); + js.setParameters(parameters); + } + } + } + } + public void populateSingleJavaScript(SingleJavaScript js){ + exportTypeComboBox.setSelectedItem(js.getExportType()); + fileNameRadioGroup.selectIndexButton(js.isDefaultFileName() ? 0 : 1); + if (!js.isDefaultFileName()) { + fileNameFormulaEditor.setEnabled(true); + fileNameFormulaEditor.setVisible(true); + fileNameTipLabel.setVisible(true); + fileNameFormulaEditor.setValue(BaseFormula.createFormulaBuilder().build(js.getFileName())); + } else { + fileNameFormulaEditor.setVisible(false); + fileNameFormulaEditor.setValue(BaseFormula.createFormulaBuilder().build()); + } + if (js.isExtendParameters()) { + extendParametersCheckBox.setSelected(true); + } else { + extendParametersCheckBox.setSelected(false); + if (this.parameterViewPane != null) { + List parameterList = this.parameterViewPane.update(); + parameterList.clear(); + ParameterProvider[] parameters = js.getParameters(); + this.parameterViewPane.populate(parameters); + } + } + } + private JPanel initExportTypePane() { + UILabel typeLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Export_JS_Type") + ":"); + exportTypeComboBox = getComboBoxWithModel(new String[]{ExportJavaScript.EXPORT_PDF, ExportJavaScript.EXPORT_EXCEL_PAGE, ExportJavaScript.EXPORT_EXCEL_SIMPLE, ExportJavaScript.EXPORT_EXCEL_SHEET, ExportJavaScript.EXPORT_WORD, ExportJavaScript.EXPORT_IMAGE} + , EXPORT_TYPES_MAP); + Component[][] components = new Component[][]{{typeLabel, exportTypeComboBox}}; + + JPanel exportTypePane = TableLayoutHelper.createTableLayoutPane(components, new double[]{p}, new double[]{p, p}); + exportTypePane.setBorder(BorderFactory.createEmptyBorder(5, 2, 5, 2)); + return exportTypePane; + } + + @Override + protected String title4PopupWindow() { + return Toolkit.i18nText("Fine-Design_Basic_Export_JS_Setting"); + } + } - private void initComponents() { - this.setLayout(FRGUIPaneFactory.createBorderLayout()); - this.setBorder(BorderFactory.createTitledBorder(new ModLineBorder(ModLineBorder.TOP), Toolkit.i18nText("Fine-Design_Basic_Export_JS_Setting"))); + // 其他模板 + class OtherTemplatePane extends BasicPane { - //导出模板+导出方式+导出文件名 - JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + private UITableEditorPane editorPane; - //导出模板 - JPanel chooseTemplatePane = initChooseTemplatePane(); - northPane.add(chooseTemplatePane, BorderLayout.NORTH); + public OtherTemplatePane() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + this.setBorder(UITitledBorder.createBorderWithTitle(Toolkit.i18nText("Fine-Design_Basic_Export_JS_Template_Other"))); - //导出方式 - JPanel exportTypePane = initExportTypePane(); - northPane.add(exportTypePane, BorderLayout.CENTER); + editorPane = new UITableEditorPane<>(new ExportJSTableModel()); + editorPane.setHeaderResizing(false); - //导出文件名 - JPanel fileNamePane = initFileNamePane(); - northPane.add(fileNamePane, BorderLayout.SOUTH); + this.add(editorPane, BorderLayout.CENTER); + } - //参数 - JPanel centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - JPanel paramsPane = initParamsPane(); - centerPane.add(paramsPane); + public void reset() { + editorPane.populate(new SingleJavaScript[0]); + } + public void updateExportJavaScript(ExportJavaScript exportJavaScript){ + List javaScripts = editorPane.update(); + for (SingleJavaScript js : javaScripts) { + exportJavaScript.addOtherTemplateJS(js); + } + } + + @Override + protected String title4PopupWindow() { + return Toolkit.i18nText("Fine-Design_Basic_Export_JS_Setting"); + } - this.add(northPane, BorderLayout.NORTH); - this.add(centerPane, BorderLayout.CENTER); } - private JPanel initParamsPane() { - extendParametersCheckBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Basic_Hyperlink_Extends_Report_Parameters")); - extendParametersCheckBox.setSelected(true); - parameterViewPane = new ReportletParameterViewPane(getChartParaType(), getValueEditorPane(), getValueEditorPane()); - parameterViewPane.setVisible(false); - parameterViewPane.addTableEditorListener(new TableModelListener() { - public void tableChanged(TableModelEvent e) { - List list = parameterViewPane.update(); - HashSet tempSet = new HashSet<>(); - for (int i = 0; i < list.size(); i++) { - if (StringUtils.isEmpty(list.get(i).getName())) { - continue; + class ExportJSTableModel extends UITableModelAdapter { + + private static final long serialVersionUID = -3697206557955735642L; + + public ExportJSTableModel() { + super(new String[]{ + Toolkit.i18nText("Fine-Design_Basic_Export_JS_Template_File"), + Toolkit.i18nText("Fine-Design_Basic_Export_JS_Type"), + Toolkit.i18nText("Fine-Design_Basic_Export_JS_Filename"), + Toolkit.i18nText("Fine-Design_Basic_Export_JS_Filename_Custom"), + Toolkit.i18nText("Fine-Design_Basic_Export_JS_Parameters_Setting"), + StringUtils.EMPTY}); + this.setColumnClass(new Class[]{ + ExportTemplateChooser.class, + ExportTypeCombobox.class, + FileNameCombobox.class, + FileNameFormulaEditor.class, + ParameterCombobox.class, + ParameterSettingButton.class + }); + this.setDefaultEditor(ExportTemplateChooser.class, new ExportTemplateChooser()); + this.setDefaultRenderer(ExportTemplateChooser.class, new ExportTemplateChooser()); + this.setDefaultEditor(ExportTypeCombobox.class, new ExportTypeCombobox()); + this.setDefaultEditor(FileNameCombobox.class, new FileNameCombobox()); + this.setDefaultEditor(FileNameFormulaEditor.class, new FileNameFormulaEditor()); + this.setDefaultEditor(ParameterCombobox.class, new ParameterCombobox()); + this.setDefaultEditor(ParameterSettingButton.class, new ParameterSettingButton()); + this.setDefaultRenderer(ParameterSettingButton.class, new ParameterSettingButton()); + this.createTable().getColumnModel().getColumn(2).setMaxWidth(60); + this.createTable().getColumnModel().getColumn(4).setMaxWidth(60); + this.createTable().getColumnModel().getColumn(5).setMaxWidth(50); + } + + @Override + public UITableEditAction[] createAction() { + return new UITableEditAction[]{new AddJSAction(), new DeleteAction()}; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + SingleJavaScript js = this.getList().get(rowIndex); + switch (columnIndex) { + case 0: + return js.getTemplatePath(); + case 1: + return EXPORT_TYPES_MAP.get(js.getExportType()); + case 2: + return js.isDefaultFileName() ? Toolkit.i18nText("Fine-Design_Basic_Export_JS_Filename_Default") : Toolkit.i18nText("Fine-Design_Basic_Export_JS_Custom"); + case 3: + return js.getFileName(); + case 4: + return js.isExtendParameters() ? Toolkit.i18nText("Fine-Design_Basic_Export_JS_Extend_Parameters") : Toolkit.i18nText("Fine-Design_Basic_Export_JS_Custom"); + case 5: + return js.getParameters(); + } + return null; + } + + @Override + public boolean isCellEditable(int row, int col) { + if (col == 3) { + // 命名详情 + return this.getList().get(row) != null && !this.getList().get(row).isDefaultFileName(); + } + return true; + } + + private class AddJSAction extends AddTableRowAction { + + public AddJSAction() { + + } + + @Override + public void actionPerformed(ActionEvent e) { + super.actionPerformed(e); + if (otherTemplatePane.editorPane.getTableModel().getList().size() <= 50) { + addJS(); + } else { + FineJOptionPane.showMessageDialog(otherTemplatePane, Toolkit.i18nText("Fine-Design_Basic_Export_JS_Batch_Export_Limit")); + } + } + } + + private void addJS() { + SingleJavaScript js = new SingleJavaScript(); + addRow(js); + fireTableDataChanged(); + table.getSelectionModel().setSelectionInterval(table.getRowCount() - 1, table.getRowCount() - 1); + } + + // 导出文件选择 + class ExportTemplateChooser extends AbstractCellEditor implements TableCellEditor, TableCellRenderer { + + private static final long serialVersionUID = -9112506131272704717L; + private JPanel reportletNamePane; + private UITextField reportPathTextField; + private UIButton browserButton; + + public ExportTemplateChooser() { + // 路径输入框 + reportPathTextField = new UITextField(8); + reportPathTextField.setEnabled(false); + + // 选择路径按钮 + browserButton = new UIButton("..."); + browserButton.setVisible(true); + + Component[][] templateChooserComponent = {{reportPathTextField, browserButton}}; + double[] rowSize = {TableLayout.PREFERRED}; + double[] columnSize = {TableLayout.FILL, 22}; + reportletNamePane = TableLayoutHelper.createCommonTableLayoutPane(templateChooserComponent, rowSize, columnSize, 0); + + browserButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent evt) { + final ReportletPane reportletPane = new ReportletPane(); + reportletPane.setSelectedReportletPath(reportPathTextField.getText()); + BasicDialog reportletDialog = reportletPane.showWindow(SwingUtilities.getWindowAncestor(ExportJavaScriptPane.this)); + + reportletDialog.addDialogActionListener(new DialogActionAdapter() { + @Override + public void doOk() { + reportPathTextField.setText(reportletPane.getSelectedReportletPath()); + } + }); + reportletDialog.setVisible(true); } - if (tempSet.contains(list.get(i).toString())) { - list.remove(i); - FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Parameter_Duplicate_Name") + "!"); - return; + }); + this.addCellEditorListener(new CellEditorListener() { + + @Override + public void editingCanceled(ChangeEvent e) { + } - tempSet.add(list.get(i).toString()); + + @Override + public void editingStopped(ChangeEvent e) { + if (table.getSelectedRow() == -1) { + return; + } + SingleJavaScript js = getList().get(table.getSelectedRow()); + String value = StringUtils.trimToNull(reportPathTextField.getText()); + js.setTemplatePath(value); + js.setCurrentTemplate(false); + fireTableDataChanged(); + } + }); + + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + reportPathTextField.setText((String) value); + return reportletNamePane; + } + + @Override + public Object getCellEditorValue() { + return reportPathTextField.getText(); + } + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + reportPathTextField.setText((String) value); + return reportletNamePane; + } + } + + // 导出方式下拉框 + class ExportTypeCombobox extends AbstractCellEditor implements TableCellEditor { + + private static final long serialVersionUID = -6564079764032351372L; + + private UIComboBox exportTypeComboBox; + + public ExportTypeCombobox() { + exportTypeComboBox = getComboBoxWithModel(new String[]{ExportJavaScript.EXPORT_PDF, ExportJavaScript.EXPORT_EXCEL_PAGE, ExportJavaScript.EXPORT_EXCEL_SIMPLE, ExportJavaScript.EXPORT_EXCEL_SHEET, ExportJavaScript.EXPORT_WORD, ExportJavaScript.EXPORT_IMAGE} + , EXPORT_TYPES_MAP); + this.addCellEditorListener(new CellEditorListener() { + + @Override + public void editingCanceled(ChangeEvent e) { + + } + + @Override + public void editingStopped(ChangeEvent e) { + if (table.getSelectedRow() == -1) { + return; + } + SingleJavaScript js = getList().get(table.getSelectedRow()); + Object ob = exportTypeComboBox.getSelectedItem(); + if (ob != null) { + String value = ob.toString(); + js.setExportType(value); + } + fireTableDataChanged(); + } + }); + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + exportTypeComboBox.setSelectedItem(getList().get(row).getExportType()); + return exportTypeComboBox; + } + + @Override + public Object getCellEditorValue() { + Object ob = exportTypeComboBox.getSelectedItem(); + if (ob != null) { + return ob.toString(); } + return ExportJavaScript.EXPORT_PDF; } - }); - extendParametersCheckBox.addItemListener(new ItemListener() { + } + + // 命名方式下拉框 + class FileNameCombobox extends AbstractCellEditor implements TableCellEditor { + + private static final long serialVersionUID = 1829005772744444269L; + private UIComboBox fileNameComboBox; + + public FileNameCombobox() { + fileNameComboBox = getComboBoxWithModel(new String[]{DEFAULT, CUSTOM}, FILENAME_TYPE_MAP); + fileNameComboBox.addItemListener(e -> { + if (e.getStateChange() == ItemEvent.SELECTED) { + final int row = table.getSelectedRow(); + if (row == -1) { + return; + } + SingleJavaScript js = getList().get(row); + Object ob = fileNameComboBox.getSelectedItem(); + if (ob != null) { + String value = ob.toString(); + js.setDefaultFileName(StringUtils.equals(value, DEFAULT)); + if (js.isDefaultFileName()) { + js.setFileName(StringUtils.EMPTY); + } + } + table.repaint(); + } + }); + this.addCellEditorListener(new CellEditorListener() { + + @Override + public void editingCanceled(ChangeEvent e) { + + } + + @Override + public void editingStopped(ChangeEvent e) { + fireTableDataChanged(); + } + }); + } + @Override - public void itemStateChanged(ItemEvent e) { - parameterViewPane.setVisible(e.getStateChange() == ItemEvent.DESELECTED); + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + fileNameComboBox.setSelectedItem(getList().get(row).isDefaultFileName() ? DEFAULT : CUSTOM); + return fileNameComboBox; } - }); - JPanel paramsPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - paramsPane.setBorder(BorderFactory.createTitledBorder(new ModLineBorder(ModLineBorder.TOP), Toolkit.i18nText("Fine-Design_Basic_Parameters"))); - paramsPane.add(extendParametersCheckBox, BorderLayout.NORTH); - JPanel dynamicPaneWrapper = FRGUIPaneFactory.createBorderLayout_S_Pane(); - dynamicPaneWrapper.add(parameterViewPane); - paramsPane.add(dynamicPaneWrapper, BorderLayout.CENTER); - return paramsPane; - } - private JPanel initFileNamePane() { - UILabel nameLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Export_JS_Filename") + ":"); - fileNameRadioGroup = new ExportRadioGroup(); - defaultNameRadio = new UIRadioButton(Toolkit.i18nText("Fine-Design_Basic_Export_JS_Filename_Default")); - defaultNameRadio.setSelected(true); - customNameRadio = new UIRadioButton(Toolkit.i18nText("Fine-Design_Basic_Export_JS_Filename_Custom")); - addRadioToGroup(fileNameRadioGroup, defaultNameRadio, customNameRadio); - fileNameFormulaEditor = new FormulaEditor(Toolkit.i18nText("Fine-Design_Report_Parameter_Formula")); - fileNameFormulaEditor.setEnabled(false); - fileNameRadioGroup.addActionListener(new ActionListener() { @Override - public void actionPerformed(ActionEvent e) { - if (defaultNameRadio.isSelected()) { - fileNameFormulaEditor.setEnabled(false); + public Object getCellEditorValue() { + return fileNameComboBox.getSelectedItem().toString(); + } + } + + // 命名方式公式框 + class FileNameFormulaEditor extends AbstractCellEditor implements TableCellEditor { + + private static final long serialVersionUID = 7120075192535645493L; + private FormulaEditor fileNameFormulaEditor; + + public FileNameFormulaEditor() { + fileNameFormulaEditor = new FormulaEditor(Toolkit.i18nText("Fine-Design_Report_Parameter_Formula")); + this.addCellEditorListener(new CellEditorListener() { + + @Override + public void editingCanceled(ChangeEvent e) { + + } + + @Override + public void editingStopped(ChangeEvent e) { + if (table.getSelectedRow() == -1) { + return; + } + SingleJavaScript js = getList().get(table.getSelectedRow()); + String value = fileNameFormulaEditor.getUITextField().getText(); + js.setFileName(value); + fireTableDataChanged(); + } + }); + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + if (value != null) { + fileNameFormulaEditor.setValue(BaseFormula.createFormulaBuilder().build(value)); } else { - fileNameFormulaEditor.setEnabled(true); + fileNameFormulaEditor.setValue(BaseFormula.createFormulaBuilder().build()); } + return fileNameFormulaEditor; + } + + @Override + public Object getCellEditorValue() { + return fileNameFormulaEditor.getUITextField().getText(); + } + + public FormulaEditor getFileNameEditor() { + return fileNameFormulaEditor; + } + } + + //参数设置下拉框 + class ParameterCombobox extends AbstractCellEditor implements TableCellEditor { + + private static final long serialVersionUID = 2630964402770993584L; + private UIComboBox parameterSetting; + + public ParameterCombobox() { + parameterSetting = getComboBoxWithModel(new String[]{DEFAULT, CUSTOM}, PARAMETER_TYPE_MAP); + parameterSetting.addItemListener(e -> { + if (e.getStateChange() == ItemEvent.SELECTED) { + final int row = table.getSelectedRow(); + if (row == -1) { + return; + } + SingleJavaScript js = getList().get(row); + Object ob = parameterSetting.getSelectedItem(); + if (ob != null) { + String value = ob.toString(); + js.setExtendParameters(StringUtils.equals(value, DEFAULT)); + } + // 单纯为了刷新表格,使某些联动生效 + table.repaint(); + } + }); + this.addCellEditorListener(new CellEditorListener() { + + @Override + public void editingCanceled(ChangeEvent e) { + + } + + @Override + public void editingStopped(ChangeEvent e) { + // 这里重新触发是为了触发某些编辑后事件 + fireTableDataChanged(); + } + }); + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + parameterSetting.setSelectedItem(getList().get(row).isExtendParameters() ? DEFAULT : CUSTOM); + return parameterSetting; } - }); - Component[][] components = new Component[][]{{nameLabel, defaultNameRadio, customNameRadio, fileNameFormulaEditor}}; - JPanel fileNameRadioPane = TableLayoutHelper.createTableLayoutPane(components, new double[]{p}, new double[]{p, p, p, p}); - - JPanel fileNameTipPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - UILabel fileNameTipLabel = new UILabel("" + Toolkit.i18nText("Fine-Design_Basic_Export_JS_Title_Tip_Front") + "\\/:*?\"<>|" + Toolkit.i18nText("Fine-Design_Basic_Export_JS_Title_Tip_Back") + ""); - fileNameTipPane.add(fileNameTipLabel); - - JPanel fileNamePane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - fileNamePane.add(fileNameRadioPane, BorderLayout.NORTH); - fileNamePane.add(fileNameTipPane, BorderLayout.CENTER); - fileNameTipPane.setBorder(BorderFactory.createEmptyBorder(5,2,5,2)); - fileNamePane.setBorder(BorderFactory.createEmptyBorder(5,2,5,2)); - return fileNamePane; - } - private JPanel initExportTypePane() { - UILabel typeLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Export_JS_Type") + ":"); - exportTypeComboBox = new UIComboBox(new DefaultComboBoxModel()); - DefaultComboBoxModel comboBoxModel = (DefaultComboBoxModel) exportTypeComboBox.getModel(); - String[] allExportTypes = new String[]{ExportJavaScript.EXPORT_PDF, ExportJavaScript.EXPORT_EXCEL_PAGE, ExportJavaScript.EXPORT_EXCEL_SIMPLE, ExportJavaScript.EXPORT_EXCEL_SHEET, ExportJavaScript.EXPORT_WORD, ExportJavaScript.EXPORT_IMAGE}; - for (int i = 0; i < allExportTypes.length; i++) { - comboBoxModel.addElement(allExportTypes[i]); + @Override + public Object getCellEditorValue() { + return parameterSetting.getSelectedItem().toString(); + } } - this.exportTypeComboBox.setRenderer(new UIComboBoxRenderer() { + + // 参数设置按钮 + class ParameterSettingButton extends AbstractCellEditor implements TableCellEditor, TableCellRenderer { + + private static final long serialVersionUID = 4021592871993049137L; + private UIButton paraButton; + private ParameterSettingPane paraSettingPane; + ParameterProvider[] parameterArr; + + public ParameterSettingButton() { + paraSettingPane = new ParameterSettingPane(); + paraButton = new UIButton(Toolkit.i18nText("Fine-Design_Report_Set")); + paraButton.addMouseListener(new MouseAdapter() { + + @Override + public void mousePressed(MouseEvent e) { + BasicDialog dialog = paraSettingPane.showWindow(SwingUtilities.getWindowAncestor(ExportJavaScriptPane.this)); + dialog.addDialogActionListener(new DialogActionAdapter() { + @Override + public void doOk() { + List parameterList = paraSettingPane.getParameterList(); + parameterArr = parameterList.toArray(new Parameter[parameterList.size()]); + } + }); + dialog.setVisible(true); + } + + }); + this.addCellEditorListener(new CellEditorListener() { + + @Override + public void editingCanceled(ChangeEvent e) { + + } + + @Override + public void editingStopped(ChangeEvent e) { + if (table.getSelectedRow() == -1) { + return; + } + SingleJavaScript js = getList().get(table.getSelectedRow()); + if (parameterArr != null) { + js.setParameters(parameterArr); + } + parameterArr = null; + fireTableDataChanged(); + } + }); + + } @Override - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - if (value instanceof String) { - this.setText(EXPORT_TYPES_MAP.get(value)); + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + if (getList().get(row) == null || getList().get(row).isExtendParameters()) { + return EMPTY_LABEL; } - return this; + ParameterProvider[] providers = (ParameterProvider[]) value; + if (providers != null) { + paraSettingPane.refresh(new ArrayList<>(Arrays.asList(providers))); + } + return paraButton; + } + + @Override + public Object getCellEditorValue() { + return paraSettingPane.getParameterList(); } - }); - Component[][] components = new Component[][]{{typeLabel, exportTypeComboBox}}; - JPanel exportTypePane = TableLayoutHelper.createTableLayoutPane(components, new double[]{p}, new double[]{p, p}); - exportTypePane.setBorder(BorderFactory.createEmptyBorder(5,2,5,2)); - return exportTypePane; + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + if (getList().get(row) == null || getList().get(row).isExtendParameters()) { + return EMPTY_LABEL; + } + return paraButton; + } + } + + // 参数设置弹出框 + class ParameterSettingPane extends BasicPane { + + private ReportletParameterViewPane parameterViewPane; + + public ParameterSettingPane() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + parameterViewPane = new ReportletParameterViewPane(ParameterTableModel.NO_CHART_USE, getValueEditorPane(), getValueEditorPane()); + addListener(parameterViewPane); + this.add(parameterViewPane); + } + + @Override + protected String title4PopupWindow() { + return Toolkit.i18nText("Fine-Design_Basic_Export_JS_Parameters_Setting"); + } + + public List getParameterList() { + return parameterViewPane.update(); + } + + public void refresh(List list) { + parameterViewPane.update(list); + } + + } + + } + + public ExportJavaScriptPane() { + initComponents(); + } + + private void initComponents() { + JPanel totalPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); + totalPanel.setBorder(UITitledBorder.createBorderWithTitle(Toolkit.i18nText("Fine-Design_Basic_Export_JS_Setting"))); + + // 导出模板 + JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + JPanel chooseTemplatePane = initChooseTemplatePane(); + northPane.add(chooseTemplatePane, BorderLayout.NORTH); + + // 默认当前模板 + currentTemplatePane = new CurrentTemplatePane(); + otherTemplatePane = new OtherTemplatePane(); + templatePanel = FRGUIPaneFactory.createCardLayout_S_Pane(); + card = new CardLayout(); + templatePanel.setLayout(card); + templatePanel.add(CURRENT_TEMPLATE, currentTemplatePane); + templatePanel.add(OTHER_TEMPLATE, otherTemplatePane); + + totalPanel.add(northPane, BorderLayout.NORTH); + totalPanel.add(templatePanel, BorderLayout.CENTER); + + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + this.add(totalPanel); } private JPanel initChooseTemplatePane() { @@ -220,51 +800,28 @@ public class ExportJavaScriptPane extends AbstractHyperLinkPane parameterList = this.parameterViewPane.update(); - parameterList.clear(); - ParameterProvider[] parameters = ob.getParameters(); - this.parameterViewPane.populate(parameters); - } + currentTemplatePane.populateSingleJavaScript(ob.getCurrentTemplateJavaScript()); + + OtherTemplatePane pane = (OtherTemplatePane) this.templatePanel.getComponent(1); + pane.editorPane.populate(ob.getJsListForOtherTemplates().toArray(new SingleJavaScript[ob.getJsListForOtherTemplates().size()])); } @Override @@ -309,32 +848,59 @@ public class ExportJavaScriptPane extends AbstractHyperLinkPane parameterList = this.parameterViewPane.update(); - if (!parameterList.isEmpty()) { - Parameter[] parameters = new Parameter[parameterList.size()]; - parameterList.toArray(parameters); - exportJavaScript.setParameters(parameters); - } - } - } + boolean selected = currentTemplateRadio.isSelected(); + exportJavaScript.setCurrentTemplate(selected); + SingleJavaScript js = new SingleJavaScript(); + js.setCurrentTemplate(selected); + currentTemplatePane.updateSingleJavaScript(js); + exportJavaScript.addCurrentTemplateJS(js); - private String getTemplatePath() { - return currentTemplateRadio.isSelected() ? CURRENT_TEMPLATE : reportPathTextField.getText(); + otherTemplatePane.updateExportJavaScript(exportJavaScript); } private String getFileName() { - return defaultNameRadio.isSelected() ? DEFAULT_FILENAME : fileNameFormulaEditor.getUITextField().getText(); + return currentTemplatePane.defaultNameRadio.isSelected() ? DEFAULT : currentTemplatePane.fileNameFormulaEditor.getUITextField().getText(); } + private UIComboBox getComboBoxWithModel(String[] itemTextArr, Map itemTextDic) { + UIComboBox comboBox = new UIComboBox(new DefaultComboBoxModel()); + DefaultComboBoxModel comboBoxModel = (DefaultComboBoxModel) comboBox.getModel(); + for (int i = 0; i < itemTextArr.length; i++) { + comboBoxModel.addElement(itemTextArr[i]); + } + comboBox.setRenderer(new UIComboBoxRenderer() { + + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + if (value instanceof String) { + this.setText(itemTextDic.get(value)); + } + return this; + } + }); + return comboBox; + } + + private void addListener(ReportletParameterViewPane paraPane) { + paraPane.addTableEditorListener(new TableModelListener() { + public void tableChanged(TableModelEvent e) { + List list = paraPane.update(); + HashSet tempSet = new HashSet<>(); + for (int i = 0; i < list.size(); i++) { + if (StringUtils.isEmpty(list.get(i).getName())) { + continue; + } + if (tempSet.contains(list.get(i).toString())) { + list.remove(i); + FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Parameter_Duplicate_Name") + "!"); + return; + } + tempSet.add(list.get(i).toString()); + } + } + }); + } @Override public boolean accept(Object ob) {