From 2080facd57f7be23822c7c07ce893f7f251b1f2c Mon Sep 17 00:00:00 2001 From: Joe <825510477@qq.com> Date: Mon, 21 Dec 2020 09:49:55 +0800 Subject: [PATCH] Event manager update stash --- plugin.xml | 2 +- .../event/manager/core/EventManager.java | 69 ------------- .../event/manager/core/FormEventManager.java | 65 ++++++++++--- .../manager/core/WorkbookEventManager.java | 63 ++++++++++-- .../event/manager/data/MyCellWidget.java | 1 - .../fr/plugin/event/manager/data/MyNode.java | 7 +- .../fr/plugin/event/manager/data/MyTree.java | 27 ++++-- .../plugin/event/manager/data/MyWidget.java | 7 +- .../event/manager/ui/CellWidgetPane.java | 19 ++++ .../event/manager/ui/EventConfigPane.java | 4 +- .../event/manager/ui/EventManagerPane.java | 1 + .../manager/ui/FormEventManagerPane.java | 7 +- .../manager/ui/WorkbookEventManagerPane.java | 96 +++++++++++-------- .../ui/tree/MyComponentCellRenderer.java | 5 +- .../manager/ui/tree/MyComponentTree.java | 28 +++++- 15 files changed, 241 insertions(+), 160 deletions(-) delete mode 100644 src/main/java/com/fr/plugin/event/manager/core/EventManager.java diff --git a/plugin.xml b/plugin.xml index d630479..7f2dce3 100644 --- a/plugin.xml +++ b/plugin.xml @@ -14,5 +14,5 @@ - + \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/event/manager/core/EventManager.java b/src/main/java/com/fr/plugin/event/manager/core/EventManager.java deleted file mode 100644 index a5f7fb7..0000000 --- a/src/main/java/com/fr/plugin/event/manager/core/EventManager.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.fr.plugin.event.manager.core; - -import com.fr.base.BaseUtils; -import com.fr.design.DesignModelAdapter; -import com.fr.design.actions.JTemplateAction; -import com.fr.design.dialog.FineJOptionPane; -import com.fr.design.dialog.UIDialog; -import com.fr.design.mainframe.DesignerContext; -import com.fr.design.mainframe.JTemplate; -import com.fr.design.mainframe.WidgetPropertyPane; -import com.fr.form.main.Form; -import com.fr.plugin.event.manager.ui.EventManagerDialog; -import com.fr.plugin.event.manager.ui.EventManagerPane; -import com.fr.plugin.event.manager.utils.KeySetUtils; -import com.fr.plugin.transform.ExecuteFunctionRecord; -import com.fr.plugin.transform.FunctionRecorder; - -import javax.swing.JOptionPane; -import java.awt.event.ActionEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; - -/** - * @author Joe - * Created by Joe on 12/11/2020 - */ -@FunctionRecorder -public abstract class EventManager extends JTemplateAction> { - - public EventManager(JTemplate jTemplate) { - super(jTemplate); - this.setMenuKeySet(KeySetUtils.EVENT_MANAGER); - this.setName(getMenuKeySet().getMenuKeySetName() + "..."); - this.setMnemonic(getMenuKeySet().getMnemonic()); - this.setSmallIcon(BaseUtils.readIcon("/com/fr/plugin/event/manager/images/icon_event_manager.png")); - } - - @Override - @ExecuteFunctionRecord - public void actionPerformed(ActionEvent e) { - JTemplate jt = getEditingComponent(); - if (jt == null) { - FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), "无法获取模板对象!", - com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Alert"), JOptionPane.ERROR_MESSAGE); - return; - } - - final Object target = jt.getTarget(); - final EventManagerPane eventManagerPane = initEventManager(target); - UIDialog dialog = new EventManagerDialog(DesignerContext.getDesignerFrame(), eventManagerPane); - - dialog.addWindowListener(new WindowAdapter() { - @Override - public void windowClosed(WindowEvent e) { - eventManagerPane.update(); - // 刷新一下右侧面板,避免事件显示不同步 - if (target instanceof Form) { - WidgetPropertyPane.getInstance().refreshDockingView(); - } - // 触发正在编辑的模板改变事件 - DesignModelAdapter.getCurrentModelAdapter().fireTargetModified(); - super.windowClosed(e); - } - }); - dialog.setVisible(true); - } - - protected abstract EventManagerPane initEventManager(Object target); -} diff --git a/src/main/java/com/fr/plugin/event/manager/core/FormEventManager.java b/src/main/java/com/fr/plugin/event/manager/core/FormEventManager.java index 6d1610d..1169dfe 100644 --- a/src/main/java/com/fr/plugin/event/manager/core/FormEventManager.java +++ b/src/main/java/com/fr/plugin/event/manager/core/FormEventManager.java @@ -1,32 +1,75 @@ package com.fr.plugin.event.manager.core; -import com.fr.design.dialog.BasicPane; -import com.fr.design.mainframe.JTemplate; +import com.fr.base.BaseUtils; +import com.fr.design.DesignModelAdapter; +import com.fr.design.actions.JTemplateAction; +import com.fr.design.dialog.FineJOptionPane; +import com.fr.design.dialog.UIDialog; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.JForm; +import com.fr.design.mainframe.WidgetPropertyPane; import com.fr.form.main.Form; +import com.fr.plugin.event.manager.ui.EventManagerDialog; import com.fr.plugin.event.manager.ui.EventManagerPane; import com.fr.plugin.event.manager.ui.FormEventManagerPane; +import com.fr.plugin.event.manager.utils.KeySetUtils; +import com.fr.plugin.transform.ExecuteFunctionRecord; + +import javax.swing.JOptionPane; +import java.awt.event.ActionEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; /** * @author Joe * Created by Joe on 9/3/2020 */ -public class FormEventManager extends EventManager { +public class FormEventManager extends JTemplateAction { - public FormEventManager(JTemplate jTemplate) { - super(jTemplate); + public FormEventManager(JForm form) { + super(form); + this.setMenuKeySet(KeySetUtils.EVENT_MANAGER); + this.setName(getMenuKeySet().getMenuKeySetName() + "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/plugin/event/manager/images/icon_event_manager.png")); + } + + @Override + @ExecuteFunctionRecord + public void actionPerformed(ActionEvent e) { + JForm jf = getEditingComponent(); + if (jf == null) { + FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), "无法获取模板对象!", + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Alert"), JOptionPane.ERROR_MESSAGE); + return; + } + + final Form form = jf.getTarget(); + final EventManagerPane eventManagerPane = initEventManager(form); + UIDialog dialog = new EventManagerDialog(DesignerContext.getDesignerFrame(), eventManagerPane); + + dialog.addWindowListener(new WindowAdapter() { + @Override + public void windowClosed(WindowEvent e) { + eventManagerPane.update(); + // 触发正在编辑的模板改变事件 + DesignModelAdapter.getCurrentModelAdapter().fireTargetModified(); + // 刷新一下右侧面板,避免事件显示不同步 + WidgetPropertyPane.getInstance().refreshDockingView(); + super.windowClosed(e); + } + }); + dialog.setVisible(true); } /** - * @param target + * @param form * @return */ - @Override - protected EventManagerPane initEventManager(Object target) { + private EventManagerPane initEventManager(Form form) { FormEventManagerPane eventManagerPane = new FormEventManagerPane(); - if (target instanceof Form) { - eventManagerPane.setTarget((Form) target); - } + eventManagerPane.setTarget(form); return eventManagerPane; } } diff --git a/src/main/java/com/fr/plugin/event/manager/core/WorkbookEventManager.java b/src/main/java/com/fr/plugin/event/manager/core/WorkbookEventManager.java index e29793e..4cb44f4 100644 --- a/src/main/java/com/fr/plugin/event/manager/core/WorkbookEventManager.java +++ b/src/main/java/com/fr/plugin/event/manager/core/WorkbookEventManager.java @@ -1,33 +1,76 @@ package com.fr.plugin.event.manager.core; -import com.fr.design.mainframe.JTemplate; +import com.fr.base.BaseUtils; +import com.fr.design.DesignModelAdapter; +import com.fr.design.actions.JWorkBookAction; +import com.fr.design.dialog.FineJOptionPane; +import com.fr.design.dialog.UIDialog; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.JWorkBook; import com.fr.main.TemplateWorkBook; +import com.fr.plugin.event.manager.ui.EventManagerDialog; import com.fr.plugin.event.manager.ui.EventManagerPane; import com.fr.plugin.event.manager.ui.WorkbookEventManagerPane; +import com.fr.plugin.event.manager.utils.KeySetUtils; +import com.fr.plugin.transform.ExecuteFunctionRecord; +import com.fr.plugin.transform.FunctionRecorder; + +import javax.swing.JOptionPane; +import java.awt.event.ActionEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; /** * @author Joe * Created by Joe on 9/3/2020 */ -public class WorkbookEventManager extends EventManager { +@FunctionRecorder +public class WorkbookEventManager extends JWorkBookAction { - public WorkbookEventManager(JTemplate jTemplate) { - super(jTemplate); + 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/plugin/event/manager/images/icon_event_manager.png")); + } + + @Override + @ExecuteFunctionRecord + public void actionPerformed(ActionEvent e) { + JWorkBook jwb = getEditingComponent(); + if (jwb == null) { + FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), "无法获取模板对象!", + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Alert"), JOptionPane.ERROR_MESSAGE); + return; + } + + final TemplateWorkBook workBook = jwb.getTarget(); + final EventManagerPane eventManagerPane = initEventManager(workBook); + UIDialog dialog = new EventManagerDialog(DesignerContext.getDesignerFrame(), eventManagerPane); + + dialog.addWindowListener(new WindowAdapter() { + @Override + public void windowClosed(WindowEvent e) { + eventManagerPane.update(); + // 触发正在编辑的模板改变事件 + DesignModelAdapter.getCurrentModelAdapter().fireTargetModified(); + super.windowClosed(e); + } + }); + dialog.setVisible(true); } /** * workbook返回tabPane * - * @param target + * @param workBook * @return */ - @Override - protected EventManagerPane initEventManager(Object target) { + private EventManagerPane initEventManager(TemplateWorkBook workBook) { WorkbookEventManagerPane eventManagerPane = new WorkbookEventManagerPane(); - if (target instanceof TemplateWorkBook) { - eventManagerPane.setTarget((TemplateWorkBook) target); - } + eventManagerPane.setTarget(workBook); return eventManagerPane; } diff --git a/src/main/java/com/fr/plugin/event/manager/data/MyCellWidget.java b/src/main/java/com/fr/plugin/event/manager/data/MyCellWidget.java index 7ba7fad..fdd1b93 100644 --- a/src/main/java/com/fr/plugin/event/manager/data/MyCellWidget.java +++ b/src/main/java/com/fr/plugin/event/manager/data/MyCellWidget.java @@ -11,7 +11,6 @@ import javax.swing.Icon; */ public class MyCellWidget extends MyWidget { private CellElement cellElement; - private Widget widget; // 来自普通还是条件属性 private WidgetSource source; diff --git a/src/main/java/com/fr/plugin/event/manager/data/MyNode.java b/src/main/java/com/fr/plugin/event/manager/data/MyNode.java index e1aee52..c201c6d 100644 --- a/src/main/java/com/fr/plugin/event/manager/data/MyNode.java +++ b/src/main/java/com/fr/plugin/event/manager/data/MyNode.java @@ -8,6 +8,7 @@ import javax.swing.Icon; */ public class MyNode { protected String nodeName; + protected Icon icon; public MyNode() { @@ -26,6 +27,10 @@ public class MyNode { } public Icon getIcon() { - return null; + return icon; + } + + public void setIcon(Icon icon) { + this.icon = icon; } } diff --git a/src/main/java/com/fr/plugin/event/manager/data/MyTree.java b/src/main/java/com/fr/plugin/event/manager/data/MyTree.java index ac0ad60..89c1102 100644 --- a/src/main/java/com/fr/plugin/event/manager/data/MyTree.java +++ b/src/main/java/com/fr/plugin/event/manager/data/MyTree.java @@ -28,7 +28,9 @@ public class MyTree { */ private List elementsIndex; - private boolean visible; + public MyTree() { + this(new MyNode()); + } /** * 构造函数 @@ -40,15 +42,14 @@ public class MyTree { this.children = new LinkedList<>(); this.elementsIndex = new LinkedList<>(); this.elementsIndex.add(this); - this.visible = true; } public MyNode getData() { return data; } - public void setVisible(boolean visible) { - this.visible = visible; + public void setData(MyNode data) { + this.data = data; } public List getChildren() { @@ -80,18 +81,24 @@ public class MyTree { /** * 添加一个子节点 * - * @param child - * @return + * @param child 子树 + */ + public void addChild(MyTree child) { + child.parent = this; + this.children.add(child); + this.registerChildForSearch(child); + } + + /** + * 添加一个子节点 + * @param child 子树的数据 + * @return 子树 */ public MyTree addChild(MyNode child) { MyTree childNode = new MyTree(child); - childNode.parent = this; - this.children.add(childNode); - this.registerChildForSearch(childNode); - return childNode; } diff --git a/src/main/java/com/fr/plugin/event/manager/data/MyWidget.java b/src/main/java/com/fr/plugin/event/manager/data/MyWidget.java index d2d5ead..7df01d5 100644 --- a/src/main/java/com/fr/plugin/event/manager/data/MyWidget.java +++ b/src/main/java/com/fr/plugin/event/manager/data/MyWidget.java @@ -16,6 +16,8 @@ public class MyWidget extends MyNode { public MyWidget(Widget widget) { this.widget = widget; this.nodeName = widget.getWidgetName(); + XCreator creator = XCreatorUtils.createXCreator(widget); + this.icon = XCreatorUtils.getCreatorIcon(creator); } public Widget getWidget() { @@ -25,9 +27,4 @@ public class MyWidget extends MyNode { public void setWidget(Widget widget) { this.widget = widget; } - - public Icon getIcon() { - XCreator creator = XCreatorUtils.createXCreator(widget); - return XCreatorUtils.getCreatorIcon(creator); - } } diff --git a/src/main/java/com/fr/plugin/event/manager/ui/CellWidgetPane.java b/src/main/java/com/fr/plugin/event/manager/ui/CellWidgetPane.java index 703dab3..6a0bf2e 100644 --- a/src/main/java/com/fr/plugin/event/manager/ui/CellWidgetPane.java +++ b/src/main/java/com/fr/plugin/event/manager/ui/CellWidgetPane.java @@ -1,8 +1,10 @@ package com.fr.plugin.event.manager.ui; import com.fr.design.dialog.BasicPane; +import com.fr.design.layout.FRGUIPaneFactory; import com.fr.plugin.event.manager.data.MyTree; +import java.awt.BorderLayout; import java.util.List; /** @@ -11,9 +13,26 @@ import java.util.List; */ public class CellWidgetPane extends BasicPane { private List cellWidgetTrees; + private EventConfigPane eventConfigPane; public CellWidgetPane(List cellWidgetTrees) { this.cellWidgetTrees = cellWidgetTrees; + initComponentPane(); + } + + private void initComponentPane() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + initEventConfigPane(); + this.add(eventConfigPane, BorderLayout.CENTER); + } + + private void initEventConfigPane() { + // 初始化事件面板 + if (cellWidgetTrees.size() > 0) { + eventConfigPane = new EventConfigPane(cellWidgetTrees.get(0)); + } else { + eventConfigPane = new EventConfigPane(new MyTree()); + } } public String tabTitle() { diff --git a/src/main/java/com/fr/plugin/event/manager/ui/EventConfigPane.java b/src/main/java/com/fr/plugin/event/manager/ui/EventConfigPane.java index 852e3e2..7366742 100644 --- a/src/main/java/com/fr/plugin/event/manager/ui/EventConfigPane.java +++ b/src/main/java/com/fr/plugin/event/manager/ui/EventConfigPane.java @@ -45,7 +45,7 @@ public class EventConfigPane extends BasicPane implements TreeSelectionListener public EventConfigPane(MyTree tree, boolean rootVisible) { this.tree = tree; this.rootVisible = rootVisible; - this.initComponentPane(); + initComponentPane(); } public MyTree getTree() { @@ -102,7 +102,7 @@ public class EventConfigPane extends BasicPane implements TreeSelectionListener leftPane.add(leftContentPane, BorderLayout.CENTER); // 左上方 items with event JPanel leftTopPane = getLeftTopPane(); - leftTopPane.setBorder(BorderFactory.createEmptyBorder(0, 6, 6, 0)); + leftTopPane.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 0)); leftPane.add(leftTopPane, BorderLayout.NORTH); return leftPane; } diff --git a/src/main/java/com/fr/plugin/event/manager/ui/EventManagerPane.java b/src/main/java/com/fr/plugin/event/manager/ui/EventManagerPane.java index 1222e8c..bd28751 100644 --- a/src/main/java/com/fr/plugin/event/manager/ui/EventManagerPane.java +++ b/src/main/java/com/fr/plugin/event/manager/ui/EventManagerPane.java @@ -5,6 +5,7 @@ import com.fr.design.gui.frpane.LoadingBasicPane; import javax.swing.JPanel; /** + * 普通报表和表单事件管理器的父类 * @author Joe * Created by Joe on 12/11/2020 */ diff --git a/src/main/java/com/fr/plugin/event/manager/ui/FormEventManagerPane.java b/src/main/java/com/fr/plugin/event/manager/ui/FormEventManagerPane.java index c47e8fd..78e6e12 100644 --- a/src/main/java/com/fr/plugin/event/manager/ui/FormEventManagerPane.java +++ b/src/main/java/com/fr/plugin/event/manager/ui/FormEventManagerPane.java @@ -3,9 +3,9 @@ package com.fr.plugin.event.manager.ui; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.form.main.Form; import com.fr.form.ui.Widget; -import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WCardLayout; import com.fr.form.ui.container.WLayout; +import com.fr.form.ui.widget.CRBoundsWidget; import com.fr.plugin.event.manager.data.MyNode; import com.fr.plugin.event.manager.data.MyTree; import com.fr.plugin.event.manager.data.MyWidget; @@ -26,7 +26,6 @@ public class FormEventManagerPane extends EventManagerPane
{ container.setLayout(FRGUIPaneFactory.createBorderLayout()); eventConfigPane = new EventConfigPane(tree); container.add(eventConfigPane, BorderLayout.CENTER); - } @Override @@ -53,8 +52,8 @@ public class FormEventManagerPane extends EventManagerPane { * @param tree */ private void traversalWidget(Widget widget, MyTree tree) { - if (widget instanceof WAbsoluteLayout.BoundsWidget) { - traversalWidget(((WAbsoluteLayout.BoundsWidget) widget).getWidget(), tree); + if (widget instanceof CRBoundsWidget) { + traversalWidget(((CRBoundsWidget) widget).getWidget(), tree); } else if (widget instanceof WLayout) { MyNode node = new MyWidget(widget); MyTree subTree = tree.addChild(node); diff --git a/src/main/java/com/fr/plugin/event/manager/ui/WorkbookEventManagerPane.java b/src/main/java/com/fr/plugin/event/manager/ui/WorkbookEventManagerPane.java index 0dab645..91bd2f7 100644 --- a/src/main/java/com/fr/plugin/event/manager/ui/WorkbookEventManagerPane.java +++ b/src/main/java/com/fr/plugin/event/manager/ui/WorkbookEventManagerPane.java @@ -4,11 +4,15 @@ import com.fr.design.gui.frpane.UITabbedPane; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.form.main.parameter.FormParameterUI; import com.fr.form.ui.Widget; +import com.fr.general.IOUtils; import com.fr.main.TemplateWorkBook; import com.fr.main.parameter.ReportParameterAttr; +import com.fr.plugin.event.manager.data.MyCellWidget; import com.fr.plugin.event.manager.data.MyNode; import com.fr.plugin.event.manager.data.MyTree; import com.fr.plugin.event.manager.data.MyWidget; +import com.fr.plugin.event.manager.data.WidgetSource; +import com.fr.plugin.event.manager.utils.CommonConstants; import com.fr.report.cell.CellElement; import com.fr.report.cell.TemplateCellElement; import com.fr.report.cell.cellattr.highlight.DefaultHighlight; @@ -22,7 +26,6 @@ import javax.swing.JTabbedPane; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import java.awt.BorderLayout; -import java.awt.Component; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -72,7 +75,9 @@ public class WorkbookEventManagerPane extends EventManagerPane @Override public void initData(TemplateWorkBook target) { + parameterTree = new MyTree(); initParaWidget(target); + cellWidgetTrees = new ArrayList<>(); initCellWidget(target); } @@ -84,7 +89,7 @@ public class WorkbookEventManagerPane extends EventManagerPane FormParameterUI parameterUI = (FormParameterUI) reportParameterAttr.getParameterUI(); if (parameterUI != null) { MyNode root = new MyWidget(parameterUI.getParaContainer()); - parameterTree = new MyTree(root); + parameterTree.setData(root); // 获取参数面板所有控件 Widget[] widgets = parameterUI.getAllWidgets(); for (int i = 1; i < widgets.length; i++) { @@ -98,7 +103,6 @@ public class WorkbookEventManagerPane extends EventManagerPane } private void initCellWidget(TemplateWorkBook workBook) { - cellWidgetTrees = new ArrayList<>(); // 获取单元格控件 for (int i = 0; i < workBook.getReportCount(); i++) { // 通过模板对象,获取报表页对象 @@ -112,45 +116,20 @@ public class WorkbookEventManagerPane extends EventManagerPane while (it.hasNext()) { // 通过迭代器,获取格子报表页对象 ElementCase elementCase = (ElementCase) it.next(); - MyNode block = new MyNode(); - MyTree tempBlockTree = new MyTree(block); - Iterator cellIterator = elementCase.cellIterator(); - while (cellIterator.hasNext()) { - // 通过迭代器,获取单元格对象 - CellElement cell = (CellElement) cellIterator.next(); - if (cell instanceof TemplateCellElement) { - if (((TemplateCellElement) cell).getWidget() != null) { - // 获取单元格控件 - Widget widget0 = ((TemplateCellElement) cell).getWidget(); - if (widget0.getListenerSize() > 0) { - // 控件有事件 - tempBlockTree.addChild(new MyWidget(widget0)); - hasWidgetEvent = true; - } - } - // 获取条件属性控件 - if (((TemplateCellElement) cell).getHighlightGroup() != null) { - int highlightSize = ((TemplateCellElement) cell).getHighlightGroup().size(); - for (int j = 0; j < highlightSize; j++) { - DefaultHighlight highlight = (DefaultHighlight) ((TemplateCellElement) cell).getHighlightGroup().getHighlight(j); - for (int k = 0; k < highlight.actionCount(); k++) { - if (highlight.getHighlightAction(k) instanceof WidgetHighlightAction) { - WidgetHighlightAction highlightAction = (WidgetHighlightAction) highlight.getHighlightAction(k); - tempBlockTree.addChild(new MyWidget(highlightAction.getWidget())); - hasWidgetEvent = true; - } - } - } - } + if (elementCase instanceof PolyECBlock) { + // 如果是聚合报表块,给节点添加名字 + MyNode block = new MyNode(((PolyECBlock) elementCase).getBlockName()); + // 设置图标,避免奇怪的错误 + block.setIcon(IOUtils.readIcon(CommonConstants.BLOCK_ICON_PATH)); + MyTree tempBlockTree = new MyTree(block); + if (initTree(tempBlockTree, elementCase)) { + // 如果块有事件,添加此块,并且这个sheet也要被添加 + tempSheetTree.addChild(tempBlockTree); + hasWidgetEvent = true; } - } - if (hasWidgetEvent) { - // 如果有控件 - if (elementCase instanceof PolyECBlock) { - // 如果是聚合报表块,给节点添加名字 - block.setNodeName(((PolyECBlock) elementCase).getBlockName()); - } - tempSheetTree.addChild(block); + } else { + // 如果是普通报表 + hasWidgetEvent = initTree(tempSheetTree, elementCase); } } if (hasWidgetEvent) { @@ -160,6 +139,41 @@ public class WorkbookEventManagerPane extends EventManagerPane } } + private boolean initTree(MyTree tree, ElementCase elementCase) { + boolean hasWidgetEvent = false; + Iterator cellIterator = elementCase.cellIterator(); + while (cellIterator.hasNext()) { + // 通过迭代器,获取单元格对象 + CellElement cell = (CellElement) cellIterator.next(); + if (cell instanceof TemplateCellElement) { + if (((TemplateCellElement) cell).getWidget() != null) { + // 获取单元格控件 + Widget widget0 = ((TemplateCellElement) cell).getWidget(); + if (widget0.getListenerSize() > 0) { + // 控件有事件 + tree.addChild(new MyCellWidget(cell, widget0)); + hasWidgetEvent = true; + } + } + // 获取条件属性控件 + if (((TemplateCellElement) cell).getHighlightGroup() != null) { + int highlightSize = ((TemplateCellElement) cell).getHighlightGroup().size(); + for (int j = 0; j < highlightSize; j++) { + DefaultHighlight highlight = (DefaultHighlight) ((TemplateCellElement) cell).getHighlightGroup().getHighlight(j); + for (int k = 0; k < highlight.actionCount(); k++) { + if (highlight.getHighlightAction(k) instanceof WidgetHighlightAction) { + WidgetHighlightAction highlightAction = (WidgetHighlightAction) highlight.getHighlightAction(k); + tree.addChild(new MyCellWidget(cell, highlightAction.getWidget(), WidgetSource.HIGHLIGHT)); + hasWidgetEvent = true; + } + } + } + } + } + } + return hasWidgetEvent; + } + /** * 当initComponents执行完后调用 */ diff --git a/src/main/java/com/fr/plugin/event/manager/ui/tree/MyComponentCellRenderer.java b/src/main/java/com/fr/plugin/event/manager/ui/tree/MyComponentCellRenderer.java index f7979e9..2c1792f 100644 --- a/src/main/java/com/fr/plugin/event/manager/ui/tree/MyComponentCellRenderer.java +++ b/src/main/java/com/fr/plugin/event/manager/ui/tree/MyComponentCellRenderer.java @@ -1,9 +1,5 @@ package com.fr.plugin.event.manager.ui.tree; -import com.fr.design.constants.UIConstants; -import com.fr.design.designer.creator.XCreator; -import com.fr.design.designer.creator.XCreatorUtils; -import com.fr.log.FineLoggerFactory; import com.fr.plugin.event.manager.data.MyTree; import javax.swing.BorderFactory; @@ -27,6 +23,7 @@ public class MyComponentCellRenderer extends DefaultTreeCellRenderer { super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); if (value instanceof MyTree) { String name = ((MyTree) value).getData().getNodeName(); + // todo 或许要用html使文字换行 https://www.open-open.com/blog/5035948000942327244.html setText(name); Icon icon = ((MyTree) value).getData().getIcon(); if (icon != null) { diff --git a/src/main/java/com/fr/plugin/event/manager/ui/tree/MyComponentTree.java b/src/main/java/com/fr/plugin/event/manager/ui/tree/MyComponentTree.java index c4d51dd..02ea8af 100644 --- a/src/main/java/com/fr/plugin/event/manager/ui/tree/MyComponentTree.java +++ b/src/main/java/com/fr/plugin/event/manager/ui/tree/MyComponentTree.java @@ -1,14 +1,15 @@ package com.fr.plugin.event.manager.ui.tree; -import com.fr.design.constants.UIConstants; import com.fr.design.gui.itree.UITreeUI; import com.fr.plugin.event.manager.data.MyTree; import com.fr.plugin.event.manager.ui.EventConfigPane; import javax.swing.BorderFactory; import javax.swing.JTree; +import javax.swing.tree.TreePath; import javax.swing.tree.TreeSelectionModel; import java.awt.Color; +import java.util.List; /** * @author Joe @@ -36,10 +37,35 @@ public class MyComponentTree extends JTree { setEditable(false); setUI(uiTreeUI); setBorder(BorderFactory.createEmptyBorder(PADDING_TOP, PADDING_LEFT, 0, 0)); + // 展开树 + expandTree(); } private void initListener() { this.addTreeSelectionListener(configPane); } + /** + * 最多展开一层 + */ + private void expandTree() { + MyTree root = (MyTree) this.getModel().getRoot(); + expandTree(new TreePath(root), 1); + } + + private void expandTree(TreePath path, int layer) { + MyTree node = (MyTree) path.getLastPathComponent(); + + // Go to leaf + if (node.getChildrenSize() > 0 && layer > 0) { + List children = node.getChildren(); + for (MyTree n : children) { + TreePath newPath = path.pathByAddingChild(n); + expandTree(newPath, --layer); + } + } + + this.expandPath(path); + } + }