|
|
|
package com.fr.plugin.event.manager.ui;
|
|
|
|
|
|
|
|
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.MyNode;
|
|
|
|
import com.fr.plugin.event.manager.data.MyTree;
|
|
|
|
import com.fr.plugin.event.manager.data.MyWidget;
|
|
|
|
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;
|
|
|
|
import com.fr.report.cell.cellattr.highlight.WidgetHighlightAction;
|
|
|
|
import com.fr.report.elementcase.ElementCase;
|
|
|
|
import com.fr.report.poly.PolyECBlock;
|
|
|
|
import com.fr.report.report.Report;
|
|
|
|
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
import javax.swing.JTabbedPane;
|
|
|
|
import javax.swing.event.ChangeEvent;
|
|
|
|
import javax.swing.event.ChangeListener;
|
|
|
|
import java.awt.BorderLayout;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Joe
|
|
|
|
* Created by Joe on 12/11/2020
|
|
|
|
*/
|
|
|
|
public class WorkbookEventManagerPane extends EventManagerPane<TemplateWorkBook> {
|
|
|
|
private MyTree parameterTree;
|
|
|
|
private List<MyTree> cellWidgetTrees;
|
|
|
|
|
|
|
|
private UITabbedPane tabbedPane;
|
|
|
|
private CellWidgetPane cellWidgetPane;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void initComponents(JPanel container) {
|
|
|
|
super.initComponents(container);
|
|
|
|
tabbedPane = new UITabbedPane();
|
|
|
|
cellWidgetPane = new CellWidgetPane(cellWidgetTrees);
|
|
|
|
eventConfigPane = new EventConfigPane(parameterTree, true);
|
|
|
|
initListener();
|
|
|
|
tabbedPane.addTab(cellWidgetPane.tabTitle(), cellWidgetPane);
|
|
|
|
tabbedPane.addTab(com.fr.design.i18n.Toolkit.i18nText("Fine-Plugin_Event_Manager_Tab_Para"), eventConfigPane);
|
|
|
|
|
|
|
|
container.setLayout(FRGUIPaneFactory.createBorderLayout());
|
|
|
|
container.add(tabbedPane, BorderLayout.CENTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 增加tab切换的监听
|
|
|
|
*/
|
|
|
|
private void initListener() {
|
|
|
|
tabbedPane.addChangeListener(new ChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void stateChanged(ChangeEvent e) {
|
|
|
|
JTabbedPane pane = (JTabbedPane) e.getSource();
|
|
|
|
int selectedIndex = pane.getSelectedIndex();
|
|
|
|
if (selectedIndex == 0) {
|
|
|
|
// 从para到cell
|
|
|
|
eventConfigPane.update();
|
|
|
|
cellWidgetPane.refreshUI();
|
|
|
|
} else {
|
|
|
|
// 从cell到para
|
|
|
|
cellWidgetPane.update();
|
|
|
|
eventConfigPane.refreshUI();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void initData(TemplateWorkBook target) {
|
|
|
|
parameterTree = new MyTree();
|
|
|
|
initParaWidget(target);
|
|
|
|
cellWidgetTrees = new ArrayList<>();
|
|
|
|
initCellWidget(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 初始化参数面板组件树
|
|
|
|
*
|
|
|
|
* @param workBook
|
|
|
|
*/
|
|
|
|
private void initParaWidget(TemplateWorkBook workBook) {
|
|
|
|
// 获取模板的参数属性对象
|
|
|
|
ReportParameterAttr reportParameterAttr = workBook.getReportParameterAttr();
|
|
|
|
// 获取参数面板对象
|
|
|
|
if (reportParameterAttr != null) {
|
|
|
|
FormParameterUI parameterUI = (FormParameterUI) reportParameterAttr.getParameterUI();
|
|
|
|
if (parameterUI != null) {
|
|
|
|
Widget para = parameterUI.getParaContainer();
|
|
|
|
// 根节点
|
|
|
|
MyWidget root = new MyWidget(para);
|
|
|
|
if (para.getListenerSize() > 0) {
|
|
|
|
root.setHasEvent(true);
|
|
|
|
}
|
|
|
|
parameterTree.setData(root);
|
|
|
|
// 获取参数面板所有控件
|
|
|
|
Widget[] widgets = parameterUI.getAllWidgets();
|
|
|
|
for (int i = 1; i < widgets.length; i++) {
|
|
|
|
if (widgets[i].getListenerSize() > 0) {
|
|
|
|
// 控件有事件
|
|
|
|
MyWidget paraWidget = new MyWidget(widgets[i]);
|
|
|
|
paraWidget.setHasEvent(true);
|
|
|
|
parameterTree.addChild(paraWidget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 初始化单元格/条件属性控件的树数组
|
|
|
|
* @param workBook
|
|
|
|
*/
|
|
|
|
private void initCellWidget(TemplateWorkBook workBook) {
|
|
|
|
// 获取单元格控件
|
|
|
|
for (int i = 0; i < workBook.getReportCount(); i++) {
|
|
|
|
// 通过模板对象,获取报表页对象
|
|
|
|
Report report = workBook.getReport(i);
|
|
|
|
if (report != null) {
|
|
|
|
// 新建树,根节点为 MySheet
|
|
|
|
MyNode root = new MyNode(workBook.getReportName(i));
|
|
|
|
MyTree tempSheetTree = new MyTree(root);
|
|
|
|
boolean hasWidgetEvent = false;
|
|
|
|
Iterator it = report.iteratorOfElementCase();
|
|
|
|
while (it.hasNext()) {
|
|
|
|
// 通过迭代器,获取格子报表页对象
|
|
|
|
ElementCase elementCase = (ElementCase) it.next();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 如果是普通报表
|
|
|
|
hasWidgetEvent = initTree(tempSheetTree, elementCase);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hasWidgetEvent) {
|
|
|
|
// 把有事件的sheet加入列表中
|
|
|
|
cellWidgetTrees.add(tempSheetTree);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 初始化单棵树,一个报表块对应一棵树
|
|
|
|
* @param tree 树根
|
|
|
|
* @param elementCase 报表块
|
|
|
|
* @return 这棵树是否含带事件的组件
|
|
|
|
*/
|
|
|
|
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) {
|
|
|
|
// 控件有事件
|
|
|
|
MyWidget cellWidget = new MyWidget(widget0);
|
|
|
|
cellWidget.setNodeName(cell.toString());
|
|
|
|
cellWidget.setHasEvent(true);
|
|
|
|
tree.addChild(cellWidget);
|
|
|
|
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);
|
|
|
|
MyWidget highlightWidget = new MyWidget(highlightAction.getWidget());
|
|
|
|
// 条件属性控件的命名不同于单元格控件
|
|
|
|
highlightWidget.setNodeName(cell.toString() + "(" + highlight.getName() + ")");
|
|
|
|
highlightWidget.setHasEvent(true);
|
|
|
|
tree.addChild(highlightWidget);
|
|
|
|
hasWidgetEvent = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hasWidgetEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 当initComponents执行完后调用
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void complete() {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 重写父类,同时更新两个tab的内容
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void update() {
|
|
|
|
eventConfigPane.update();
|
|
|
|
cellWidgetPane.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|