Browse Source

组件事件管理器 - 更新

master
Joe 4 years ago committed by Joe.Jiang
parent
commit
95dc90025c
  1. 30
      src/main/java/com/fr/plugin/event/manager/core/EventManager.java
  2. 4
      src/main/java/com/fr/plugin/event/manager/core/FormEventManager.java
  3. 4
      src/main/java/com/fr/plugin/event/manager/core/WorkbookEventManager.java
  4. 52
      src/main/java/com/fr/plugin/event/manager/data/MyCellWidget.java
  5. 37
      src/main/java/com/fr/plugin/event/manager/data/MyContainer.java
  6. 26
      src/main/java/com/fr/plugin/event/manager/data/MyNode.java
  7. 28
      src/main/java/com/fr/plugin/event/manager/data/MySheet.java
  8. 137
      src/main/java/com/fr/plugin/event/manager/data/MyTree.java
  9. 27
      src/main/java/com/fr/plugin/event/manager/data/MyWidget.java
  10. 13
      src/main/java/com/fr/plugin/event/manager/ui/CellWidgetPane.java
  11. 141
      src/main/java/com/fr/plugin/event/manager/ui/EventConfigPane.java
  12. 4
      src/main/java/com/fr/plugin/event/manager/ui/EventManagerPane.java
  13. 62
      src/main/java/com/fr/plugin/event/manager/ui/FormEventManagerPane.java
  14. 91
      src/main/java/com/fr/plugin/event/manager/ui/WorkbookEventManagerPane.java
  15. 55
      src/main/java/com/fr/plugin/event/manager/ui/tree/MyComponentCellRenderer.java
  16. 31
      src/main/java/com/fr/plugin/event/manager/ui/tree/MyComponentTree.java
  17. 22
      src/main/java/com/fr/plugin/event/manager/ui/tree/MyComponentTreeModel.java
  18. 2
      src/main/java/com/fr/plugin/event/manager/utils/KeySetUtils.java

30
src/main/java/com/fr/plugin/event/manager/core/EventManager.java

@ -1,19 +1,27 @@
package com.fr.plugin.event.manager.core; package com.fr.plugin.event.manager.core;
import com.fr.base.BaseUtils; import com.fr.base.BaseUtils;
import com.fr.design.DesignModelAdapter;
import com.fr.design.actions.JTemplateAction; import com.fr.design.actions.JTemplateAction;
import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.dialog.FineJOptionPane; import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.dialog.UIDialog; import com.fr.design.dialog.UIDialog;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.JWorkBook;
import com.fr.design.mainframe.WidgetPropertyPane;
import com.fr.plugin.event.manager.ui.EventManagerDialog; 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.event.manager.utils.KeySetUtils;
import com.fr.plugin.transform.ExecuteFunctionRecord; import com.fr.plugin.transform.ExecuteFunctionRecord;
import com.fr.plugin.transform.FunctionRecorder; import com.fr.plugin.transform.FunctionRecorder;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import java.awt.Dimension;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/** /**
* @author Joe * @author Joe
@ -41,12 +49,22 @@ public abstract class EventManager extends JTemplateAction<JTemplate<?, ?>> {
} }
final Object target = jt.getTarget(); final Object target = jt.getTarget();
BasicPane eventManagerPane = initEventManager(target); final EventManagerPane eventManagerPane = initEventManager(target);
UIDialog dialog = new EventManagerDialog(DesignerContext.getDesignerFrame(), eventManagerPane);
UIDialog dlg = new EventManagerDialog(DesignerContext.getDesignerFrame(), eventManagerPane);
dlg.setVisible(true);
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
eventManagerPane.update();
// 刷新一下右侧面板,避免事件显示不同步
WidgetPropertyPane.getInstance().refreshDockingView();
// 触发正在编辑的模板改变事件
DesignModelAdapter.getCurrentModelAdapter().fireTargetModified();
super.windowClosed(e);
}
});
dialog.setVisible(true);
} }
protected abstract BasicPane initEventManager(Object target); protected abstract EventManagerPane initEventManager(Object target);
} }

4
src/main/java/com/fr/plugin/event/manager/core/FormEventManager.java

@ -3,6 +3,7 @@ package com.fr.plugin.event.manager.core;
import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.BasicPane;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
import com.fr.form.main.Form; import com.fr.form.main.Form;
import com.fr.plugin.event.manager.ui.EventManagerPane;
import com.fr.plugin.event.manager.ui.FormEventManagerPane; import com.fr.plugin.event.manager.ui.FormEventManagerPane;
@ -21,8 +22,7 @@ public class FormEventManager extends EventManager {
* @return * @return
*/ */
@Override @Override
protected BasicPane initEventManager(Object target) { protected EventManagerPane initEventManager(Object target) {
// todo 控件对象整理
FormEventManagerPane eventManagerPane = new FormEventManagerPane(); FormEventManagerPane eventManagerPane = new FormEventManagerPane();
if (target instanceof Form) { if (target instanceof Form) {
eventManagerPane.setTarget((Form) target); eventManagerPane.setTarget((Form) target);

4
src/main/java/com/fr/plugin/event/manager/core/WorkbookEventManager.java

@ -1,8 +1,8 @@
package com.fr.plugin.event.manager.core; package com.fr.plugin.event.manager.core;
import com.fr.design.dialog.BasicPane;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
import com.fr.main.TemplateWorkBook; import com.fr.main.TemplateWorkBook;
import com.fr.plugin.event.manager.ui.EventManagerPane;
import com.fr.plugin.event.manager.ui.WorkbookEventManagerPane; import com.fr.plugin.event.manager.ui.WorkbookEventManagerPane;
@ -23,7 +23,7 @@ public class WorkbookEventManager extends EventManager {
* @return * @return
*/ */
@Override @Override
protected BasicPane initEventManager(Object target) { protected EventManagerPane initEventManager(Object target) {
WorkbookEventManagerPane eventManagerPane = new WorkbookEventManagerPane(); WorkbookEventManagerPane eventManagerPane = new WorkbookEventManagerPane();
if (target instanceof TemplateWorkBook) { if (target instanceof TemplateWorkBook) {
eventManagerPane.setTarget((TemplateWorkBook) target); eventManagerPane.setTarget((TemplateWorkBook) target);

52
src/main/java/com/fr/plugin/event/manager/data/MyCellWidget.java

@ -0,0 +1,52 @@
package com.fr.plugin.event.manager.data;
import com.fr.form.ui.Widget;
import com.fr.report.cell.CellElement;
import javax.swing.Icon;
/**
* @author Joe
* Created by Joe on 12/13/2020
*/
public class MyCellWidget extends MyWidget {
private CellElement cellElement;
private Widget widget;
// 来自普通还是条件属性
private WidgetSource source;
public MyCellWidget(CellElement cellElement, Widget widget) {
this(cellElement, widget, WidgetSource.NORMAL);
}
public MyCellWidget(CellElement cellElement, Widget widget, WidgetSource source) {
super(widget);
this.cellElement = cellElement;
this.source = source;
}
public Widget getWidget() {
return widget;
}
public void setWidget(Widget widget) {
this.widget = widget;
}
public WidgetSource getSource() {
return source;
}
public void setSource(WidgetSource source) {
this.source = source;
}
@Override
public String getNodeName() {
if (source == WidgetSource.NORMAL) {
return cellElement.getRow() + " - " + cellElement.getColumn();
} else {
return cellElement.getRow() + " - " + cellElement.getColumn() + "Cond";
}
}
}

37
src/main/java/com/fr/plugin/event/manager/data/MyContainer.java

@ -1,37 +0,0 @@
package com.fr.plugin.event.manager.data;
import java.util.ArrayList;
import java.util.List;
/**
* @author Joe
* Created by Joe on 12/11/2020
*/
public class MyContainer {
private String blockName;
private List<MyWidget> widgets;
public MyContainer() {
widgets = new ArrayList<>();
}
public String getBlockName() {
return blockName;
}
public void setBlockName(String blockName) {
this.blockName = blockName;
}
public void addWidget(MyWidget widget) {
this.widgets.add(widget);
}
public void setWidgets(List<MyWidget> widgets) {
this.widgets = widgets;
}
public List<MyWidget> getWidgets() {
return this.widgets;
}
}

26
src/main/java/com/fr/plugin/event/manager/data/MyNode.java

@ -1,11 +1,31 @@
package com.fr.plugin.event.manager.data; package com.fr.plugin.event.manager.data;
import javax.swing.Icon;
/** /**
* @author Joe * @author Joe
* Created by Joe on 12/14/2020 * Created by Joe on 12/14/2020
*/ */
public interface MyNode { public class MyNode {
String getNodeName(); protected String nodeName;
public MyNode() {
}
public MyNode(String nodeName) {
this.nodeName = nodeName;
}
public String getNodeName() {
return nodeName;
}
public void setNodeName(String nodeName) {
this.nodeName = nodeName;
}
String getIconPath(); public Icon getIcon() {
return null;
}
} }

28
src/main/java/com/fr/plugin/event/manager/data/MySheet.java

@ -1,28 +0,0 @@
package com.fr.plugin.event.manager.data;
import java.util.ArrayList;
import java.util.List;
/**
* @author Joe
* Created by Joe on 12/11/2020
*/
public class MySheet {
private List<MyContainer> containers;
public MySheet() {
containers = new ArrayList<>();
}
public void addContainer(MyContainer container) {
this.containers.add(container);
}
public void setContainers(List<MyContainer> containers) {
this.containers = containers;
}
public List<MyContainer> getContainers() {
return containers;
}
}

137
src/main/java/com/fr/plugin/event/manager/data/MyTree.java

@ -0,0 +1,137 @@
package com.fr.plugin.event.manager.data;
import java.util.LinkedList;
import java.util.List;
/**
* @author Joe
* Created by Joe on 12/14/2020
*/
public class MyTree {
/**
* 树节点
*/
private MyNode data;
/**
* 父节点根没有父节点
*/
private MyTree parent;
/**
* 子节点叶子节点没有子节点
*/
private List<MyTree> children;
/**
* 保存了当前节点及其所有子节点方便查询
*/
private List<MyTree> elementsIndex;
private boolean visible;
/**
* 构造函数
*
* @param data
*/
public MyTree(MyNode data) {
this.data = data;
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 List<MyTree> getChildren() {
return children;
}
public List<MyTree> getElementsIndex() {
return elementsIndex;
}
/**
* 判断是否为根根没有父节点
*
* @return
*/
public boolean isRoot() {
return parent == null;
}
/**
* 判断是否为叶子节点子节点没有子节点
*
* @return
*/
public boolean isLeaf() {
return children.size() == 0;
}
/**
* 添加一个子节点
*
* @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;
}
public void removeChild(MyTree child) {
// 如果是根的话,就保留
if (child.parent != null) {
child.parent.children.remove(child);
child.parent = null;
}
}
/**
* 递归为当前节点以及当前节点的所有父节点增加新的节点
*
* @param node
*/
private void registerChildForSearch(MyTree node) {
elementsIndex.add(node);
if (parent != null) {
parent.registerChildForSearch(node);
}
}
public MyTree findChild(int index) {
return children.get(index);
}
public int getChildrenSize() {
return children.size();
}
public int getIndexOfChild(Object child) {
int count = getChildrenSize();
for (int i = 0; i < count; i++) {
MyTree comp = findChild(i);
if (comp == child) {
return i;
}
}
return -1;
}
}

27
src/main/java/com/fr/plugin/event/manager/data/MyWidget.java

@ -1,23 +1,21 @@
package com.fr.plugin.event.manager.data; package com.fr.plugin.event.manager.data;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XCreatorUtils;
import com.fr.form.ui.Widget; import com.fr.form.ui.Widget;
import javax.swing.Icon;
/** /**
* @author Joe * @author Joe
* Created by Joe on 12/13/2020 * Created by Joe on 12/14/2020
*/ */
public class MyWidget { public class MyWidget extends MyNode {
private Widget widget; protected Widget widget;
// 来自普通还是条件属性
private WidgetSource source;
public MyWidget(Widget widget) { public MyWidget(Widget widget) {
this(widget, WidgetSource.NORMAL);
}
public MyWidget(Widget widget, WidgetSource source) {
this.widget = widget; this.widget = widget;
this.source = source; this.nodeName = widget.getWidgetName();
} }
public Widget getWidget() { public Widget getWidget() {
@ -28,11 +26,8 @@ public class MyWidget {
this.widget = widget; this.widget = widget;
} }
public WidgetSource getSource() { public Icon getIcon() {
return source; XCreator creator = XCreatorUtils.createXCreator(widget);
} return XCreatorUtils.getCreatorIcon(creator);
public void setSource(WidgetSource source) {
this.source = source;
} }
} }

13
src/main/java/com/fr/plugin/event/manager/ui/CellWidgetPane.java

@ -1,12 +1,21 @@
package com.fr.plugin.event.manager.ui; package com.fr.plugin.event.manager.ui;
import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.BasicPane;
import com.fr.plugin.event.manager.data.MyTree;
import java.util.List;
/** /**
* @author Joe * @author Joe
* Created by Joe on 12/13/2020 * Created by Joe on 12/13/2020
*/ */
public class CellWidgetPane extends BasicPane { public class CellWidgetPane extends BasicPane {
private List<MyTree> cellWidgetTrees;
public CellWidgetPane(List<MyTree> cellWidgetTrees) {
this.cellWidgetTrees = cellWidgetTrees;
}
public String tabTitle() { public String tabTitle() {
return "Cell Widget"; return "Cell Widget";
} }
@ -15,4 +24,8 @@ public class CellWidgetPane extends BasicPane {
protected String title4PopupWindow() { protected String title4PopupWindow() {
return "cell widget"; return "cell widget";
} }
public void update() {
}
} }

141
src/main/java/com/fr/plugin/event/manager/ui/EventConfigPane.java

@ -6,41 +6,70 @@ import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.design.widget.FRWidgetFactory; import com.fr.design.widget.FRWidgetFactory;
import com.fr.plugin.event.manager.data.MyContainer; import com.fr.design.widget.WidgetEventPane;
import com.fr.plugin.event.manager.ui.tree.ContainerRootTree; import com.fr.design.widget.WidgetEventPaneNoPop;
import com.fr.form.event.Listener;
import com.fr.form.ui.Widget;
import com.fr.plugin.event.manager.data.MyTree;
import com.fr.plugin.event.manager.data.MyWidget;
import com.fr.plugin.event.manager.ui.tree.MyComponentTree;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JSplitPane; import javax.swing.JSplitPane;
import javax.swing.SwingConstants;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.CardLayout; import java.awt.Component;
import java.util.ArrayList;
import java.util.List;
/** /**
* 事件配置面板左边为组件树右边为无/事件编辑面板
* @author Joe * @author Joe
* Created by Joe on 12/11/2020 * Created by Joe on 12/11/2020
*/ */
public class EventConfigPane extends BasicPane { public class EventConfigPane extends BasicPane implements TreeSelectionListener {
private CardLayout cardLayout; private MyTree tree;
private JPanel cardPane; private MyTree lastNode;
private List<MyContainer> containers; private boolean rootVisible;
public EventConfigPane() { //事件属性容器
containers = new ArrayList<>(); private JPanel rightPane;
private WidgetEventPane eventPane;
private UILabel emptyLabel;
public EventConfigPane(MyTree tree) {
this(tree, false);
}
public EventConfigPane(MyTree tree, boolean rootVisible) {
this.tree = tree;
this.rootVisible = rootVisible;
this.initComponentPane(); this.initComponentPane();
} }
public void addContainer(MyContainer container) { public MyTree getTree() {
containers.add(container); return tree;
}
public void setTree(MyTree tree) {
this.tree = tree;
}
public boolean isRootVisible() {
return rootVisible;
}
public void setRootVisible(boolean rootVisible) {
this.rootVisible = rootVisible;
} }
private void initComponentPane() { private void initComponentPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setLayout(FRGUIPaneFactory.createBorderLayout());
initCardPane(); initRightPane();
// SplitPane // SplitPane
// 增加边框 // 增加边框
JSplitPane mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, getLeftPane(), cardPane); JSplitPane mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, getLeftPane(), rightPane);
mainSplitPane.setBorder(BorderFactory.createLineBorder(GUICoreUtils.getTitleLineBorderColor())); mainSplitPane.setBorder(BorderFactory.createLineBorder(GUICoreUtils.getTitleLineBorderColor()));
mainSplitPane.setOneTouchExpandable(true); mainSplitPane.setOneTouchExpandable(true);
@ -49,14 +78,20 @@ public class EventConfigPane extends BasicPane {
mainSplitPane.setDividerLocation(230); mainSplitPane.setDividerLocation(230);
} }
private void initCardPane() { private void initRightPane() {
// p: edit card layout rightPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
this.cardLayout = new CardLayout(); rightPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
cardPane = FRGUIPaneFactory.createCardLayout_S_Pane(); eventPane = new WidgetEventPaneNoPop(null);
cardPane.setLayout(this.cardLayout); emptyLabel = new UILabel("当前组件没有设置过事件");
// p:选择的Label emptyLabel.setHorizontalAlignment(SwingConstants.CENTER);
UILabel selectLabel = new UILabel(); rightPane.add(emptyLabel, BorderLayout.CENTER);
cardPane.add(selectLabel); }
private void refreshRightPane(Component component) {
rightPane.removeAll();
rightPane.repaint();
rightPane.add(component, BorderLayout.CENTER);
rightPane.revalidate();
} }
private JPanel getLeftPane() { private JPanel getLeftPane() {
@ -73,9 +108,10 @@ public class EventConfigPane extends BasicPane {
} }
private void initLeftContentPane(JPanel leftContentPane) { private void initLeftContentPane(JPanel leftContentPane) {
ContainerRootTree tree = new ContainerRootTree(); MyComponentTree componentTree = new MyComponentTree(tree, EventConfigPane.this, rootVisible);
UIScrollPane scrollPane = new UIScrollPane(componentTree);
// 把树添加到滚动框中 // 把树添加到滚动框中
leftContentPane.add(new UIScrollPane(), BorderLayout.CENTER); leftContentPane.add(scrollPane, BorderLayout.CENTER);
} }
private JPanel getLeftTopPane() { private JPanel getLeftTopPane() {
@ -90,4 +126,59 @@ public class EventConfigPane extends BasicPane {
} }
/**
* 树节点的点击响应事件
*
* @param e
*/
@Override
public void valueChanged(TreeSelectionEvent e) {
// 先更新下事件
update();
MyComponentTree componentTree = (MyComponentTree) e.getSource();
MyTree tree = (MyTree) componentTree.getLastSelectedPathComponent();
lastNode = tree;
if (hasEvent(tree)) {
Widget widget = ((MyWidget) tree.getData()).getWidget();
refreshRightPane(eventPane);
populate(widget);
return;
}
refreshRightPane(emptyLabel);
}
/**
* 判断节点是否是一个含有事件的控件
*
* @param tree
* @return
*/
private boolean hasEvent(MyTree tree) {
if (tree != null && tree.getData() instanceof MyWidget) {
MyWidget myWidget = (MyWidget) tree.getData();
if (myWidget != null) {
Widget widget = myWidget.getWidget();
return widget != null && widget.getListenerSize() > 0;
}
}
return false;
}
public void populate(Widget widget) {
eventPane.populate(widget);
}
public void update() {
if (hasEvent(lastNode)) {
Widget lastNodeWidget = ((MyWidget) lastNode.getData()).getWidget();
Listener[] listener = eventPane.updateListeners();
lastNodeWidget.clearListeners();
for (Listener l : listener) {
lastNodeWidget.addListener(l);
}
}
// 退出窗口时清空lastNode
lastNode = null;
}
} }

4
src/main/java/com/fr/plugin/event/manager/ui/EventManagerPane.java

@ -28,4 +28,8 @@ public abstract class EventManagerPane<T> extends LoadingBasicPane {
protected abstract void initData(T target); protected abstract void initData(T target);
public void update() {
eventConfigPane.update();
}
} }

62
src/main/java/com/fr/plugin/event/manager/ui/FormEventManagerPane.java

@ -2,6 +2,13 @@ package com.fr.plugin.event.manager.ui;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.form.main.Form; 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.plugin.event.manager.data.MyNode;
import com.fr.plugin.event.manager.data.MyTree;
import com.fr.plugin.event.manager.data.MyWidget;
import javax.swing.JPanel; import javax.swing.JPanel;
import java.awt.BorderLayout; import java.awt.BorderLayout;
@ -11,19 +18,24 @@ import java.awt.BorderLayout;
* Created by Joe on 12/11/2020 * Created by Joe on 12/11/2020
*/ */
public class FormEventManagerPane extends EventManagerPane<Form> { public class FormEventManagerPane extends EventManagerPane<Form> {
private MyTree tree;
@Override @Override
protected void initComponents(JPanel container) { protected void initComponents(JPanel container) {
super.initComponents(container); super.initComponents(container);
container.setLayout(FRGUIPaneFactory.createBorderLayout()); container.setLayout(FRGUIPaneFactory.createBorderLayout());
eventConfigPane = new EventConfigPane(tree);
eventConfigPane = new EventConfigPane();
container.add(eventConfigPane, BorderLayout.CENTER); container.add(eventConfigPane, BorderLayout.CENTER);
} }
@Override @Override
public void initData(Form target) { public void initData(Form target) {
WLayout rootContainer = target.getContainer();
MyNode root = new MyWidget(rootContainer);
tree = new MyTree(root);
traversalWidget(rootContainer, tree);
filterWidget(tree);
} }
/** /**
@ -34,4 +46,48 @@ public class FormEventManagerPane extends EventManagerPane<Form> {
// do nothing // do nothing
} }
/**
* 关键算法遍历添加节点进树
*
* @param widget
* @param tree
*/
private void traversalWidget(Widget widget, MyTree tree) {
if (widget instanceof WAbsoluteLayout.BoundsWidget) {
traversalWidget(((WAbsoluteLayout.BoundsWidget) widget).getWidget(), tree);
} else if (widget instanceof WLayout) {
MyNode node = new MyWidget(widget);
MyTree subTree = tree.addChild(node);
if (widget instanceof WCardLayout) {
int idx = ((WCardLayout) widget).getShowIndex();
if (((WCardLayout) widget).getWidgetCount() > idx) {
traversalWidget(((WCardLayout) widget).getWidget(idx), subTree);
}
} else {
for (int i = 0, count = ((WLayout) widget).getWidgetCount(); i < count; i++) {
traversalWidget(((WLayout) widget).getWidget(i), subTree);
}
}
} else {
// 普通widget
tree.addChild(new MyWidget(widget));
}
}
/**
* 从底向上如果节点的控件没有事件就把它删除
*
* @param tree
*/
private void filterWidget(MyTree tree) {
for (int i = tree.getElementsIndex().size() - 1; i >= 0; i--) {
MyTree tempTree = tree.getElementsIndex().get(i);
if (tempTree.isLeaf() && tempTree.getData() instanceof MyWidget) {
if (((MyWidget) tempTree.getData()).getWidget().getListenerSize() <= 0) {
tree.removeChild(tempTree);
}
}
}
}
} }

91
src/main/java/com/fr/plugin/event/manager/ui/WorkbookEventManagerPane.java

@ -1,15 +1,14 @@
package com.fr.plugin.event.manager.ui; package com.fr.plugin.event.manager.ui;
import com.fr.base.parameter.ParameterUI;
import com.fr.design.gui.frpane.UITabbedPane; import com.fr.design.gui.frpane.UITabbedPane;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.form.main.parameter.FormParameterUI;
import com.fr.form.ui.Widget; import com.fr.form.ui.Widget;
import com.fr.main.TemplateWorkBook; import com.fr.main.TemplateWorkBook;
import com.fr.main.parameter.ReportParameterAttr; import com.fr.main.parameter.ReportParameterAttr;
import com.fr.plugin.event.manager.data.MyContainer; import com.fr.plugin.event.manager.data.MyNode;
import com.fr.plugin.event.manager.data.MySheet; import com.fr.plugin.event.manager.data.MyTree;
import com.fr.plugin.event.manager.data.MyWidget; import com.fr.plugin.event.manager.data.MyWidget;
import com.fr.plugin.event.manager.data.WidgetSource;
import com.fr.report.cell.CellElement; import com.fr.report.cell.CellElement;
import com.fr.report.cell.TemplateCellElement; import com.fr.report.cell.TemplateCellElement;
import com.fr.report.cell.cellattr.highlight.DefaultHighlight; import com.fr.report.cell.cellattr.highlight.DefaultHighlight;
@ -19,7 +18,11 @@ import com.fr.report.poly.PolyECBlock;
import com.fr.report.report.Report; import com.fr.report.report.Report;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Component;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -29,17 +32,19 @@ import java.util.List;
* Created by Joe on 12/11/2020 * Created by Joe on 12/11/2020
*/ */
public class WorkbookEventManagerPane extends EventManagerPane<TemplateWorkBook> { public class WorkbookEventManagerPane extends EventManagerPane<TemplateWorkBook> {
private MyTree parameterTree;
private List<MyTree> cellWidgetTrees;
private MyContainer parameterContainer; private UITabbedPane tabbedPane;
private List<MySheet> sheets = new ArrayList<>(); private CellWidgetPane cellWidgetPane;
@Override @Override
protected void initComponents(JPanel container) { protected void initComponents(JPanel container) {
super.initComponents(container); super.initComponents(container);
UITabbedPane tabbedPane = new UITabbedPane(); tabbedPane = new UITabbedPane();
CellWidgetPane cellWidgetPane = new CellWidgetPane(); cellWidgetPane = new CellWidgetPane(cellWidgetTrees);
EventConfigPane eventConfigPane = new EventConfigPane(); eventConfigPane = new EventConfigPane(parameterTree, true);
eventConfigPane.addContainer(parameterContainer); initListener();
tabbedPane.addTab(cellWidgetPane.tabTitle(), cellWidgetPane); tabbedPane.addTab(cellWidgetPane.tabTitle(), cellWidgetPane);
tabbedPane.addTab("Parameter Widget", eventConfigPane); tabbedPane.addTab("Parameter Widget", eventConfigPane);
@ -47,10 +52,28 @@ public class WorkbookEventManagerPane extends EventManagerPane<TemplateWorkBook>
container.add(tabbedPane, BorderLayout.CENTER); container.add(tabbedPane, BorderLayout.CENTER);
} }
private void initListener() {
tabbedPane.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
// todo 切换tab时需要保存之前配置
JTabbedPane pane = (JTabbedPane) e.getSource();
int selectedIndex = pane.getSelectedIndex();
if (selectedIndex == 0) {
// 从para到cell
eventConfigPane.update();
} else {
// 从cell到para
cellWidgetPane.update();
}
}
});
}
@Override @Override
public void initData(TemplateWorkBook target) { public void initData(TemplateWorkBook target) {
initParaWidget(target); initParaWidget(target);
initReportWidget(target); initCellWidget(target);
} }
private void initParaWidget(TemplateWorkBook workBook) { private void initParaWidget(TemplateWorkBook workBook) {
@ -58,33 +81,39 @@ public class WorkbookEventManagerPane extends EventManagerPane<TemplateWorkBook>
ReportParameterAttr reportParameterAttr = workBook.getReportParameterAttr(); ReportParameterAttr reportParameterAttr = workBook.getReportParameterAttr();
// 获取参数面板对象 // 获取参数面板对象
if (reportParameterAttr != null) { if (reportParameterAttr != null) {
ParameterUI parameterUI = reportParameterAttr.getParameterUI(); FormParameterUI parameterUI = (FormParameterUI) reportParameterAttr.getParameterUI();
if (parameterUI != null) { if (parameterUI != null) {
parameterContainer = new MyContainer(); MyNode root = new MyWidget(parameterUI.getParaContainer());
parameterTree = new MyTree(root);
// 获取参数面板所有控件 // 获取参数面板所有控件
Widget[] widgets = parameterUI.getAllWidgets(); Widget[] widgets = parameterUI.getAllWidgets();
for (Widget widget : widgets) { for (int i = 1; i < widgets.length; i++) {
if (widget.getListenerSize() > 0) { if (widgets[i].getListenerSize() > 0) {
// 控件有事件 // 控件有事件
parameterContainer.addWidget(new MyWidget(widget)); parameterTree.addChild(new MyWidget(widgets[i]));
} }
} }
} }
} }
} }
private void initReportWidget(TemplateWorkBook workBook) { private void initCellWidget(TemplateWorkBook workBook) {
cellWidgetTrees = new ArrayList<>();
// 获取单元格控件 // 获取单元格控件
for (int i = 0; i < workBook.getReportCount(); i++) { for (int i = 0; i < workBook.getReportCount(); i++) {
// 通过模板对象,获取报表页对象 // 通过模板对象,获取报表页对象
Report report = workBook.getReport(i); Report report = workBook.getReport(i);
if (report != null) { if (report != null) {
MySheet sheet = new MySheet(); // 新建树,根节点为 MySheet
MyNode root = new MyNode(workBook.getReportName(i));
MyTree tempSheetTree = new MyTree(root);
boolean hasWidgetEvent = false;
Iterator it = report.iteratorOfElementCase(); Iterator it = report.iteratorOfElementCase();
while (it.hasNext()) { while (it.hasNext()) {
// 通过迭代器,获取格子报表页对象 // 通过迭代器,获取格子报表页对象
MyContainer container = new MyContainer();
ElementCase elementCase = (ElementCase) it.next(); ElementCase elementCase = (ElementCase) it.next();
MyNode block = new MyNode();
MyTree tempBlockTree = new MyTree(block);
Iterator cellIterator = elementCase.cellIterator(); Iterator cellIterator = elementCase.cellIterator();
while (cellIterator.hasNext()) { while (cellIterator.hasNext()) {
// 通过迭代器,获取单元格对象 // 通过迭代器,获取单元格对象
@ -95,7 +124,8 @@ public class WorkbookEventManagerPane extends EventManagerPane<TemplateWorkBook>
Widget widget0 = ((TemplateCellElement) cell).getWidget(); Widget widget0 = ((TemplateCellElement) cell).getWidget();
if (widget0.getListenerSize() > 0) { if (widget0.getListenerSize() > 0) {
// 控件有事件 // 控件有事件
container.addWidget(new MyWidget(widget0)); tempBlockTree.addChild(new MyWidget(widget0));
hasWidgetEvent = true;
} }
} }
// 获取条件属性控件 // 获取条件属性控件
@ -106,23 +136,26 @@ public class WorkbookEventManagerPane extends EventManagerPane<TemplateWorkBook>
for (int k = 0; k < highlight.actionCount(); k++) { for (int k = 0; k < highlight.actionCount(); k++) {
if (highlight.getHighlightAction(k) instanceof WidgetHighlightAction) { if (highlight.getHighlightAction(k) instanceof WidgetHighlightAction) {
WidgetHighlightAction highlightAction = (WidgetHighlightAction) highlight.getHighlightAction(k); WidgetHighlightAction highlightAction = (WidgetHighlightAction) highlight.getHighlightAction(k);
container.addWidget(new MyWidget(highlightAction.getWidget(), WidgetSource.HIGHLIGHT)); tempBlockTree.addChild(new MyWidget(highlightAction.getWidget()));
hasWidgetEvent = true;
} }
} }
} }
} }
} }
} }
if (!container.getWidgets().isEmpty()) { if (hasWidgetEvent) {
// 如果有控件 // 如果有控件
if (elementCase instanceof PolyECBlock) { if (elementCase instanceof PolyECBlock) {
// 如果是聚合报表块 // 如果是聚合报表块,给节点添加名字
container.setBlockName(((PolyECBlock) elementCase).getBlockName()); block.setNodeName(((PolyECBlock) elementCase).getBlockName());
} }
sheet.addContainer(container); tempSheetTree.addChild(block);
} }
} }
sheets.add(sheet); if (hasWidgetEvent) {
cellWidgetTrees.add(tempSheetTree);
}
} }
} }
} }
@ -135,4 +168,10 @@ public class WorkbookEventManagerPane extends EventManagerPane<TemplateWorkBook>
// do nothing // do nothing
} }
@Override
public void update() {
eventConfigPane.update();
cellWidgetPane.update();
}
} }

55
src/main/java/com/fr/plugin/event/manager/ui/tree/MyComponentCellRenderer.java

@ -0,0 +1,55 @@
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;
import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;
import java.awt.Color;
import java.awt.Component;
/**
* @author Joe
* Created by Joe on 12/14/2020
*/
public class MyComponentCellRenderer extends DefaultTreeCellRenderer {
public MyComponentCellRenderer() {
}
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
if (value instanceof MyTree) {
String name = ((MyTree) value).getData().getNodeName();
setText(name);
Icon icon = ((MyTree) value).getData().getIcon();
if (icon != null) {
setIcon(icon);
}
}
this.setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0));
this.setBackgroundNonSelectionColor(new Color(255, 255, 255));
return this;
}
@Override
public Icon getClosedIcon() {
return getIcon();
}
@Override
public Icon getLeafIcon() {
return getIcon();
}
@Override
public Icon getOpenIcon() {
return getIcon();
}
}

31
src/main/java/com/fr/plugin/event/manager/ui/tree/ContainerRootTree.java → src/main/java/com/fr/plugin/event/manager/ui/tree/MyComponentTree.java

@ -1,40 +1,45 @@
package com.fr.plugin.event.manager.ui.tree; package com.fr.plugin.event.manager.ui.tree;
import com.fr.design.constants.UIConstants; import com.fr.design.constants.UIConstants;
import com.fr.design.designer.treeview.ComponentTreeCellRenderer;
import com.fr.design.gui.itree.UITreeUI; import com.fr.design.gui.itree.UITreeUI;
import com.fr.plugin.event.manager.data.MyContainer; import com.fr.plugin.event.manager.data.MyTree;
import com.fr.plugin.event.manager.ui.EventConfigPane;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.JTree; import javax.swing.JTree;
import javax.swing.tree.TreeSelectionModel; import javax.swing.tree.TreeSelectionModel;
import java.awt.Color;
/** /**
* @author Joe * @author Joe
* Created by Joe on 12/14/2020 * Created by Joe on 12/14/2020
*/ */
public class ContainerRootTree extends JTree { public class MyComponentTree extends JTree {
private MyContainer container; private EventConfigPane configPane;
private ContainerTreeModel model; private MyComponentTreeModel model;
private UITreeUI uiTreeUI = new UITreeUI(); private UITreeUI uiTreeUI = new UITreeUI();
private static final int PADDING_LEFT = 5; private static final int PADDING_LEFT = 5;
private static final int PADDING_TOP = 5; private static final int PADDING_TOP = 5;
public ContainerRootTree(MyContainer container) { public MyComponentTree(MyTree tree, EventConfigPane configPane, boolean rootVisible) {
this.container = container; this.configPane = configPane;
model = new ContainerTreeModel(container); model = new MyComponentTreeModel(tree);
setModel(model); setModel(model);
this.setBackground(UIConstants.TREE_BACKGROUND); this.setBackground(new Color(255, 255, 255));
// 根不可见 // 根的可见性
setRootVisible(false); setRootVisible(rootVisible);
setCellRenderer(new ComponentTreeCellRenderer()); setCellRenderer(new MyComponentCellRenderer());
getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
this.setDragEnabled(false); this.setDragEnabled(false);
// initListeners(); initListener();
setEditable(false); setEditable(false);
setUI(uiTreeUI); setUI(uiTreeUI);
setBorder(BorderFactory.createEmptyBorder(PADDING_TOP, PADDING_LEFT, 0, 0)); setBorder(BorderFactory.createEmptyBorder(PADDING_TOP, PADDING_LEFT, 0, 0));
} }
private void initListener() {
this.addTreeSelectionListener(configPane);
}
} }

22
src/main/java/com/fr/plugin/event/manager/ui/tree/ContainerTreeModel.java → src/main/java/com/fr/plugin/event/manager/ui/tree/MyComponentTreeModel.java

@ -1,6 +1,6 @@
package com.fr.plugin.event.manager.ui.tree; package com.fr.plugin.event.manager.ui.tree;
import com.fr.plugin.event.manager.data.MyContainer; import com.fr.plugin.event.manager.data.MyTree;
import javax.swing.event.TreeModelListener; import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel; import javax.swing.tree.TreeModel;
@ -10,11 +10,11 @@ import javax.swing.tree.TreePath;
* @author Joe * @author Joe
* Created by Joe on 12/11/2020 * Created by Joe on 12/11/2020
*/ */
public class ContainerTreeModel implements TreeModel { public class MyComponentTreeModel implements TreeModel {
private MyContainer root; private MyTree root;
public ContainerTreeModel(MyContainer root) { public MyComponentTreeModel(MyTree root) {
this.root = root; this.root = root;
} }
@ -25,16 +25,25 @@ public class ContainerTreeModel implements TreeModel {
@Override @Override
public Object getChild(Object parent, int index) { public Object getChild(Object parent, int index) {
if (parent instanceof MyTree) {
return ((MyTree) parent).findChild(index);
}
return null; return null;
} }
@Override @Override
public int getChildCount(Object parent) { public int getChildCount(Object parent) {
if (parent instanceof MyTree) {
return ((MyTree) parent).getChildrenSize();
}
return 0; return 0;
} }
@Override @Override
public boolean isLeaf(Object node) { public boolean isLeaf(Object node) {
if (node instanceof MyTree) {
return ((MyTree) node).isLeaf();
}
return false; return false;
} }
@ -45,7 +54,10 @@ public class ContainerTreeModel implements TreeModel {
@Override @Override
public int getIndexOfChild(Object parent, Object child) { public int getIndexOfChild(Object parent, Object child) {
return 0; if (parent instanceof MyTree) {
return ((MyTree) parent).getIndexOfChild(child);
}
return -1;
} }
@Override @Override

2
src/main/java/com/fr/plugin/event/manager/utils/KeySetUtils.java

@ -1,6 +1,7 @@
package com.fr.plugin.event.manager.utils; package com.fr.plugin.event.manager.utils;
import com.fr.design.menu.MenuKeySet; import com.fr.design.menu.MenuKeySet;
import com.fr.plugin.event.manager.data.MyTree;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
@ -25,4 +26,5 @@ public class KeySetUtils {
return null; return null;
} }
}; };
} }

Loading…
Cancel
Save