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 9adbfff9bf..460e838c51 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,7 +3,6 @@ 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; @@ -16,10 +15,6 @@ 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; @@ -28,40 +23,32 @@ 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; @@ -72,20 +59,21 @@ public class ExportJavaScriptPane extends AbstractHyperLinkPane EXPORT_TYPES_MAP = new HashMap<>(); - 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(); + private static final String CURRENT_TEMPLATE = "current"; + private static final String DEFAULT_FILENAME = "default"; + static { EXPORT_TYPES_MAP.put(ExportJavaScript.EXPORT_PDF, Toolkit.i18nText("Fine-Design_Basic_Export_JS_PDF")); @@ -94,700 +82,135 @@ 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())); - } - 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"); - } - + public ExportJavaScriptPane() { + initComponents(); } - // 其他模板 - class OtherTemplatePane extends BasicPane { - - private UITableEditorPane editorPane; + private void initComponents() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + this.setBorder(BorderFactory.createTitledBorder(new ModLineBorder(ModLineBorder.TOP), Toolkit.i18nText("Fine-Design_Basic_Export_JS_Setting"))); - public OtherTemplatePane() { - this.setLayout(FRGUIPaneFactory.createBorderLayout()); - this.setBorder(UITitledBorder.createBorderWithTitle(Toolkit.i18nText("Fine-Design_Basic_Export_JS_Template_Other"))); + //导出模板+导出方式+导出文件名 + JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - editorPane = new UITableEditorPane<>(new ExportJSTableModel()); - editorPane.setHeaderResizing(false); + //导出模板 + JPanel chooseTemplatePane = initChooseTemplatePane(); + northPane.add(chooseTemplatePane, BorderLayout.NORTH); - this.add(editorPane, BorderLayout.CENTER); - } + //导出方式 + JPanel exportTypePane = initExportTypePane(); + northPane.add(exportTypePane, BorderLayout.CENTER); - public void reset() { - editorPane.populate(new SingleJavaScript[0]); - } - public void updateExportJavaScript(ExportJavaScript exportJavaScript){ - List javaScripts = editorPane.update(); - for (SingleJavaScript js : javaScripts) { - exportJavaScript.addOtherTemplateJS(js); - } - } + //导出文件名 + JPanel fileNamePane = initFileNamePane(); + northPane.add(fileNamePane, BorderLayout.SOUTH); - @Override - protected String title4PopupWindow() { - return Toolkit.i18nText("Fine-Design_Basic_Export_JS_Setting"); - } + //参数 + JPanel centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + JPanel paramsPane = initParamsPane(); + centerPane.add(paramsPane); + this.add(northPane, BorderLayout.NORTH); + this.add(centerPane, BorderLayout.CENTER); } - 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); - } - }); - 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 = 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) { - + 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; } - - @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(); + 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; } - }); - } - - @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(); + tempSet.add(list.get(i).toString()); } - return ExportJavaScript.EXPORT_PDF; - } - } - - // 命名方式下拉框 - 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 Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { - fileNameComboBox.setSelectedItem(getList().get(row).isDefaultFileName() ? DEFAULT : CUSTOM); - return fileNameComboBox; } - + }); + extendParametersCheckBox.addItemListener(new ItemListener() { @Override - 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(); - } - }); + public void itemStateChanged(ItemEvent e) { + parameterViewPane.setVisible(e.getStateChange() == ItemEvent.DESELECTED); } + }); + 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 Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { - if (value != null) { - fileNameFormulaEditor.setValue(BaseFormula.createFormulaBuilder().build(value)); + public void actionPerformed(ActionEvent e) { + if (defaultNameRadio.isSelected()) { + fileNameFormulaEditor.setEnabled(false); } else { - fileNameFormulaEditor.setValue(BaseFormula.createFormulaBuilder().build()); + fileNameFormulaEditor.setEnabled(true); } - 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; + } - @Override - public Object getCellEditorValue() { - return parameterSetting.getSelectedItem().toString(); - } + 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]); } - - // 参数设置按钮 - 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 getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { - if (getList().get(row) == null || getList().get(row).isExtendParameters()) { - return EMPTY_LABEL; - } - ParameterProvider[] providers = (ParameterProvider[]) value; - if (providers != null) { - paraSettingPane.refresh(new ArrayList<>(Arrays.asList(providers))); - } - return paraButton; - } - - @Override - public Object getCellEditorValue() { - return paraSettingPane.getParameterList(); - } + this.exportTypeComboBox.setRenderer(new UIComboBoxRenderer() { @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; + 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)); } - 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); + return this; } + }); + Component[][] components = new Component[][]{{typeLabel, exportTypeComboBox}}; - } - - } - - 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); + JPanel exportTypePane = TableLayoutHelper.createTableLayoutPane(components, new double[]{p}, new double[]{p, p}); + exportTypePane.setBorder(BorderFactory.createEmptyBorder(5,2,5,2)); + return exportTypePane; } private JPanel initChooseTemplatePane() { @@ -797,28 +220,51 @@ public class ExportJavaScriptPane extends AbstractHyperLinkPane parameterList = this.parameterViewPane.update(); + parameterList.clear(); + ParameterProvider[] parameters = ob.getParameters(); + this.parameterViewPane.populate(parameters); + } } @Override @@ -845,59 +309,32 @@ public class ExportJavaScriptPane extends AbstractHyperLinkPane parameterList = this.parameterViewPane.update(); + if (!parameterList.isEmpty()) { + Parameter[] parameters = new Parameter[parameterList.size()]; + parameterList.toArray(parameters); + exportJavaScript.setParameters(parameters); + } + } } - private String getFileName() { - return currentTemplatePane.defaultNameRadio.isSelected() ? DEFAULT : currentTemplatePane.fileNameFormulaEditor.getUITextField().getText(); + private String getTemplatePath() { + return currentTemplateRadio.isSelected() ? CURRENT_TEMPLATE : reportPathTextField.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 String getFileName() { + return defaultNameRadio.isSelected() ? DEFAULT_FILENAME : fileNameFormulaEditor.getUITextField().getText(); } - 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) {