From 10c57fd26110941cb503c2f822ca4943796d618d Mon Sep 17 00:00:00 2001 From: richie Date: Tue, 24 Sep 2019 13:59:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=B3=E7=AD=96=E6=8A=A5=E8=A1=A8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 6 + build.xml | 114 +++++++++++ lib/report/.gitkeep | 0 plugin.xml | 41 ++++ pom.xml | 38 ++++ .../reportRefresh/RefreshAttrState.java | 60 ++++++ .../reportRefresh/ReportExtraRefreshAttr.java | 140 ++++++++++++++ .../propertypane/AccessibleRefreshEditor.java | 36 ++++ .../propertypane/RefreshAttrPane.java | 180 ++++++++++++++++++ .../designer/propertypane/RefreshEditor.java | 15 ++ .../propertypane/RefreshPropertyEditor.java | 60 ++++++ .../propertypane/RefreshRadioGroup.java | 75 ++++++++ .../designer/propertypane/RefreshRender.java | 10 + .../designer/propertypane/RefreshWrapper.java | 15 ++ .../locale/RefreshLocaleFinder.java | 18 ++ .../web/CachedExpressionControl.java | 116 +++++++++++ .../web/CheckRefreshAreaAction.java | 125 ++++++++++++ .../web/FormGetRefreshConfigAction.java | 62 ++++++ .../reportRefresh/web/JavaScriptFile.java | 16 ++ .../reportRefresh/web/RefreshFormService.java | 32 ++++ .../reportRefresh/locale/refresh.properties | 15 ++ .../locale/refresh_en_US.properties | 15 ++ .../locale/refresh_zh_CN.properties | 15 ++ .../locale/refresh_zh_TW.properties | 15 ++ .../fr/plugin/reportRefresh/web/refresh.js | 130 +++++++++++++ 25 files changed, 1349 insertions(+) create mode 100644 .gitignore create mode 100644 build.xml create mode 100644 lib/report/.gitkeep create mode 100644 plugin.xml create mode 100644 pom.xml create mode 100644 src/main/java/com/fr/plugin/reportRefresh/RefreshAttrState.java create mode 100644 src/main/java/com/fr/plugin/reportRefresh/ReportExtraRefreshAttr.java create mode 100644 src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/AccessibleRefreshEditor.java create mode 100644 src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshAttrPane.java create mode 100644 src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshEditor.java create mode 100644 src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshPropertyEditor.java create mode 100644 src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshRadioGroup.java create mode 100644 src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshRender.java create mode 100644 src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshWrapper.java create mode 100644 src/main/java/com/fr/plugin/reportRefresh/locale/RefreshLocaleFinder.java create mode 100644 src/main/java/com/fr/plugin/reportRefresh/web/CachedExpressionControl.java create mode 100644 src/main/java/com/fr/plugin/reportRefresh/web/CheckRefreshAreaAction.java create mode 100644 src/main/java/com/fr/plugin/reportRefresh/web/FormGetRefreshConfigAction.java create mode 100644 src/main/java/com/fr/plugin/reportRefresh/web/JavaScriptFile.java create mode 100644 src/main/java/com/fr/plugin/reportRefresh/web/RefreshFormService.java create mode 100644 src/main/resources/com/fr/plugin/reportRefresh/locale/refresh.properties create mode 100644 src/main/resources/com/fr/plugin/reportRefresh/locale/refresh_en_US.properties create mode 100644 src/main/resources/com/fr/plugin/reportRefresh/locale/refresh_zh_CN.properties create mode 100644 src/main/resources/com/fr/plugin/reportRefresh/locale/refresh_zh_TW.properties create mode 100644 src/main/resources/com/fr/plugin/reportRefresh/web/refresh.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ca1fd18 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.iml +.idea/ +target/ +lib/report/*.jar +.DS_Store +.classpath \ No newline at end of file diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..465924f --- /dev/null +++ b/build.xml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/report/.gitkeep b/lib/report/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..a959974 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,41 @@ + + com.fr.plugin.reportRefresh.v10 + + yes + no + 1.5 + 10.0~ + 2018-07-31 + finereport + + [2019-05-22]修复sessionidtimeout问题

+

[2019-04-19]修复tab块中报表块不刷新问题

+

[2019-03-22]修复与组件加载动画插件冲突的问题

+

[2019-02-18]修复区域监控一段时间后无法刷新问题

+

[2018-12-26]修复复杂表单下卡顿问题

+

[2018-11-06]增加对组件动画的支持

+

[2018-07-31]插件升级以支持10

+

[2018-7-17]修复安装性能插件后无法自动刷新的问题

+

[2017-10-27]支持自定义类刷新, 精简获取刷新配置的json

+

[2017-7-12]适配9.0热部署

+

[2017-05-24]加入联动刷新, 修改jartime

+

[2017-05-22]加入单报表块刷新功能, 隐藏刷新动画

+

[2017-05-17]加入监控区域刷新功能

+

[2017-02-10]区分表单和报表参数面板,非表单不刷新

+

[2017-02-07]前端新加接口,表单初始化时增加afterload事件

+

[2016-11-16]可以通过设置不同报表块的刷新频率

+ ]]>
+ + + + + + + + + + + + +
diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..00d7a4e --- /dev/null +++ b/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + + com.fr.plugin + starter + 10.0 + + + jar + demo-form-property + + + com.fanruan.api + finekit + 10.0 + system + ${project.basedir}/lib/finekit-10.0.jar + + + + + ${project.basedir}/../webroot/WEB-INF/plugins/plugin-com.fr.plugin.export.xml-1.0/classes + + + org.apache.maven.plugins + maven-compiler-plugin + + 6 + 6 + + + + + \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/reportRefresh/RefreshAttrState.java b/src/main/java/com/fr/plugin/reportRefresh/RefreshAttrState.java new file mode 100644 index 0000000..239b270 --- /dev/null +++ b/src/main/java/com/fr/plugin/reportRefresh/RefreshAttrState.java @@ -0,0 +1,60 @@ +package com.fr.plugin.reportRefresh; + +import com.fr.design.designer.properties.items.Item; +import com.fr.locale.InterProviderFactory; +import com.fr.stable.StringUtils; + +/** + * Created by Administrator on 2016/4/13/0013. + */ +public enum RefreshAttrState { + NO_REFRESH(0) { + @Override + public String description() { + return InterProviderFactory.getProvider().getLocText("FR-Plugin_Refresh-No-Refresh"); + } + + }, + TIMER_REFRESH(1) { + @Override + public String description() { + return InterProviderFactory.getProvider().getLocText("FR-Plugin_Refresh-Interval-Refresh"); + } + }, + MONITOR_REFRESH(2) { + @Override + public String description() { + return InterProviderFactory.getProvider().getLocText("FR-Plugin_Monitor-Refresh"); + } + }; + + private int state; + + + private RefreshAttrState(int state) { + this.state = state; + } + + public int getState() { + return this.state; + } + + public String description() { + return StringUtils.EMPTY; + } + + public static RefreshAttrState parse(int state) { + for (RefreshAttrState attrState : values()) { + if (attrState.state == state) { + return attrState; + } + } + + return NO_REFRESH; + } + + public Item propertyItem() { + return new Item(this.description(), this.getState()); + } + +} diff --git a/src/main/java/com/fr/plugin/reportRefresh/ReportExtraRefreshAttr.java b/src/main/java/com/fr/plugin/reportRefresh/ReportExtraRefreshAttr.java new file mode 100644 index 0000000..4af7864 --- /dev/null +++ b/src/main/java/com/fr/plugin/reportRefresh/ReportExtraRefreshAttr.java @@ -0,0 +1,140 @@ +package com.fr.plugin.reportRefresh; + +import com.fr.form.stable.RefreshAttrProvider; +import com.fr.general.ComparatorUtils; +import com.fr.intelli.record.Focus; +import com.fr.intelli.record.Original; +import com.fr.json.JSONException; +import com.fr.json.JSONObject; +import com.fr.record.analyzer.EnableMetrics; +import com.fr.stable.StringUtils; +import com.fr.stable.fun.impl.AbstractIOFileAttrMark; +import com.fr.stable.xml.XMLPrintWriter; +import com.fr.stable.xml.XMLableReader; + +/** + * Created by Slpire on 2016/10/21. + */ +@EnableMetrics +public class ReportExtraRefreshAttr extends AbstractIOFileAttrMark implements RefreshAttrProvider { + + private RefreshAttrState attrState = RefreshAttrState.NO_REFRESH; + // 刷新间隔, 0表示不刷新 + private double interval = 0; + // 刷新区域, 空表示不刷新. + private String refreshArea; + // 自定义类刷新 + private boolean customClass = false; + + private static final String PLUGIN_ID = "com.fr.plugin.reportRefresh"; + + + public ReportExtraRefreshAttr() { + } + + public ReportExtraRefreshAttr(RefreshAttrState attrState) { + this.attrState = attrState; + } + + public RefreshAttrState getAttrState() { + return attrState; + } + + public void setAttrState(RefreshAttrState attrState) { + this.attrState = attrState; + } + + public double getInterval() { + return interval; + } + + public void setInterval(double interval) { + this.interval = interval; + } + + public String getRefreshArea() { + return refreshArea; + } + + public void setRefreshArea(String refreshArea) { + this.refreshArea = refreshArea; + } + + public boolean isCustomClass() { + return customClass; + } + + public void setCustomClass(boolean customClass) { + this.customClass = customClass; + } + + @Override + public String xmlTag() { + return RefreshAttrProvider.XML_TAG; + } + + @Override + public ReportExtraRefreshAttr clone() { + ReportExtraRefreshAttr cloned = (ReportExtraRefreshAttr) super.clone(); + this.setAttrState(cloned.attrState); + this.setInterval(cloned.interval); + this.setRefreshArea(cloned.refreshArea); + this.setCustomClass(cloned.customClass); + return cloned; + } + + @Override + @Focus(id = PLUGIN_ID, source = Original.PLUGIN, text = "FR-Plugin_Refresh-Plugin") + public void readXML(XMLableReader reader) { + if (reader.isChildNode()) { + String tagName = reader.getTagName(); + if (this.xmlTag().equals(tagName)) { + // 兼容老的逻辑与xml + if (reader.getAttrAsBoolean("IsExtraAttr", false)) { + this.setAttrState(RefreshAttrState.TIMER_REFRESH); + this.setInterval(reader.getAttrAsDouble("reportRefreshInPC", 0)); + } else { + int state = reader.getAttrAsInt("state", 0); + this.setAttrState(RefreshAttrState.parse(state)); + this.setInterval(reader.getAttrAsDouble("interval", 0)); + this.setRefreshArea(reader.getAttrAsString("refreshArea", StringUtils.EMPTY)); + this.setCustomClass(reader.getAttrAsBoolean("customClass", false)); + } + } + } + } + + @Override + public boolean equals(Object obj) { + return obj instanceof ReportExtraRefreshAttr && super.equals(obj) + && ComparatorUtils.equals(attrState, ((ReportExtraRefreshAttr) obj).attrState) + && ComparatorUtils.equals(interval, ((ReportExtraRefreshAttr) obj).interval) + && ComparatorUtils.equals(refreshArea, ((ReportExtraRefreshAttr) obj).refreshArea); + } + + @Override + public String toString() { + return attrState.description(); + } + + @Override + public void writeXML(XMLPrintWriter writer) { + writer.startTAG(this.xmlTag()) + .attr("state", attrState.getState()) + .attr("interval", this.getInterval()) + .attr("refreshArea", this.getRefreshArea()) + .attr("customClass", this.isCustomClass()) + .end(); + } + + @Override + public JSONObject createJSONConfig() throws JSONException { + JSONObject jo = JSONObject.create(); + jo.put("state", attrState.getState()); + jo.put("interval", this.getInterval()); + jo.put("refreshArea", this.getRefreshArea()); + jo.put("customClass", this.isCustomClass()); + return jo; + } + +} diff --git a/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/AccessibleRefreshEditor.java b/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/AccessibleRefreshEditor.java new file mode 100644 index 0000000..72c3293 --- /dev/null +++ b/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/AccessibleRefreshEditor.java @@ -0,0 +1,36 @@ +package com.fr.plugin.reportRefresh.designer.propertypane; + +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.mainframe.widget.accessibles.UneditableAccessibleEditor; +import com.fr.plugin.reportRefresh.ReportExtraRefreshAttr; + +import javax.swing.SwingUtilities; + +public class AccessibleRefreshEditor extends UneditableAccessibleEditor { + + private RefreshAttrPane refreshAttrPane; + + public AccessibleRefreshEditor() { + super(new RefreshWrapper()); + } + + @Override + protected void showEditorPane() { + if (refreshAttrPane == null) { + refreshAttrPane = new RefreshAttrPane(); + } + + BasicDialog dlg = refreshAttrPane.showSmallWindow(SwingUtilities.getWindowAncestor(this), new DialogActionAdapter() { + + @Override + public void doOk() { + ReportExtraRefreshAttr refreshAttr = refreshAttrPane.updateBean(); + setValue(refreshAttr); + fireStateChanged(); + } + }); + refreshAttrPane.populateBean((ReportExtraRefreshAttr) getValue()); + dlg.setVisible(true); + } +} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshAttrPane.java b/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshAttrPane.java new file mode 100644 index 0000000..2a66d3d --- /dev/null +++ b/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshAttrPane.java @@ -0,0 +1,180 @@ +package com.fr.plugin.reportRefresh.designer.propertypane; + +import com.fr.base.BaseUtils; +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ibutton.UIRadioButton; +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.ispinner.UISpinner; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.general.Inter; +import com.fr.plugin.reportRefresh.RefreshAttrState; +import com.fr.plugin.reportRefresh.ReportExtraRefreshAttr; +import com.fr.stable.StringUtils; + +import javax.swing.JPanel; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +/** + * Created by Administrator on 2017/5/8/0008. + */ +public class RefreshAttrPane extends BasicBeanPane { + + private UIRadioButton noRefreshRadio; + private UIRadioButton intervalRadio; + private UIRadioButton monitorRadio; + private UISpinner intervalSpinner; + private UITextField areaTextField; + private RefreshRadioGroup radioGroup; + private UICheckBox customRefresh; + private UILabel areaLabel; + private UILabel tipLabel; + private UIButton tipButton; + private JPanel typePane; + private JPanel intervalPane; + private JPanel areaPane; + + public RefreshAttrPane() { + initComponents(); + } + + private void initComponents() { + double p = TableLayout.PREFERRED; + double[] rowSize = {p}; + + // 刷新类型 + typePane = TableLayoutHelper.createTableLayoutPane(initTypeComponents(), rowSize, new double[]{p, p, p, p}); + // 刷新间隔 + intervalPane = TableLayoutHelper.createTableLayoutPane(initIntervalComponents(), rowSize, new double[]{p, p, p, p, p, p}); + // 刷新区域 + areaPane = TableLayoutHelper.createTableLayoutPane(initAreaComponents(), rowSize, new double[]{p, p, p}); + + JPanel contentPane = TableLayoutHelper.createTableLayoutPane(new Component[][]{ + new Component[]{typePane}, + new Component[]{intervalPane}, + new Component[]{areaPane} + }, new double[]{p, p, p}, new double[]{p}); + + intervalPane.setVisible(false); + areaPane.setVisible(false); + + this.add(contentPane); + } + + private Component[][] initTypeComponents() { + noRefreshRadio = new UIRadioButton(Inter.getLocText("FR-Plugin_Refresh-No-Refresh")); + intervalRadio = new UIRadioButton(Inter.getLocText("FR-Plugin_Refresh-Interval-Refresh")); + monitorRadio = new UIRadioButton(Inter.getLocText("FR-Plugin_Monitor-Refresh")); + + radioGroup = new RefreshRadioGroup(); + radioGroup.add(noRefreshRadio); + radioGroup.add(intervalRadio); + radioGroup.add(monitorRadio); + + radioGroup.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + populateIntervalArea(); + } + }); + radioGroup.selectIndexButton(0); + + return new Component[][]{ + new Component[]{new UILabel(Inter.getLocText("FR-Plugin_Refresh-Type")), noRefreshRadio, intervalRadio, monitorRadio} + }; + } + + private void populateIntervalArea() { + boolean noRefresh = noRefreshRadio.isSelected(); + boolean interval = intervalRadio.isSelected(); + boolean monitor = monitorRadio.isSelected(); + + intervalPane.setVisible(interval || monitor); + areaPane.setVisible(monitor); + customRefresh.setVisible(monitor); + tipButton.setVisible(monitor); + if (noRefresh) { + intervalSpinner.setValue(0); + } + if (noRefresh || interval) { + areaTextField.setText(StringUtils.EMPTY); + } + } + + private Component[][] initIntervalComponents() { + intervalSpinner = new UISpinner(0, Integer.MAX_VALUE, 1, 0); + customRefresh = new UICheckBox(Inter.getLocText("FR-Plugin_Refresh-Class")); + initTipButton(); + Component[][] components = new Component[][]{ + new Component[]{new UILabel(Inter.getLocText("FR-Plugin_Refresh-Interval")), intervalSpinner, + new UILabel(Inter.getLocText("FR-Plugin_Refresh-Second")), new UILabel(), customRefresh, tipButton} + }; + + customRefresh.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + populateClassLabel(); + } + }); + return components; + } + + private void initTipButton() { + tipButton = new UIButton(); + tipButton.set4ToolbarButton(); + tipButton.setIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/help.png")); + tipButton.setToolTipText(Inter.getLocText("FR-Plugin_Refresh-Tip")); + } + + private void populateClassLabel() { + if (customRefresh.isSelected()) { + areaLabel.setText(Inter.getLocText("FR-Plugin_Refresh-Label")); + tipLabel.setText(Inter.getLocText("FR-Plugin_Refresh-Example")); + } else { + areaLabel.setText(Inter.getLocText("FR-Plugin_Refresh-Area")); + tipLabel.setText(Inter.getLocText("FR-Plugin_Refresh-Sample")); + } + } + + private Component[][] initAreaComponents() { + areaTextField = new UITextField(7); + areaLabel = new UILabel(Inter.getLocText("FR-Plugin_Refresh-Area")); + tipLabel = new UILabel(Inter.getLocText("FR-Plugin_Refresh-Sample")); + return new Component[][]{ + new Component[]{areaLabel, areaTextField, tipLabel} + }; + } + + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("FR-Plugin_Refresh"); + } + + @Override + public void populateBean(ReportExtraRefreshAttr refreshAttr) { + radioGroup.selectIndexButton(refreshAttr.getAttrState().getState()); + populateIntervalArea(); + intervalSpinner.setValue(refreshAttr.getInterval()); + areaTextField.setText(refreshAttr.getRefreshArea()); + customRefresh.setSelected(refreshAttr.isCustomClass()); + populateClassLabel(); + } + + @Override + public ReportExtraRefreshAttr updateBean() { + ReportExtraRefreshAttr newAttr = new ReportExtraRefreshAttr(); + int state = radioGroup.getSelectRadioIndex(); + newAttr.setAttrState(RefreshAttrState.parse(state)); + newAttr.setInterval(intervalSpinner.getValue()); + newAttr.setRefreshArea(areaTextField.getText()); + newAttr.setCustomClass(customRefresh.isSelected()); + return newAttr; + } +} diff --git a/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshEditor.java b/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshEditor.java new file mode 100644 index 0000000..96b46a8 --- /dev/null +++ b/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshEditor.java @@ -0,0 +1,15 @@ +package com.fr.plugin.reportRefresh.designer.propertypane; + +import com.fr.design.mainframe.widget.accessibles.AccessiblePropertyEditor; + +public class RefreshEditor extends AccessiblePropertyEditor { + + public RefreshEditor() { + super(new AccessibleRefreshEditor()); + } + + @Override + public boolean refreshInTime() { + return true; + } +} diff --git a/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshPropertyEditor.java b/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshPropertyEditor.java new file mode 100644 index 0000000..ff60b34 --- /dev/null +++ b/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshPropertyEditor.java @@ -0,0 +1,60 @@ +package com.fr.plugin.reportRefresh.designer.propertypane; + +import com.fr.design.designer.beans.events.DesignerEvent; +import com.fr.design.designer.creator.CRPropertyDescriptor; +import com.fr.design.form.util.XCreatorConstants; +import com.fr.design.fun.impl.AbstractFormElementCaseEditorProvider; +import com.fr.design.mainframe.FormDesigner; +import com.fr.design.mainframe.WidgetPropertyPane; +import com.fr.form.FormProvider; +import com.fr.form.stable.RefreshAttrProvider; +import com.fr.form.ui.ElementCaseEditor; +import com.fr.form.ui.ElementCaseEditorProvider; +import com.fr.locale.InterProviderFactory; +import com.fr.plugin.reportRefresh.ReportExtraRefreshAttr; +import com.fr.stable.core.PropertyChangeAdapter; + +import java.beans.IntrospectionException; +import java.beans.PropertyDescriptor; + +/** + * Created by Slpire on 16/9/22. + */ +public class RefreshPropertyEditor extends AbstractFormElementCaseEditorProvider { + + public static String Refresh = "refresh"; + + private FormDesigner designer; + + public PropertyDescriptor[] createPropertyDescriptor(Class temp, ReportExtraRefreshAttr refreshAttrProvider) { + try { + return new CRPropertyDescriptor[]{ + new CRPropertyDescriptor("refreshAttr", temp) + .setEditorClass(RefreshEditor.class) + .setI18NName(InterProviderFactory.getProvider().getLocText("FR-Plugin_Refresh")) + .putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced") + .setPropertyChangeListener(new PropertyChangeAdapter() { + @Override + public void propertyChange() { + designer = WidgetPropertyPane.getInstance().getEditingFormDesigner(); + designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_EDITED); + } + }) + }; + } catch (IntrospectionException e) { + return new CRPropertyDescriptor[0]; + } + } + + @Override + public PropertyDescriptor[] createPropertyDescriptor(Class temp, FormProvider reportAttr, ElementCaseEditorProvider editor) { + ElementCaseEditor elementCaseEditor = (ElementCaseEditor) editor; + ReportExtraRefreshAttr refreshAttr = elementCaseEditor.getAttrMark(RefreshAttrProvider.XML_TAG); + if (refreshAttr == null) { + refreshAttr = new ReportExtraRefreshAttr(); + elementCaseEditor.addWidgetAttrMark(refreshAttr); + } + + return this.createPropertyDescriptor(editor.getClass(), refreshAttr); + } +} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshRadioGroup.java b/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshRadioGroup.java new file mode 100644 index 0000000..4ca1129 --- /dev/null +++ b/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshRadioGroup.java @@ -0,0 +1,75 @@ +package com.fr.plugin.reportRefresh.designer.propertypane; + +import com.fr.design.gui.ibutton.UIRadioButton; + +import javax.swing.AbstractButton; +import javax.swing.ButtonGroup; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.List; + +public class RefreshRadioGroup extends ButtonGroup { + + private List radioButtons = new ArrayList(); + + @Override + public void add(AbstractButton button) { + super.add(button); + + UIRadioButton radioButton = (UIRadioButton) button; + radioButtons.add(radioButton); + } + + /** + * 设置按钮状态 + */ + public void setEnabled(boolean enabled) { + for (UIRadioButton radioButton : radioButtons) { + radioButton.setEnabled(enabled); + } + } + + /** + * 设置按钮状态 + */ + public boolean isEnabled() { + return radioButtons.get(0).isEnabled(); + } + + /** + * 获取当前选中的按钮index + * + * @return 按钮index + */ + public int getSelectRadioIndex() { + for (int i = 0, len = radioButtons.size(); i < len; i++) { + if (radioButtons.get(i).isSelected()) { + return i; + } + } + + return 0; + } + + /** + * 选中指定index的按钮 + */ + public void selectIndexButton(int index) { + if (index < 0 || index > radioButtons.size() - 1) { + return; + } + + UIRadioButton button = radioButtons.get(index); + button.setSelected(true); + } + + /** + * 给所有的按钮加上监听 + */ + public void addActionListener(ActionListener actionListener) { + for (UIRadioButton radioButton : radioButtons) { + radioButton.addActionListener(actionListener); + } + } + +} diff --git a/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshRender.java b/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshRender.java new file mode 100644 index 0000000..c0151c0 --- /dev/null +++ b/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshRender.java @@ -0,0 +1,10 @@ +package com.fr.plugin.reportRefresh.designer.propertypane; + +import com.fr.design.mainframe.widget.renderer.EncoderCellRenderer; + +public class RefreshRender extends EncoderCellRenderer { + + public RefreshRender() { + super(new RefreshWrapper()); + } +} diff --git a/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshWrapper.java b/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshWrapper.java new file mode 100644 index 0000000..d5af45f --- /dev/null +++ b/src/main/java/com/fr/plugin/reportRefresh/designer/propertypane/RefreshWrapper.java @@ -0,0 +1,15 @@ +package com.fr.plugin.reportRefresh.designer.propertypane; + +import com.fr.design.designer.properties.Encoder; +import com.fr.plugin.reportRefresh.ReportExtraRefreshAttr; +import com.fr.stable.StringUtils; + +public class RefreshWrapper implements Encoder { + public RefreshWrapper() { + } + + @Override + public String encode(ReportExtraRefreshAttr source) { + return source == null ? StringUtils.EMPTY : source.toString(); + } +} diff --git a/src/main/java/com/fr/plugin/reportRefresh/locale/RefreshLocaleFinder.java b/src/main/java/com/fr/plugin/reportRefresh/locale/RefreshLocaleFinder.java new file mode 100644 index 0000000..059e42c --- /dev/null +++ b/src/main/java/com/fr/plugin/reportRefresh/locale/RefreshLocaleFinder.java @@ -0,0 +1,18 @@ +package com.fr.plugin.reportRefresh.locale; + +import com.fr.stable.fun.impl.AbstractLocaleFinder; + +/** + * Created by Slpire on 16/9/22. + */ +public class RefreshLocaleFinder extends AbstractLocaleFinder { + + /** + * 国际化文件路径 + * + * @return 路径 + */ + public String find() { + return "com/fr/plugin/reportRefresh/locale/refresh"; + } +} diff --git a/src/main/java/com/fr/plugin/reportRefresh/web/CachedExpressionControl.java b/src/main/java/com/fr/plugin/reportRefresh/web/CachedExpressionControl.java new file mode 100644 index 0000000..8c84efa --- /dev/null +++ b/src/main/java/com/fr/plugin/reportRefresh/web/CachedExpressionControl.java @@ -0,0 +1,116 @@ +package com.fr.plugin.reportRefresh.web; + +import com.fr.base.Painter; +import com.fr.general.ComparatorUtils; +import com.fr.general.FArray; +import com.fr.plugin.context.PluginContexts; +import com.fr.stable.web.ServletContext; +import com.fr.stable.web.ServletContextAdapter; +import com.fr.web.core.SessionPoolManager; +import com.fr.web.core.TemplateSessionIDInfo; +import com.fr.web.session.SessionIDInfo; + +import java.util.Iterator; +import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.ConcurrentHashMap; + +/** + * 缓存一些解析的单元格 + * 格式为 > + * { + * 123 { + * A1: aaa, + * B5:C5: farray + * }, + * 456 { + * C7: map + * } + * } + *

+ * Created by Administrator on 2017/5/11/0011. + */ +public class CachedExpressionControl { + private static CachedExpressionControl expressionControl; + private static final long RELEASE_TIMER = 5 * 60 * 1000L; + + private Map> cachedValue = new ConcurrentHashMap>(); + + private Timer timer = PluginContexts.currentContext().newTimer(); + + static { + ServletContext.addServletContextListener(new ServletContextAdapter() { + @Override + public void onServletStop() { + expressionControl.release(); + expressionControl = null; + } + }); + } + + public static CachedExpressionControl getInstance() { + if (expressionControl == null) { + expressionControl = new CachedExpressionControl(); + } + + return expressionControl; + } + + private void release() { + cachedValue.clear(); + timer.cancel(); + } + + private CachedExpressionControl() { + initReleaseTimer(); + } + + private void initReleaseTimer() { + timer.schedule(new TimerTask() { + @Override + public void run() { + try { + String[] cachedSessionIDs = cachedValue.keySet().toArray(new String[cachedValue.size()]); + for (String sessionID : cachedSessionIDs) { + SessionIDInfo info = SessionPoolManager.getSessionIDInfor(sessionID, TemplateSessionIDInfo.class); + + if (info == null || info.isTimeout()) { + cachedValue.remove(sessionID); + } + } + } catch (Throwable ignored) { + // do nth + } + + } + }, RELEASE_TIMER, RELEASE_TIMER); + } + + public boolean whetherExpressionValueChange(String sessionID, String expression, Object newVal) { + Map sessionValueMap = cachedValue.get(sessionID); + if (sessionValueMap == null) { + sessionValueMap = new ConcurrentHashMap(); + cachedValue.put(sessionID, sessionValueMap); + } + + Object oldVal = sessionValueMap.get(expression); + // 缓存新的值 + sessionValueMap.put(expression, newVal); + // 如果之前没有值, 可能是刚预览. + if (newVal instanceof Painter) { + return false; + } + + if (newVal instanceof FArray) { + Iterator iterator = ((FArray) newVal).iterator(); + while (iterator.hasNext()) { + if (iterator.next() instanceof Painter) { + return false; + } + } + } + return !ComparatorUtils.equals(newVal, oldVal); + } + +} diff --git a/src/main/java/com/fr/plugin/reportRefresh/web/CheckRefreshAreaAction.java b/src/main/java/com/fr/plugin/reportRefresh/web/CheckRefreshAreaAction.java new file mode 100644 index 0000000..70db7b7 --- /dev/null +++ b/src/main/java/com/fr/plugin/reportRefresh/web/CheckRefreshAreaAction.java @@ -0,0 +1,125 @@ +package com.fr.plugin.reportRefresh.web; + +import com.fr.base.Formula; +import com.fr.base.ParameterMapNameSpace; +import com.fr.data.NetworkHelper; +import com.fr.data.TableDataSource; +import com.fr.form.FormElementCaseProvider; +import com.fr.form.main.Form; +import com.fr.form.ui.ElementCaseEditor; +import com.fr.form.ui.Widget; +import com.fr.general.GeneralUtils; +import com.fr.log.FineLoggerFactory; +import com.fr.schedule.util.ExecuteCondition; +import com.fr.script.Calculator; +import com.fr.stable.Constants; +import com.fr.stable.StringUtils; +import com.fr.stable.web.Repository; +import com.fr.web.RepositoryDeal; +import com.fr.web.core.ActionNoSessionCMD; +import com.fr.web.core.ErrorHandlerHelper; +import com.fr.web.core.FormSessionIDInfor; +import com.fr.web.core.SessionPoolManager; +import com.fr.web.session.SessionIDInfo; +import com.fr.web.utils.WebUtils; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.PrintWriter; +import java.util.Map; + +/** + * Created by Slpire on 2016/10/29. + */ +public class CheckRefreshAreaAction extends ActionNoSessionCMD { + + private static final String CMD = "area"; + + @Override + public String getCMD() { + return CMD; + } + + @Override + public void actionCMD(HttpServletRequest req, HttpServletResponse res, String sessionID) throws Exception { + FormSessionIDInfor sessionIDInfo = SessionPoolManager.getSessionIDInfor(sessionID, FormSessionIDInfor.class); + if (sessionIDInfo == null) { + ErrorHandlerHelper.getErrorHandler().error(req, res, "SessionID: \"" + sessionID + "\" time out."); + return; + } + + String refreshArea = NetworkHelper.getHTTPRequestParameter(req, "refreshArea"); + String reportName = NetworkHelper.getHTTPRequestParameter(req, "reportName"); + boolean valueChange = true; + + if (StringUtils.isNotEmpty(refreshArea)) { + if (NetworkHelper.getHTTPRequestBoolParameter(req, "customClass")) { + valueChange = exeCustomClass(refreshArea, sessionIDInfo, reportName); + } else { + valueChange = exeCellValue(req, sessionID, sessionIDInfo, refreshArea, reportName, true); + } + } + + PrintWriter writer = WebUtils.createPrintWriter(res); + writer.write(valueChange + ""); + writer.flush(); + writer.close(); + } + + private boolean exeCellValue(HttpServletRequest req, String sessionID, FormSessionIDInfor sessionIDInfor, String refreshArea, String reportName, boolean valueChange) { + Repository repo = new RepositoryDeal(req, sessionIDInfor, Constants.DEFAULT_WEBWRITE_AND_SCREEN_RESOLUTION); + Form form = sessionIDInfor.getForm2Show(); + sessionIDInfor.applySessionIDInforParameters(req); + Map para = sessionIDInfor.updatePara(); + Calculator ca = initExpressionCalculator(sessionID, form, para); + para.putAll(form.getWidgetDefaultValueMap(para, repo)); + + sessionIDInfor.clearResultElementCase(reportName.toUpperCase()); + // 计算下指定的报表块 + executeGivenElements(sessionIDInfor, reportName, form, para); + + try { + //用于解析报表块中的格子=reportBlock1~A1这种 + String formulaContent = "=" + reportName + "~" + refreshArea; + Object newVal = ca.eval(new Formula(formulaContent)); + valueChange = CachedExpressionControl.getInstance().whetherExpressionValueChange(sessionID, formulaContent, newVal); + } catch (Throwable e) { + // 传入非法的刷新区域, 直接强制刷新. + } + return valueChange; + } + + private boolean exeCustomClass(String refreshArea, FormSessionIDInfor sessionIDInfor, String reportName) { + try { + ExecuteCondition executeClass = (ExecuteCondition) GeneralUtils.classForName(refreshArea).newInstance(); + boolean result = executeClass.execute(); + if (result) { + sessionIDInfor.clearResultElementCase(reportName.toUpperCase()); + } + FineLoggerFactory.getLogger().debug("Class Execute Result: " + result); + return result; + } catch (Throwable throwable) { + FineLoggerFactory.getLogger().debug("Class Execute Failed: " + throwable.getMessage()); + return false; + } + } + + private void executeGivenElements(FormSessionIDInfor sessionIDInfor, String reportName, Form form, Map para) { + Widget widget = form.getWidgetByName(reportName); + ElementCaseEditor table = (ElementCaseEditor) widget; + FormElementCaseProvider elementcase = table.getElementCase(); + elementcase.setName(reportName); + elementcase.setTabledataSource(form); + String[] elems = elementcase.dependenceBlocks(); + elementcase.executeGivenElements(elems, sessionIDInfor, para); + } + + private Calculator initExpressionCalculator(String sessionID, Form form, Map para) { + Calculator ca = Calculator.createCalculator(); + ca.pushNameSpace(ParameterMapNameSpace.create(para)); + ca.setAttribute(TableDataSource.KEY, form); + //用于解析报表块中的格子=reportBlock1~A1这种 + ca.pushNameSpace(SessionIDInfo.asNameSpace(sessionID)); + return ca; + } +} diff --git a/src/main/java/com/fr/plugin/reportRefresh/web/FormGetRefreshConfigAction.java b/src/main/java/com/fr/plugin/reportRefresh/web/FormGetRefreshConfigAction.java new file mode 100644 index 0000000..6ea05aa --- /dev/null +++ b/src/main/java/com/fr/plugin/reportRefresh/web/FormGetRefreshConfigAction.java @@ -0,0 +1,62 @@ +package com.fr.plugin.reportRefresh.web; + +import com.fr.form.main.Form; +import com.fr.form.stable.RefreshAttrProvider; +import com.fr.form.ui.ElementCaseEditor; +import com.fr.form.ui.ElementCaseEditorProvider; +import com.fr.json.JSONArray; +import com.fr.json.JSONObject; +import com.fr.plugin.reportRefresh.ReportExtraRefreshAttr; +import com.fr.web.core.ActionNoSessionCMD; +import com.fr.web.core.ErrorHandlerHelper; +import com.fr.web.core.FormSessionIDInfor; +import com.fr.web.core.SessionPoolManager; +import com.fr.web.utils.WebUtils; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Created by Slpire on 2016/10/29. + */ +public class FormGetRefreshConfigAction extends ActionNoSessionCMD { + + public static final String CMD = "config"; + + @Override + public String getCMD() { + return CMD; + } + + @Override + public void actionCMD(HttpServletRequest req, HttpServletResponse res, String sessionID) throws Exception { + FormSessionIDInfor sessionIDInfo; + try { + sessionIDInfo = SessionPoolManager.getSessionIDInfor(sessionID, FormSessionIDInfor.class); + } catch (Exception e) { + return; + } + if (sessionIDInfo == null) { + ErrorHandlerHelper.getErrorHandler().error(req, res, "SessionID: \"" + sessionID + "\" time out."); + return; + } + Form form = sessionIDInfo.getForm2Show(); + ElementCaseEditorProvider[] elems = form.getElementCases(); + JSONArray reports = JSONArray.create(); + for (ElementCaseEditorProvider elem : elems) { + JSONObject jo = JSONObject.create(); + String widgetName = elem.getWidgetName(); + String mark = RefreshAttrProvider.XML_TAG; + ReportExtraRefreshAttr attr = ((ElementCaseEditor) elem).getAttrMark(mark); + jo.put("widgetName", widgetName); + if (attr != null) { + jo.put(mark, attr.createJSONConfig()); + } + reports.put(jo); + } + JSONObject formJo = JSONObject.create(); + formJo.put("sessionID", sessionID); + formJo.put("reports", reports); + WebUtils.printAsJSON(res, formJo); + } +} diff --git a/src/main/java/com/fr/plugin/reportRefresh/web/JavaScriptFile.java b/src/main/java/com/fr/plugin/reportRefresh/web/JavaScriptFile.java new file mode 100644 index 0000000..21171a8 --- /dev/null +++ b/src/main/java/com/fr/plugin/reportRefresh/web/JavaScriptFile.java @@ -0,0 +1,16 @@ +package com.fr.plugin.reportRefresh.web; + +import com.fr.stable.fun.impl.AbstractJavaScriptFileHandler; + +/** + * Created by Slpire on 16/9/22. + */ +public class JavaScriptFile extends AbstractJavaScriptFileHandler { + + @Override + public String[] pathsForFiles() { + return new String[] { + "/com/fr/plugin/reportRefresh/web/refresh.js" + }; + } +} diff --git a/src/main/java/com/fr/plugin/reportRefresh/web/RefreshFormService.java b/src/main/java/com/fr/plugin/reportRefresh/web/RefreshFormService.java new file mode 100644 index 0000000..8d8961c --- /dev/null +++ b/src/main/java/com/fr/plugin/reportRefresh/web/RefreshFormService.java @@ -0,0 +1,32 @@ +package com.fr.plugin.reportRefresh.web; + +import com.fr.stable.fun.Service; +import com.fr.stable.web.RequestCMDReceiver; +import com.fr.web.core.WebActionsDispatcher; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Created by Slpire on 2016/10/29. + */ +public class RefreshFormService implements Service { + + private RequestCMDReceiver[] actions = { + new FormGetRefreshConfigAction(), + new CheckRefreshAreaAction() + }; + + public RefreshFormService() { + } + + @Override + public String actionOP() { + return "form_refresh"; + } + + @Override + public void process(HttpServletRequest req, HttpServletResponse res, String op, String sessionID) throws Exception { + WebActionsDispatcher.dealForActionDefaultCmd(req, res, sessionID, actions, FormGetRefreshConfigAction.CMD); + } +} diff --git a/src/main/resources/com/fr/plugin/reportRefresh/locale/refresh.properties b/src/main/resources/com/fr/plugin/reportRefresh/locale/refresh.properties new file mode 100644 index 0000000..7d7358c --- /dev/null +++ b/src/main/resources/com/fr/plugin/reportRefresh/locale/refresh.properties @@ -0,0 +1,15 @@ +FR-Plugin_Refresh=Refresh +FR-Plugin_Refresh-Plugin=Refresh PLugin +FR-Plugin_Monitor-Refresh=Monitor Refresh +FR-Plugin_Refresh-Area=Refresh Area +FR-Plugin_Refresh-Interval=Interval: +FR-Plugin_Refresh-Interval-Refresh=Interval Refresh +FR-Plugin_Refresh-No-Refresh=No Refresh +FR-Plugin_Refresh-Sample=eg: A1, C2:C12, E3:J6 +FR-Plugin_Refresh-Second=Second +FR-Plugin_Refresh-Type=Refresh Type: +FR-Plugin_Class-Refresh= +FR-Plugin_Refresh-Class= +FR-Plugin_Refresh-Label= +FR-Plugin_Refresh-Example= +FR-Plugin_Refresh-Tip= \ No newline at end of file diff --git a/src/main/resources/com/fr/plugin/reportRefresh/locale/refresh_en_US.properties b/src/main/resources/com/fr/plugin/reportRefresh/locale/refresh_en_US.properties new file mode 100644 index 0000000..080ce7b --- /dev/null +++ b/src/main/resources/com/fr/plugin/reportRefresh/locale/refresh_en_US.properties @@ -0,0 +1,15 @@ +FR-Plugin_Refresh=Refresh +FR-Plugin_Refresh-Plugin=Refresh PLugin +FR-Plugin_Monitor-Refresh=Monitor Refresh +FR-Plugin_Refresh-Area=Refresh Area +FR-Plugin_Refresh-Interval=Interval: +FR-Plugin_Refresh-Interval-Refresh=Interval Refresh +FR-Plugin_Refresh-No-Refresh=No Refresh +FR-Plugin_Refresh-Sample=eg: A1, C2:C12, E3:J6 +FR-Plugin_Refresh-Second=Second +FR-Plugin_Refresh-Type=Refresh Type: +FR-Plugin_Class-Refresh=Custom Refresh +FR-Plugin_Refresh-Class=Custom Class +FR-Plugin_Refresh-Label=Custom: +FR-Plugin_Refresh-Example=eg: com.fr.RefreshImpl +FR-Plugin_Refresh-Tip=you can implement ExecuteCondition to return wherher need refresh \ No newline at end of file diff --git a/src/main/resources/com/fr/plugin/reportRefresh/locale/refresh_zh_CN.properties b/src/main/resources/com/fr/plugin/reportRefresh/locale/refresh_zh_CN.properties new file mode 100644 index 0000000..465ff16 --- /dev/null +++ b/src/main/resources/com/fr/plugin/reportRefresh/locale/refresh_zh_CN.properties @@ -0,0 +1,15 @@ +FR-Plugin_Refresh=\u5237\u65B0 +FR-Plugin_Refresh-Plugin=\u8868\u5355\u62A5\u8868\u5757\u5237\u65B0\u63D2\u4EF6 +FR-Plugin_Monitor-Refresh=\u76D1\u63A7\u5237\u65B0 +FR-Plugin_Refresh-Area=\u76D1\u63A7\u533A\u57DF: +FR-Plugin_Refresh-Interval=\u5237\u65B0\u95F4\u9694:\u3000 +FR-Plugin_Refresh-Interval-Refresh=\u5B9A\u671F\u5237\u65B0 +FR-Plugin_Refresh-No-Refresh=\u5173\u95ED +FR-Plugin_Refresh-Sample=\u683C\u5F0F: A1, C2:C123, E3:J6 +FR-Plugin_Refresh-Second=\u79D2 +FR-Plugin_Refresh-Type=\u5237\u65B0\u673A\u5236: \u3000 +FR-Plugin_Class-Refresh=\u81EA\u5B9A\u4E49\u7C7B\u5237\u65B0 +FR-Plugin_Refresh-Class=\u81EA\u5B9A\u4E49\u7C7B +FR-Plugin_Refresh-Label=\u81EA\u5B9A\u4E49\u7C7B: +FR-Plugin_Refresh-Example=\u683C\u5F0F: com.fr.RefreshImpl +FR-Plugin_Refresh-Tip=\u60A8\u53EF\u4EE5\u901A\u8FC7\u81EA\u5B9A\u4E49\u7C7B\u5B9E\u73B0ExecuteCondition\u63A5\u53E3\u6765\u8FD4\u56DE\u662F\u5426\u9700\u8981\u5237\u65B0\u7EC4\u4EF6. \ No newline at end of file diff --git a/src/main/resources/com/fr/plugin/reportRefresh/locale/refresh_zh_TW.properties b/src/main/resources/com/fr/plugin/reportRefresh/locale/refresh_zh_TW.properties new file mode 100644 index 0000000..16de687 --- /dev/null +++ b/src/main/resources/com/fr/plugin/reportRefresh/locale/refresh_zh_TW.properties @@ -0,0 +1,15 @@ +FR-Plugin_Refresh=\u5237\u65B0 +FR-Plugin_Refresh-Plugin=\u8868\u5355\u62A5\u8868\u5757\u5237\u65B0\u63D2\u4EF6 +FR-Plugin_Monitor-Refresh=\u76E3\u63A7\u5237\u65B0 +FR-Plugin_Refresh-Area=\u76E3\u63A7\u55AE\u5143\u683C: +FR-Plugin_Refresh-Interval=\u5237\u65B0\u9593\u9694: +FR-Plugin_Refresh-Interval-Refresh=\u5B9A\u671F\u5237\u65B0 +FR-Plugin_Refresh-No-Refresh=\u95DC\u9589 +FR-Plugin_Refresh-Sample=\u683C\u5F0F: A1, C2:C12, E3:J6 +FR-Plugin_Refresh-Second=\u79D2 +FR-Plugin_Refresh-Type=\u5237\u65B0\u6A5F\u5236: +FR-Plugin_Class-Refresh=\u81EA\u5B9A\u7FA9\u985E\u5237\u65B0 +FR-Plugin_Refresh-Class=\u81EA\u5B9A\u4E49\u7C7B +FR-Plugin_Refresh-Label=\u81EA\u5B9A\u4E49\u7C7B: +FR-Plugin_Refresh-Example=\u683C\u5F0F: com.fr.RefreshImpl +FR-Plugin_Refresh-Tip=\u60A8\u53EF\u4EE5\u901A\u8FC7\u81EA\u5B9A\u4E49\u7C7B\u5B9E\u73B0ExecuteCondition\u63A5\u53E3\u6765\u8FD4\u56DE\u662F\u5426\u9700\u8981\u5237\u65B0\u7EC4\u4EF6. \ No newline at end of file diff --git a/src/main/resources/com/fr/plugin/reportRefresh/web/refresh.js b/src/main/resources/com/fr/plugin/reportRefresh/web/refresh.js new file mode 100644 index 0000000..64cbeaf --- /dev/null +++ b/src/main/resources/com/fr/plugin/reportRefresh/web/refresh.js @@ -0,0 +1,130 @@ +; +(function ($) { + //防止重复设置 + var flag = false; + FR.Form.Plugin.Panel.Events.push({ + name: FR.Events.AFTERLOAD, + + action: function () { + if (isParameterPane(this.options.type) || flag) { + return; + } + flag = true; + var sessionID = this.sessionID; + FR.ajax({ + url: FR.servletURL, + data: { + op: 'form_refresh', + cmd: 'config', + sessionID: sessionID, + _: new Date().getTime() + }, + async: false, + complete: function (res, status) { + if (status == 'success' && res.responseText) { + contenConfig = FR.jsonDecode(res.responseText); + doSetRefresh(contenConfig); + } + } + }); + } + }); + + var isParameterPane = function(type){ + //参数面板的form的话不走这边的逻辑 + return type === "parameter"; + }; + + var doSetRefresh = function (contenConfig) { + var reportsConfig = contenConfig.reports; + if (FR.isEmpty(reportsConfig)) { + return; + } + + for (var j = 0, length = reportsConfig.length; j < length; j++) { + var opts = reportsConfig[j]; + if (FR.isEmpty(opts.Refresh)) { + continue; + } + + var state = opts.Refresh.state; + var interval = opts.Refresh.interval; + + if (state === 0 || interval === 0) { + continue; + } + opts.sessionID = contenConfig.sessionID; + var refreshFunc = function (opts) { + return function () { + refreshReport(opts); + } + }; + window.setTimeout(refreshFunc(opts), interval * 1000); + } + }; + + var refreshReport = function (opts) { + var currentTime = new Date().getTime(); + var widget = _g().getWidgetByName(opts.widgetName); + if (FR.isEmpty(widget)) { + //有些控件会在某些操作之后创建,所以这边也要添加定时器 + window.setTimeout(function() { + refreshReport(opts); + }, opts.Refresh.interval * 1000); + return; + } + FR.ajax({ + url: FR.servletURL, + data: { + op: 'clear_pdl', + sessionID: opts.sessionID, + _: new Date().getTime() + } + }); + function fun(needRefresh) { + if(needRefresh){ + var animateProcessor = FR.Report.Plugin.AnimateProcessor; + var item = animateProcessor.item; + if (item && FR.Plugin.validLevel(animateProcessor, item) && item.refresh) { + item.refresh.call(this, widget, function () { + widget.gotoPage(1, "{}", 'lazy', false, false, true); + }); + resetTimer(); + return; + } + widget.gotoPage(1, "{}", 'lazy', false, false, true); + } + resetTimer(); + } + + function resetTimer() { + var proccessTime = opts.Refresh.interval * 1000 - new Date().getTime() + currentTime; + var timeout = proccessTime ? proccessTime : 0; + window.setTimeout(function () { + refreshReport(opts); + }, timeout); + } + + refreshByArea(opts, fun); + }; + + var refreshByArea = function (opts, callback) { + FR.ajax({ + url: FR.servletURL, + data: { + op: 'form_refresh', + cmd: 'area', + sessionID: opts.sessionID, + refreshArea: opts.Refresh.refreshArea, + customClass: opts.Refresh.customClass, + reportName: opts.widgetName, + _: new Date().getTime() + }, + complete: function (res, status) { + if (status == 'success') { + callback(res.responseText === 'true' || FR.isEmpty(opts.Refresh.refreshArea)); + } + } + }); + }; +})(jQuery);