diff --git a/designer-form/src/main/java/com/fr/design/actions/FormECParallelCalAction.java b/designer-form/src/main/java/com/fr/design/actions/FormECParallelCalAction.java new file mode 100644 index 0000000000..48f8cc2c67 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/actions/FormECParallelCalAction.java @@ -0,0 +1,81 @@ +package com.fr.design.actions; + +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.dialog.UIDialog; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.JForm; +import com.fr.design.menu.MenuKeySet; +import com.fr.design.widget.ui.designer.FormECParallelCalSettingPane; +import com.fr.form.main.Form; +import com.fr.form.main.parallel.FormECParallelCalAttr; + +import javax.swing.KeyStroke; +import java.awt.Dimension; +import java.awt.event.ActionEvent; + +/** + * @author fly.li + * @version 10.0 + * Created on 2022/03/18 + */ +public class FormECParallelCalAction extends JTemplateAction { + + private static final MenuKeySet FORM_PARALLEL_SETTING = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'P'; + } + + @Override + public String getMenuName() { + return Toolkit.i18nText("Fine-Designer_Parallel_Setting"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; + + + private void initMenuStyle() { + this.setMenuKeySet(FORM_PARALLEL_SETTING); + this.setName(getMenuKeySet().getMenuKeySetName() + "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon("com/fr/design/form/images/parallel.png"); + } + + public FormECParallelCalAction(JForm jForm) { + super(jForm); + initMenuStyle(); + } + + @Override + public void actionPerformed(ActionEvent e) { + final JForm jf = getEditingComponent(); + if (jf == null) { + return; + } + showParallelSettingDialog(jf); + } + + private void showParallelSettingDialog(JForm jf) { + FormECParallelCalSettingPane attrPane = new FormECParallelCalSettingPane(); + Form form = jf.getTarget(); + FormECParallelCalAttr parallelAttr = form.getParallelAttr(); + attrPane.populateBean(parallelAttr); + UIDialog dialog = attrPane.showWindowWithCustomSize(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { + @Override + public void doOk() { + fireEditingOk(jf, form, attrPane.updateBean()); + } + }, new Dimension(600, 600)); + dialog.setVisible(true); + } + + private void fireEditingOk(JForm jForm, Form form, FormECParallelCalAttr parallelAttr){ + form.setParallelAttr(parallelAttr); + jForm.fireTargetModified(); + } +} diff --git a/designer-form/src/main/java/com/fr/design/mainframe/JForm.java b/designer-form/src/main/java/com/fr/design/mainframe/JForm.java index 449aa51906..493a7fa74a 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/JForm.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/JForm.java @@ -15,6 +15,7 @@ import com.fr.design.DesignModelAdapter; import com.fr.design.DesignState; import com.fr.design.DesignerEnvManager; import com.fr.design.actions.FormMobileAttrAction; +import com.fr.design.actions.FormECParallelCalAction; import com.fr.design.actions.TemplateParameterAction; import com.fr.design.actions.core.WorkBookSupportable; import com.fr.design.actions.file.export.EmbeddedFormExportExportAction; @@ -588,9 +589,9 @@ public class JForm extends JTemplate implements BaseJForm { + private static final String[] CHOOSE_ITEM = new String[] { + Toolkit.i18nText("Fine-Design_Report_I_Want_To_Set_Single"), + Toolkit.i18nText("Fine-Design_Form_Using_Server_Report_View_Settings") + }; + protected static final int SINGLE_SET = 0; + protected static final int SERVER_SET = 1; + //并行设置范围的下拉框(服务器设置还是模板设置) + UIComboBox parallelSettingScope; + //并行计算开关 + UICheckBox parallelSwitch; + + public FormECParallelCalSettingPane(){ + initPane(); + } + + private void initPane(){ + JPanel calSettingOutPane = FRGUIPaneFactory.createTitledBorderPane(Toolkit.i18nText("Fine-Designer_Form_Block_Parallel_Calculate")); + calSettingOutPane.setPreferredSize(new Dimension(550,110)); + calSettingOutPane.add(getCalSettingPane()); + this.add(calSettingOutPane); + } + + private JPanel getCalSettingPane() { + JPanel calSettingPane = new JPanel(); + calSettingPane.setLayout(new BorderLayout()); + UILabel belowSetLabel = new UILabel(Toolkit.i18nText("Fine-Designer_Setting_Mode")); + belowSetLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 20)); + JPanel parallelSettingScopePane = GUICoreUtils.createFlowPane(new Component[] { + belowSetLabel, getParallelSettingScope()}, FlowLayout.LEFT, 0, 0); + calSettingPane.add(parallelSettingScopePane, BorderLayout.NORTH); + calSettingPane.add(getSwitchPane(Toolkit.i18nText("Fine-Designer_Enable_Form_Block_Parallel_Calculate")), BorderLayout.CENTER); + return calSettingPane; + } + + @Override + protected String title4PopupWindow() { + return Toolkit.i18nText("Fine-Designer_Form_Block_Parallel_Calculate"); + } + + private UIComboBox getParallelSettingScope() { + if (this.parallelSettingScope == null){ + parallelSettingScope = new UIComboBox(CHOOSE_ITEM); + parallelSettingScope.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + if (e.getStateChange() == ItemEvent.SELECTED) { + if (isUsingServerSettings()) { + populateServerSettings(); + parallelSwitch.setEnabled(false); + } else { + parallelSwitch.setEnabled(true); + } + } + } + }); + } + return this.parallelSettingScope; + } + + private JPanel getSwitchPane(String tip){ + JPanel innerPane = new JPanel(); + innerPane.setLayout(new BorderLayout()); + innerPane.setPreferredSize(new Dimension(500, 30)); + innerPane.setBorder(BorderFactory.createEmptyBorder(10, 70, 5, 10)); + innerPane.add(getParallelSwitch(tip)); + return innerPane; + } + + private UICheckBox getParallelSwitch(String tip){ + if (parallelSwitch == null){ + parallelSwitch = new UICheckBox(tip); + } + return parallelSwitch; + } + + private boolean isUsingServerSettings(){ + return parallelSettingScope.getSelectedIndex() == SERVER_SET; + } + + @Override + public void populateBean(FormECParallelCalAttr formParallelAttr){ + if (formParallelAttr == null){ + formParallelAttr = FormECParallelCalAttr.getDefaultParallelAttr(); + } + parallelSettingScope.setSelectedIndex(formParallelAttr.isUseServerSetting() ? SERVER_SET : SINGLE_SET); + if (formParallelAttr.isUseServerSetting()){ + populateServerSettings(); + } else { + populateSingleTemplateSetting(formParallelAttr); + } + } + + private void populateServerSettings(){ + parallelSwitch.setSelected(FormParallelCalConfig.getInstance().isParallelCal()); + } + + private void populateSingleTemplateSetting(FormECParallelCalAttr parallelAttr){ + parallelSwitch.setSelected(parallelAttr.isParallelCal()); + } + + public FormECParallelCalAttr updateBean(){ + return new FormECParallelCalAttr(isUsingServerSettings(), parallelSwitch.isSelected()); + } +} diff --git a/designer-form/src/main/resources/com/fr/design/form/images/parallel.png b/designer-form/src/main/resources/com/fr/design/form/images/parallel.png new file mode 100644 index 0000000000..2eff0f4ee7 Binary files /dev/null and b/designer-form/src/main/resources/com/fr/design/form/images/parallel.png differ