forked from FR-Global/plugin-event-manager
Joe.Jiang
4 years ago
commit
a7d30f84d8
7 changed files with 552 additions and 0 deletions
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||
<plugin> |
||||
<id>com.fr.plugin.event.manager</id> |
||||
<name><![CDATA[Event Manager Demo]]></name> |
||||
<active>yes</active> |
||||
<version>1.0</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2020-02-28</jartime> |
||||
<vendor>finereport-joe</vendor> |
||||
<description><![CDATA[Event Manager Demo]]></description> |
||||
<change-notes><![CDATA[]]></change-notes> |
||||
<main-package>com.fr.plugin.event.manager</main-package> |
||||
<extra-designer> |
||||
<MenuHandler class="com.fr.plugin.event.manager.EventManager"/> |
||||
</extra-designer> |
||||
|
||||
<function-recorder class="com.fr.plugin.event.manager.WorkbookEventManager"/> |
||||
</plugin> |
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<artifactId>starter</artifactId> |
||||
<groupId>com.fr.plugin</groupId> |
||||
<version>10.0</version> |
||||
<relativePath>../../pom.xml</relativePath> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<artifactId>plugin-event-manager</artifactId> |
||||
|
||||
<build> |
||||
<outputDirectory>${project.basedir}/../../webroot/WEB-INF/plugins/plugin-com.fr.plugin.event.manager-1.0/classes</outputDirectory> |
||||
</build> |
||||
</project> |
@ -0,0 +1,47 @@
|
||||
package com.fr.plugin.event.manager; |
||||
|
||||
import com.fr.design.fun.MenuHandler; |
||||
import com.fr.design.fun.impl.AbstractMenuHandler; |
||||
import com.fr.design.mainframe.JForm; |
||||
import com.fr.design.mainframe.JWorkBook; |
||||
import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; |
||||
import com.fr.design.menu.ShortCut; |
||||
|
||||
/** |
||||
* @author Joe |
||||
* @version 10.0 |
||||
* Created by Joe on 9/3/2020 |
||||
*/ |
||||
public class EventManager extends AbstractMenuHandler { |
||||
@Override |
||||
public int insertPosition(int i) { |
||||
return -1; |
||||
} |
||||
|
||||
@Override |
||||
public boolean insertSeparatorBefore() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public boolean insertSeparatorAfter() { |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public String category() { |
||||
return MenuHandler.TEMPLATE; |
||||
} |
||||
|
||||
@Override |
||||
public ShortCut shortcut(ToolBarMenuDockPlus plus) { |
||||
if (plus instanceof JWorkBook) { |
||||
return new WorkbookEventManager((JWorkBook) plus); |
||||
} else if (plus instanceof JForm) { |
||||
return new FormEventManager((JForm) plus); |
||||
} |
||||
// ParameterDefinitePane pane = new ParameterDefinitePane();
|
||||
// pane.getParaDesigner().getParaTarget().getAllWidgets()
|
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,51 @@
|
||||
package com.fr.plugin.event.manager; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.design.actions.JTemplateAction; |
||||
import com.fr.design.mainframe.JForm; |
||||
import com.fr.form.main.Form; |
||||
import com.fr.form.ui.FormWidgetHelper; |
||||
import com.fr.form.ui.Widget; |
||||
import com.fr.form.ui.container.WLayout; |
||||
|
||||
import java.awt.event.ActionEvent; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author Joe |
||||
* Created by Joe on 9/3/2020 |
||||
*/ |
||||
public class FormEventManager extends JTemplateAction<JForm> { |
||||
|
||||
public FormEventManager(JForm jForm) { |
||||
super(jForm); |
||||
this.setMenuKeySet(KeySetUtils.EVENT_MANAGER); |
||||
this.setName(getMenuKeySet().getMenuKeySetName() + "..."); |
||||
this.setMnemonic(getMenuKeySet().getMnemonic()); |
||||
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/p.png")); |
||||
} |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
final JForm jwb = getEditingComponent(); |
||||
if (jwb == null) { |
||||
return; |
||||
} |
||||
final Form wbTpl = jwb.getTarget(); |
||||
// 获取最底层的表单容器
|
||||
WLayout container = wbTpl.getContainer(); |
||||
|
||||
// 获取参数面板容器
|
||||
WLayout parameterContainer = wbTpl.getParaContainer(); |
||||
if (parameterContainer != null) { |
||||
System.out.println("表单参数面板控件数:" + parameterContainer.getWidgetCount()); |
||||
System.out.println("根据Index获取控件:" + parameterContainer.getWidget(0)); |
||||
System.out.println("根据名称获取控件:" + parameterContainer.getWidget("textEditor0")); |
||||
} |
||||
|
||||
// 获取表单中指定名字的控件
|
||||
Widget report = wbTpl.getWidgetByName("report0"); |
||||
// 获取表单中指定名字的控件(不对WTitleLayout和WScaleLayout进一步处理)
|
||||
Widget chart = wbTpl.getWidgetWithBound("chart0"); |
||||
} |
||||
} |
@ -0,0 +1,28 @@
|
||||
package com.fr.plugin.event.manager; |
||||
|
||||
import com.fr.design.menu.MenuKeySet; |
||||
|
||||
import javax.swing.KeyStroke; |
||||
|
||||
/** |
||||
* @author Joe |
||||
* Created by Joe on 9/3/2020 |
||||
*/ |
||||
public class KeySetUtils { |
||||
public static final MenuKeySet EVENT_MANAGER = new MenuKeySet() { |
||||
@Override |
||||
public char getMnemonic() { |
||||
return 'E'; |
||||
} |
||||
|
||||
@Override |
||||
public String getMenuName() { |
||||
return "事件管理器"; |
||||
} |
||||
|
||||
@Override |
||||
public KeyStroke getKeyStroke() { |
||||
return null; |
||||
} |
||||
}; |
||||
} |
@ -0,0 +1,274 @@
|
||||
package com.fr.plugin.event.manager; |
||||
|
||||
import com.fr.base.Parameter; |
||||
import com.fr.base.TableData; |
||||
import com.fr.form.ui.Widget; |
||||
import com.fr.io.attr.ReportExportAttr; |
||||
import com.fr.main.TemplateWorkBook; |
||||
import com.fr.main.parameter.ReportParameterAttr; |
||||
import com.fr.main.workbook.ResultWorkBook; |
||||
import com.fr.report.fit.ReportFitAttr; |
||||
import com.fr.report.mobile.ElementCaseMobileAttr; |
||||
import com.fr.report.report.ECReport; |
||||
import com.fr.report.report.Report; |
||||
import com.fr.report.report.TemplateReport; |
||||
import com.fr.report.stable.fun.Actor; |
||||
import com.fr.report.worksheet.WorkSheet; |
||||
import com.fr.stable.fun.IOFileAttrMark; |
||||
import com.fr.stable.xml.XMLPrintWriter; |
||||
import com.fr.stable.xml.XMLableReader; |
||||
import com.fr.web.attr.ReportWebAttr; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Iterator; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 装饰器模式 |
||||
* @author Joe |
||||
* Created by Joe on 9/24/2020 |
||||
*/ |
||||
public class TemplateWorkBookDecorator implements TemplateWorkBook { |
||||
protected TemplateWorkBook decoratedTemplateWorkBook; |
||||
|
||||
private List<Widget> widgetList; |
||||
|
||||
public TemplateWorkBookDecorator(TemplateWorkBook templateWorkBook) { |
||||
decoratedTemplateWorkBook = templateWorkBook; |
||||
widgetList = new ArrayList<>(); |
||||
} |
||||
|
||||
@Override |
||||
public void addReport(TemplateReport templateReport) { |
||||
decoratedTemplateWorkBook.addReport(templateReport); |
||||
} |
||||
|
||||
@Override |
||||
public void addReport(String s, TemplateReport templateReport) { |
||||
decoratedTemplateWorkBook.addReport(s, templateReport); |
||||
} |
||||
|
||||
@Override |
||||
public void setReport(int i, TemplateReport templateReport) { |
||||
decoratedTemplateWorkBook.setReport(i, templateReport); |
||||
} |
||||
|
||||
@Override |
||||
public void setReport(int i, String s, TemplateReport templateReport) { |
||||
decoratedTemplateWorkBook.setReport(i, s, templateReport); |
||||
} |
||||
|
||||
@Override |
||||
public TemplateReport getTemplateReport(int i) { |
||||
return decoratedTemplateWorkBook.getTemplateReport(i); |
||||
} |
||||
|
||||
@Override |
||||
public WorkSheet getTemplateElementCaseReport(int i) { |
||||
return decoratedTemplateWorkBook.getTemplateElementCaseReport(i); |
||||
} |
||||
|
||||
@Override |
||||
public int getReportIndex(TemplateReport templateReport) { |
||||
return decoratedTemplateWorkBook.getReportIndex(templateReport); |
||||
} |
||||
|
||||
@Override |
||||
public void apply4Parameters(Map<String, Object> map) { |
||||
decoratedTemplateWorkBook.apply4Parameters(map); |
||||
} |
||||
|
||||
@Override |
||||
public ResultWorkBook execute(Map<String, Object> map, Actor actor) { |
||||
return decoratedTemplateWorkBook.execute(map, actor); |
||||
} |
||||
|
||||
@Override |
||||
public ResultWorkBook execute(Map<String, Object> map, Actor actor, int i) { |
||||
return decoratedTemplateWorkBook.execute(map, actor, i); |
||||
} |
||||
|
||||
@Override |
||||
public ReportParameterAttr getReportParameterAttr() { |
||||
return decoratedTemplateWorkBook.getReportParameterAttr(); |
||||
} |
||||
|
||||
@Override |
||||
public void setReportParameterAttr(ReportParameterAttr reportParameterAttr) { |
||||
decoratedTemplateWorkBook.setReportParameterAttr(reportParameterAttr); |
||||
} |
||||
|
||||
@Override |
||||
public Parameter[] getParameters() { |
||||
return decoratedTemplateWorkBook.getParameters(); |
||||
} |
||||
|
||||
@Override |
||||
public String getReportName(int i) { |
||||
return decoratedTemplateWorkBook.getReportName(i); |
||||
} |
||||
|
||||
@Override |
||||
public void setReportName(int i, String s) { |
||||
decoratedTemplateWorkBook.setReportName(i, s); |
||||
} |
||||
|
||||
@Override |
||||
public void removeReport(String s) { |
||||
decoratedTemplateWorkBook.removeReport(s); |
||||
} |
||||
|
||||
@Override |
||||
public void removeReport(int i) { |
||||
decoratedTemplateWorkBook.removeReport(i); |
||||
} |
||||
|
||||
@Override |
||||
public void removeReports() { |
||||
decoratedTemplateWorkBook.removeReports(); |
||||
} |
||||
|
||||
@Override |
||||
public Report getReport(int i) { |
||||
return decoratedTemplateWorkBook.getReport(i); |
||||
} |
||||
|
||||
@Override |
||||
public boolean isElementCaseBook() { |
||||
return decoratedTemplateWorkBook.isElementCaseBook(); |
||||
} |
||||
|
||||
@Override |
||||
public boolean isElementCaseBook(int i) { |
||||
return decoratedTemplateWorkBook.isElementCaseBook(i); |
||||
} |
||||
|
||||
@Override |
||||
public ECReport getElementCaseReport(int i) { |
||||
return decoratedTemplateWorkBook.getElementCaseReport(i); |
||||
} |
||||
|
||||
@Override |
||||
public int getReportCount() { |
||||
return decoratedTemplateWorkBook.getReportCount(); |
||||
} |
||||
|
||||
@Override |
||||
public ReportWebAttr getReportWebAttr() { |
||||
return decoratedTemplateWorkBook.getReportWebAttr(); |
||||
} |
||||
|
||||
@Override |
||||
public void setReportWebAttr(ReportWebAttr reportWebAttr) { |
||||
decoratedTemplateWorkBook.setReportWebAttr(reportWebAttr); |
||||
} |
||||
|
||||
@Override |
||||
public ReportExportAttr getReportExportAttr() { |
||||
return decoratedTemplateWorkBook.getReportExportAttr(); |
||||
} |
||||
|
||||
@Override |
||||
public void setReportExportAttr(ReportExportAttr reportExportAttr) { |
||||
decoratedTemplateWorkBook.setReportExportAttr(reportExportAttr); |
||||
} |
||||
|
||||
@Override |
||||
public ElementCaseMobileAttr getReportMobileAttr() { |
||||
return decoratedTemplateWorkBook.getReportMobileAttr(); |
||||
} |
||||
|
||||
@Override |
||||
public void setReportMobileAttr(ElementCaseMobileAttr elementCaseMobileAttr) { |
||||
decoratedTemplateWorkBook.setReportMobileAttr(elementCaseMobileAttr); |
||||
} |
||||
|
||||
@Override |
||||
public void addAttrMark(IOFileAttrMark ioFileAttrMark) { |
||||
decoratedTemplateWorkBook.addAttrMark(ioFileAttrMark); |
||||
} |
||||
|
||||
@Override |
||||
public <T extends IOFileAttrMark> T getAttrMark(String s) { |
||||
return decoratedTemplateWorkBook.getAttrMark(s); |
||||
} |
||||
|
||||
@Override |
||||
public Iterator<String> getAllMarkName() { |
||||
return decoratedTemplateWorkBook.getAllMarkName(); |
||||
} |
||||
|
||||
@Override |
||||
public Iterator<String> getTableDataNameIterator() { |
||||
return decoratedTemplateWorkBook.getTableDataNameIterator(); |
||||
} |
||||
|
||||
@Override |
||||
public TableData getTableData(String s) { |
||||
return decoratedTemplateWorkBook.getTableData(s); |
||||
} |
||||
|
||||
@Override |
||||
public void putTableData(String s, TableData tableData) { |
||||
decoratedTemplateWorkBook.putTableData(s, tableData); |
||||
} |
||||
|
||||
@Override |
||||
public boolean renameTableData(String s, String s1) { |
||||
return decoratedTemplateWorkBook.renameTableData(s, s1); |
||||
} |
||||
|
||||
@Override |
||||
public void removeTableData(String s) { |
||||
decoratedTemplateWorkBook.removeTableData(s); |
||||
} |
||||
|
||||
@Override |
||||
public void clearAllTableData() { |
||||
decoratedTemplateWorkBook.clearAllTableData(); |
||||
} |
||||
|
||||
@Override |
||||
public ReportFitAttr getReportFitAttr() { |
||||
return decoratedTemplateWorkBook.getReportFitAttr(); |
||||
} |
||||
|
||||
@Override |
||||
public void setReportFitAttr(ReportFitAttr reportFitAttr) { |
||||
decoratedTemplateWorkBook.setReportFitAttr(reportFitAttr); |
||||
} |
||||
|
||||
@Override |
||||
public void readXML(XMLableReader xmLableReader) { |
||||
decoratedTemplateWorkBook.readXML(xmLableReader); |
||||
} |
||||
|
||||
@Override |
||||
public void writeXML(XMLPrintWriter xmlPrintWriter) { |
||||
decoratedTemplateWorkBook.writeXML(xmlPrintWriter); |
||||
} |
||||
|
||||
@Override |
||||
public String[] getJSImport() { |
||||
return decoratedTemplateWorkBook.getJSImport(); |
||||
} |
||||
|
||||
@Override |
||||
public String[] getCSSImport() { |
||||
return decoratedTemplateWorkBook.getCSSImport(); |
||||
} |
||||
|
||||
@Override |
||||
public Object clone() throws CloneNotSupportedException { |
||||
return decoratedTemplateWorkBook.clone(); |
||||
} |
||||
|
||||
public List<Widget> getWidgetList() { |
||||
return widgetList; |
||||
} |
||||
|
||||
public void addWidget(Widget widget) { |
||||
this.widgetList.add(widget); |
||||
} |
||||
} |
@ -0,0 +1,116 @@
|
||||
package com.fr.plugin.event.manager; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.base.parameter.ParameterUI; |
||||
import com.fr.design.actions.JWorkBookAction; |
||||
import com.fr.design.mainframe.JWorkBook; |
||||
import com.fr.design.menu.MenuKeySet; |
||||
import com.fr.form.event.Listener; |
||||
import com.fr.form.ui.Widget; |
||||
import com.fr.js.JavaScript; |
||||
import com.fr.js.JavaScriptImpl; |
||||
import com.fr.main.TemplateWorkBook; |
||||
import com.fr.main.parameter.ReportParameterAttr; |
||||
import com.fr.plugin.transform.ExecuteFunctionRecord; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.privilege.finegrain.CellPrivilegeControl; |
||||
import com.fr.privilege.finegrain.WorkSheetPrivilegeControl; |
||||
import com.fr.report.cell.AbstractWidgetCellElement; |
||||
import com.fr.report.cell.CellElement; |
||||
import com.fr.report.cell.TemplateCellElement; |
||||
import com.fr.report.cell.WidgetAttrElem; |
||||
import com.fr.report.cell.cellattr.highlight.DefaultHighlight; |
||||
import com.fr.report.cell.cellattr.highlight.WidgetHighlightAction; |
||||
import com.fr.report.elementcase.ElementCase; |
||||
import com.fr.report.elementcase.TemplateElementCase; |
||||
import com.fr.report.report.Report; |
||||
import com.fr.report.report.TemplateReport; |
||||
|
||||
import javax.swing.KeyStroke; |
||||
import java.awt.event.ActionEvent; |
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.Iterator; |
||||
import java.util.List; |
||||
|
||||
import static com.fr.plugin.event.manager.KeySetUtils.EVENT_MANAGER; |
||||
|
||||
/** |
||||
* @author Joe |
||||
* Created by Joe on 9/3/2020 |
||||
*/ |
||||
@FunctionRecorder |
||||
public class WorkbookEventManager extends JWorkBookAction { |
||||
private List<Widget> widgetList = new ArrayList<>(); |
||||
|
||||
public WorkbookEventManager(JWorkBook jwb) { |
||||
super(jwb); |
||||
this.setMenuKeySet(KeySetUtils.EVENT_MANAGER); |
||||
this.setName(getMenuKeySet().getMenuKeySetName() + "..."); |
||||
this.setMnemonic(getMenuKeySet().getMnemonic()); |
||||
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/p.png")); |
||||
} |
||||
|
||||
@Override |
||||
@ExecuteFunctionRecord |
||||
public void actionPerformed(ActionEvent e) { |
||||
JWorkBook jwb = getEditingComponent(); |
||||
if (jwb == null) { |
||||
return; |
||||
} |
||||
|
||||
final TemplateWorkBook wbTpl = jwb.getTarget(); |
||||
ReportParameterAttr reportParameterAttr = wbTpl.getReportParameterAttr(); |
||||
// 参数面板获取控件
|
||||
ParameterUI parameterUI = reportParameterAttr.getParameterUI(); |
||||
Widget[] widgets = parameterUI.getAllWidgets(); |
||||
for (Widget widget : widgets) { |
||||
if (widget.getListenerSize() > 0) { |
||||
// 有事件的控件
|
||||
widgetList.add(widget); |
||||
} |
||||
|
||||
// 获取单元格控件
|
||||
for (int i = 0; i < wbTpl.getReportCount(); i++) { |
||||
Report report = wbTpl.getReport(i); |
||||
if (report != null) { |
||||
Iterator it = report.iteratorOfElementCase(); |
||||
while (it.hasNext()) { |
||||
ElementCase elementCase = (ElementCase) it.next(); |
||||
Iterator cellIterator = elementCase.cellIterator(); |
||||
while (cellIterator.hasNext()) { |
||||
CellElement cell = (CellElement) cellIterator.next(); |
||||
//单元格内有控件
|
||||
if (cell instanceof TemplateCellElement && ((TemplateCellElement) cell).getWidget() != null) { |
||||
Widget widget0 = ((TemplateCellElement) cell).getWidget(); |
||||
if (widget0.getListenerSize() > 0) { |
||||
widgetList.add(widget0); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
for (Widget widget1 : widgetList) { |
||||
for (int i = 0; i < widget1.getListenerSize(); i++) { |
||||
Listener listener = widget1.getListener(i); |
||||
JavaScript javaScript = listener.getAction(); |
||||
System.out.println("控件名:" + widget1.getWidgetName()); |
||||
System.out.println("事件名:" + listener.getEventName()); |
||||
System.out.println("事件类型:" + javaScript.getClass().getName()); |
||||
} |
||||
} |
||||
|
||||
/* // 测试修改控件事件
|
||||
if("test".equals(widget.getWidgetName())) { |
||||
Listener listener = new Listener(); |
||||
listener.setEventName("afterinit"); |
||||
JavaScriptImpl javaScript = new JavaScriptImpl(); |
||||
javaScript.setContent("this is a test"); |
||||
listener.setAction(javaScript); |
||||
widget.addListener(listener); |
||||
}*/ |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue