3 changed files with 322 additions and 2 deletions
@ -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<JForm> { |
||||||
|
|
||||||
|
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(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,232 @@ |
|||||||
|
package com.fr.design.widget.ui.designer; |
||||||
|
|
||||||
|
import com.fr.design.beans.BasicBeanPane; |
||||||
|
import com.fr.design.dialog.BasicPane; |
||||||
|
import com.fr.design.gui.icombobox.UIComboBox; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.mainframe.JForm; |
||||||
|
import com.fr.design.utils.gui.GUICoreUtils; |
||||||
|
import com.fr.form.main.parallel.FormParallelAttr; |
||||||
|
import com.fr.form.main.parallel.ParallelAttrMark; |
||||||
|
import com.fr.general.IOUtils; |
||||||
|
import com.fr.report.core.config.FormParallelCalConfig; |
||||||
|
|
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.Icon; |
||||||
|
import javax.swing.JLabel; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.FlowLayout; |
||||||
|
import java.awt.Font; |
||||||
|
import java.awt.event.ItemEvent; |
||||||
|
import java.awt.event.ItemListener; |
||||||
|
import java.awt.event.MouseAdapter; |
||||||
|
import java.awt.event.MouseEvent; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author fly.li |
||||||
|
* @version 10.0 |
||||||
|
* Created on 2022/03/18 |
||||||
|
*/ |
||||||
|
public class FormParallelSettingPane extends BasicBeanPane<FormParallelAttr> { |
||||||
|
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; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue