|
|
|
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.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;
|
|
|
|
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
import java.awt.BorderLayout;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 决策报表下的事件管理器面板
|
|
|
|
* @author Joe
|
|
|
|
* Created by Joe on 12/11/2020
|
|
|
|
*/
|
|
|
|
public class FormEventManagerPane extends EventManagerPane<Form> {
|
|
|
|
// 组件树
|
|
|
|
private MyTree tree;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 先调用super.initComponents(),执行initData()
|
|
|
|
* 之后tree已经被初始化了
|
|
|
|
*
|
|
|
|
* @param container
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void initComponents(JPanel container) {
|
|
|
|
super.initComponents(container);
|
|
|
|
container.setLayout(FRGUIPaneFactory.createBorderLayout());
|
|
|
|
eventConfigPane = new EventConfigPane(tree);
|
|
|
|
container.add(eventConfigPane, BorderLayout.CENTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void initData(Form target) {
|
|
|
|
WLayout rootContainer = target.getContainer();
|
|
|
|
MyNode root = new MyWidget(rootContainer);
|
|
|
|
tree = new MyTree(root);
|
|
|
|
traversalWidget(rootContainer, tree);
|
|
|
|
filterWidget(tree);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 当initComponents执行完后调用
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void complete() {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 关键算法,遍历添加节点进树
|
|
|
|
*
|
|
|
|
* @param widget
|
|
|
|
* @param tree
|
|
|
|
*/
|
|
|
|
private void traversalWidget(Widget widget, MyTree 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);
|
|
|
|
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
|
|
|
|
MyWidget myWidget = new MyWidget(widget);
|
|
|
|
if (widget.getListenerSize() > 0) {
|
|
|
|
myWidget.setHasEvent(true);
|
|
|
|
}
|
|
|
|
tree.addChild(myWidget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 从底向上,如果节点的控件没有事件,就把它删除
|
|
|
|
* 保留有事件的叶子节点 和 它们的父节点
|
|
|
|
*
|
|
|
|
* @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()).isHasEvent()) {
|
|
|
|
tree.removeChild(tempTree);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|