From dfcb34be713768944c8f934d96fecd6f7bd5f0ae Mon Sep 17 00:00:00 2001 From: "fly.li" Date: Fri, 25 Mar 2022 17:01:51 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-10650:=E6=A8=A1=E6=9D=BF=E5=B9=B6?= =?UTF-8?q?=E8=A1=8C=E5=BC=80=E5=85=B3=E9=9D=A2=E6=9D=BF=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/actions/FormParallelAction.java | 87 +++++++ .../java/com/fr/design/mainframe/JForm.java | 5 +- .../ui/designer/FormParallelSettingPane.java | 232 ++++++++++++++++++ 3 files changed, 322 insertions(+), 2 deletions(-) create mode 100644 designer-form/src/main/java/com/fr/design/actions/FormParallelAction.java create mode 100644 designer-form/src/main/java/com/fr/design/widget/ui/designer/FormParallelSettingPane.java diff --git a/designer-form/src/main/java/com/fr/design/actions/FormParallelAction.java b/designer-form/src/main/java/com/fr/design/actions/FormParallelAction.java new file mode 100644 index 000000000..9011a5d15 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/actions/FormParallelAction.java @@ -0,0 +1,87 @@ +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.FormParallelSettingPane; +import com.fr.form.main.Form; +import com.fr.form.main.parallel.FormParallelAttr; + +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 FormParallelAction extends JTemplateAction { + + private static final MenuKeySet FORM_PARALLEL_SETTING = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'P'; + } + + @Override + public String getMenuName() { + //todo 国际化 + return Toolkit.i18nText("Fine-Designer_PC_Fit_Attr"); + } + + @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 FormParallelAction(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) { + FormParallelSettingPane attrPane = new FormParallelSettingPane(); + Form form = jf.getTarget(); + FormParallelAttr parallelAttr = form.getParallelAttr(); + //兼容之前的frm文件,在获取不到属性时 + if (parallelAttr == null){ + parallelAttr = FormParallelAttr.getDefaultParallelAttr(); + } + attrPane.populateBean(parallelAttr); + //注意这里的pane大小 + 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, FormParallelAttr 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 449aa5190..0848244db 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.FormParallelAction; 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 AbstractParallelSettingPane calculatePane; + private AbstractParallelSettingPane fetchDataPane; + public FormParallelSettingPane(){ + initPane(); + } + + private void initPane(){ + JPanel calSettingPane = FRGUIPaneFactory.createTitledBorderPane("报表块并行计算设置"); + calSettingPane.add(getCalculateSettingPane()); + calSettingPane.setPreferredSize(new Dimension(550,110)); + this.add(calSettingPane); + JPanel fetchDataSettingPane = FRGUIPaneFactory.createTitledBorderPane("并行取数设置"); + fetchDataSettingPane.add(getFetchDataSettingPane()); + fetchDataSettingPane.setPreferredSize(new Dimension(550, 110)); + this.add(fetchDataSettingPane); + JPanel tip = new JPanel(); + tip.setLayout(new BorderLayout()); + tip.add(new JLabel("注意:在多报表块共用一个数据集并且开启报表块并行计算时,建议同时开启并行取数"), BorderLayout.WEST); + tip.setPreferredSize(new Dimension(500, 20)); + this.add(tip); + } + + private AbstractParallelSettingPane getCalculateSettingPane(){ + if (calculatePane == null){ + this.calculatePane = new AbstractParallelSettingPane("开启报表块并行计算") { + @Override + protected void populateServerSettings() { + //这里获取全局设置并刷新数据到面板 + parallelSwitchLabel.setSwitchState(FormParallelCalConfig.getInstance().isParallelCal()); + } + }; + } + return calculatePane; + } + + private AbstractParallelSettingPane getFetchDataSettingPane(){ + if (fetchDataPane == null){ + this.fetchDataPane = new AbstractParallelSettingPane("开启并行取数") { + @Override + protected void populateServerSettings() { + parallelSwitchLabel.setSwitchState(FormParallelCalConfig.getInstance().isParallelFetchData()); + } + }; + } + return fetchDataPane; + } + + @Override + public void populateBean(FormParallelAttr ob) { + getCalculateSettingPane().populateBean(ob.getParallelCalculateMark()); + getFetchDataSettingPane().populateBean(ob.getParallelFetchDataMark()); + } + + @Override + public FormParallelAttr updateBean() { + FormParallelAttr formParallelAttr = new FormParallelAttr(); + formParallelAttr.setParallelCalculateMark(calculatePane.updateBean()); + formParallelAttr.setParallelFetchDataMark(fetchDataPane.updateBean()); + return formParallelAttr; + } + + @Override + protected String title4PopupWindow() { + return "Form并行设置"; + } + + abstract static class AbstractParallelSettingPane extends BasicPane { + private static final String[] CHOOSEITEM = new String[] { + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_I_Want_To_Set_Single"), + com.fr.design.i18n.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 combox; + //并行计算开关 + ParallelSwitchLabel parallelSwitchLabel; + + public AbstractParallelSettingPane(String tip){ + this.setLayout(new BorderLayout()); + JPanel comboxPane = new JPanel(); + UILabel belowSetLabel = new UILabel("设置方式"); + belowSetLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 20)); + JPanel buttonPane = GUICoreUtils.createFlowPane(new Component[] { + belowSetLabel, getCombox()}, FlowLayout.LEFT, 0, 0); + comboxPane.setLayout(new BorderLayout()); + comboxPane.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10)); + this.add(buttonPane, BorderLayout.NORTH); + this.add(getContentPane(tip), BorderLayout.CENTER); + } + + protected JPanel getContentPane(String tip) { + return getSwitchPane(tip); + } + + public UIComboBox getCombox() { + if (combox == null){ + combox = new UIComboBox(CHOOSEITEM); + combox.setFont(new Font(null, 0, 11)); + combox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + if (e.getStateChange() == ItemEvent.SELECTED) { + if (combox.getSelectedIndex() == SERVER_SET) { + populateServerSettings(); + } + } + } + }); + } + return combox; + } + + /** + * 从服务器拿数据 + * */ + protected abstract void populateServerSettings(); + + private JPanel getSwitchPane(String tip){ + JPanel innerPane = new JPanel(); + innerPane.setLayout(new BorderLayout()); + innerPane.setPreferredSize(new Dimension(500, 30)); + innerPane.setBorder(BorderFactory.createEmptyBorder(5, 70, 5, 10)); + + JLabel label = new JLabel(tip); + label.setFont(new Font(null, 0, 12)); + innerPane.add(label, BorderLayout.WEST); + innerPane.add(getSwitchLabel(), BorderLayout.EAST); + return innerPane; + } + + private JLabel getSwitchLabel(){ + if (parallelSwitchLabel == null){ + parallelSwitchLabel = new ParallelSwitchLabel(); + parallelSwitchLabel.setSwitchState(false); + parallelSwitchLabel.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (!isUsingServerSettings()){ + parallelSwitchLabel.changeSwitchState(); + } + } + }); + } + return parallelSwitchLabel; + } + + public void populateBean(ParallelAttrMark parallelAttrMark){ + combox.setSelectedIndex(parallelAttrMark.isUseServerSetting() ? 1 : 0); + //只有在单模板设置时才需要在这里设置开关状态,服务器设置在setSelectedIndex的时候自动获取了服务器设置 + if (!parallelAttrMark.isUseServerSetting()){ + parallelSwitchLabel.setSwitchState(parallelAttrMark.isEnableParallel()); + } + } + + private boolean isUsingServerSettings(){ + return combox.getSelectedIndex() == SERVER_SET; + } + + public ParallelAttrMark updateBean(){ + return new ParallelAttrMark(isUsingServerSettings(), parallelSwitchLabel.isParallel()); + } + + @Override + protected String title4PopupWindow() { + return ""; + } + } + + /** + * 一个并行开关Label + * */ + private static class ParallelSwitchLabel extends JLabel{ + boolean parallel; + private final static Icon openIcon = IOUtils.readIcon("com/fr/design/form/images/open.png"); + private final static Icon closeIcon = IOUtils.readIcon("com/fr/design/form/images/close.png"); + //设置计算状态,parallel状态和图标一起变化 + public void setSwitchState(boolean parallel){ + this.parallel = parallel; + if (parallel){ + this.setIcon(openIcon); + }else { + this.setIcon(closeIcon); + } + } + + public void changeSwitchState(){ + parallel = !parallel; + setSwitchState(parallel); + } + + public boolean isParallel() { + return parallel; + } + } + +}