Browse Source

Event manager update stash

master
Joe 4 years ago committed by Joe.Jiang
parent
commit
2080facd57
  1. 2
      plugin.xml
  2. 69
      src/main/java/com/fr/plugin/event/manager/core/EventManager.java
  3. 65
      src/main/java/com/fr/plugin/event/manager/core/FormEventManager.java
  4. 63
      src/main/java/com/fr/plugin/event/manager/core/WorkbookEventManager.java
  5. 1
      src/main/java/com/fr/plugin/event/manager/data/MyCellWidget.java
  6. 7
      src/main/java/com/fr/plugin/event/manager/data/MyNode.java
  7. 27
      src/main/java/com/fr/plugin/event/manager/data/MyTree.java
  8. 7
      src/main/java/com/fr/plugin/event/manager/data/MyWidget.java
  9. 19
      src/main/java/com/fr/plugin/event/manager/ui/CellWidgetPane.java
  10. 4
      src/main/java/com/fr/plugin/event/manager/ui/EventConfigPane.java
  11. 1
      src/main/java/com/fr/plugin/event/manager/ui/EventManagerPane.java
  12. 7
      src/main/java/com/fr/plugin/event/manager/ui/FormEventManagerPane.java
  13. 96
      src/main/java/com/fr/plugin/event/manager/ui/WorkbookEventManagerPane.java
  14. 5
      src/main/java/com/fr/plugin/event/manager/ui/tree/MyComponentCellRenderer.java
  15. 28
      src/main/java/com/fr/plugin/event/manager/ui/tree/MyComponentTree.java

2
plugin.xml

@ -14,5 +14,5 @@
<MenuHandler class="com.fr.plugin.event.manager.provider.EventManagerProvider"/>
</extra-designer>
<function-recorder class="com.fr.plugin.event.manager.core.EventManager"/>
<function-recorder class="com.fr.plugin.event.manager.core.WorkbookEventManager"/>
</plugin>

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

@ -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<JTemplate<?, ?>> {
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);
}

65
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<JForm> {
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;
}
}

63
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;
}

1
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;

7
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;
}
}

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

@ -28,7 +28,9 @@ public class MyTree {
*/
private List<MyTree> 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<MyTree> 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;
}

7
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);
}
}

19
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<MyTree> cellWidgetTrees;
private EventConfigPane eventConfigPane;
public CellWidgetPane(List<MyTree> 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() {

4
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;
}

1
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
*/

7
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<Form> {
container.setLayout(FRGUIPaneFactory.createBorderLayout());
eventConfigPane = new EventConfigPane(tree);
container.add(eventConfigPane, BorderLayout.CENTER);
}
@Override
@ -53,8 +52,8 @@ public class FormEventManagerPane extends EventManagerPane<Form> {
* @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);

96
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<TemplateWorkBook>
@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<TemplateWorkBook>
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<TemplateWorkBook>
}
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<TemplateWorkBook>
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<TemplateWorkBook>
}
}
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执行完后调用
*/

5
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) {

28
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<MyTree> children = node.getChildren();
for (MyTree n : children) {
TreePath newPath = path.pathByAddingChild(n);
expandTree(newPath, --layer);
}
}
this.expandPath(path);
}
}

Loading…
Cancel
Save