|
|
@ -1,8 +1,10 @@ |
|
|
|
package com.fr.design.data.datapane; |
|
|
|
package com.fr.design.data.datapane; |
|
|
|
|
|
|
|
|
|
|
|
import com.fr.base.BaseUtils; |
|
|
|
import com.fr.base.BaseUtils; |
|
|
|
|
|
|
|
import com.fr.data.impl.storeproc.StoreProcedure; |
|
|
|
import com.fr.design.constants.UIConstants; |
|
|
|
import com.fr.design.constants.UIConstants; |
|
|
|
import com.fr.design.data.datapane.management.search.TableDataTreeSearchManager; |
|
|
|
import com.fr.design.data.datapane.management.search.TableDataTreeSearchManager; |
|
|
|
|
|
|
|
import com.fr.design.data.tabledata.wrapper.AbstractTableDataWrapper; |
|
|
|
import com.fr.design.data.tabledata.wrapper.TableDataWrapper; |
|
|
|
import com.fr.design.data.tabledata.wrapper.TableDataWrapper; |
|
|
|
import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; |
|
|
|
import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; |
|
|
|
import com.fr.design.gui.itree.refreshabletree.UserObjectRefreshJTree; |
|
|
|
import com.fr.design.gui.itree.refreshabletree.UserObjectRefreshJTree; |
|
|
@ -19,7 +21,9 @@ import javax.swing.tree.TreePath; |
|
|
|
import java.awt.Color; |
|
|
|
import java.awt.Color; |
|
|
|
import java.awt.Component; |
|
|
|
import java.awt.Component; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* TableData Tree |
|
|
|
* TableData Tree |
|
|
@ -27,6 +31,10 @@ import java.util.List; |
|
|
|
public class TableDataTree extends UserObjectRefreshJTree<TableDataSourceOP> { |
|
|
|
public class TableDataTree extends UserObjectRefreshJTree<TableDataSourceOP> { |
|
|
|
private static final long serialVersionUID = 1L; |
|
|
|
private static final long serialVersionUID = 1L; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String TABLE_DATA_NODE = "tableData"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String COLUMN_NODE = "column"; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Constructor. |
|
|
|
* Constructor. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -87,6 +95,7 @@ public class TableDataTree extends UserObjectRefreshJTree<TableDataSourceOP> { |
|
|
|
this.tableDataTreeCellRenderer = tableDataTreeCellRenderer; |
|
|
|
this.tableDataTreeCellRenderer = tableDataTreeCellRenderer; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
protected void refreshTreeNode(ExpandMutableTreeNode eTreeNode, String childName) { |
|
|
|
protected void refreshTreeNode(ExpandMutableTreeNode eTreeNode, String childName) { |
|
|
|
if (interceptRefresh(eTreeNode)) { |
|
|
|
if (interceptRefresh(eTreeNode)) { |
|
|
|
return; |
|
|
|
return; |
|
|
@ -178,11 +187,11 @@ public class TableDataTree extends UserObjectRefreshJTree<TableDataSourceOP> { |
|
|
|
ExpandMutableTreeNode[] dsTreeNodes = loadChildTreeNodes(root); |
|
|
|
ExpandMutableTreeNode[] dsTreeNodes = loadChildTreeNodes(root); |
|
|
|
root.removeAllChildren(); |
|
|
|
root.removeAllChildren(); |
|
|
|
for (ExpandMutableTreeNode dsTreeNode : dsTreeNodes) { |
|
|
|
for (ExpandMutableTreeNode dsTreeNode : dsTreeNodes) { |
|
|
|
if (TableDataTreeSearchManager.getInstance().nodeMatches(dsTreeNode)) { |
|
|
|
if (TableDataTreeSearchManager.getInstance().nodeNameMatches(dsTreeNode.getUserObject().toString())) { |
|
|
|
// 加载数据列节点
|
|
|
|
// 加载数据列节点
|
|
|
|
loadAndAddChildTreeChild(dsTreeNode); |
|
|
|
loadAndAddChildTreeChild(dsTreeNode); |
|
|
|
// 处理子节点的展开
|
|
|
|
// 处理子节点的展开
|
|
|
|
TableDataTreeSearchManager.getInstance().dealWithNodeExpand(dsTreeNode); |
|
|
|
dealWithNodeExpand(dsTreeNode); |
|
|
|
// 添加数据集子节点
|
|
|
|
// 添加数据集子节点
|
|
|
|
root.add(dsTreeNode); |
|
|
|
root.add(dsTreeNode); |
|
|
|
} |
|
|
|
} |
|
|
@ -196,7 +205,7 @@ public class TableDataTree extends UserObjectRefreshJTree<TableDataSourceOP> { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private ExpandMutableTreeNode loadAndAddChildTreeChild(ExpandMutableTreeNode treeNode) { |
|
|
|
private ExpandMutableTreeNode loadAndAddChildTreeChild(ExpandMutableTreeNode treeNode) { |
|
|
|
if (TableDataTreeSearchManager.getInstance().isTreeNodeStoreProcedure(treeNode)) { |
|
|
|
if (isTreeNodeStoreProcedure(treeNode)) { |
|
|
|
// 如果是存储过程,则再加载一次其子表节点,这里比较坑的就是存储过程不能使用loadChildTreeNodes
|
|
|
|
// 如果是存储过程,则再加载一次其子表节点,这里比较坑的就是存储过程不能使用loadChildTreeNodes
|
|
|
|
int tableChildCounts = treeNode.getChildCount(); |
|
|
|
int tableChildCounts = treeNode.getChildCount(); |
|
|
|
ExpandMutableTreeNode[] childs = new ExpandMutableTreeNode[tableChildCounts]; |
|
|
|
ExpandMutableTreeNode[] childs = new ExpandMutableTreeNode[tableChildCounts]; |
|
|
@ -215,9 +224,36 @@ public class TableDataTree extends UserObjectRefreshJTree<TableDataSourceOP> { |
|
|
|
return treeNode; |
|
|
|
return treeNode; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 处理节点的展开,如果此节点是存储过程,还会处理其子表节点的展开 |
|
|
|
|
|
|
|
* 只针对数据集节点 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param treeNode |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public ExpandMutableTreeNode dealWithNodeExpand(ExpandMutableTreeNode treeNode) { |
|
|
|
|
|
|
|
String tableDataName = treeNode.getUserObject().toString(); |
|
|
|
|
|
|
|
// 主要还是处理存储过程
|
|
|
|
|
|
|
|
if (isTreeNodeStoreProcedure(treeNode)) { |
|
|
|
|
|
|
|
int childCount = treeNode.getChildCount(); |
|
|
|
|
|
|
|
for (int i = 0; i < childCount; i++) { |
|
|
|
|
|
|
|
ExpandMutableTreeNode child = (ExpandMutableTreeNode) treeNode.getChildAt(i); |
|
|
|
|
|
|
|
String nodeName = tableDataName + "_" + child.getUserObject().toString(); |
|
|
|
|
|
|
|
if (TableDataTreeSearchManager.getInstance().nodeCanExpand(nodeName)) { |
|
|
|
|
|
|
|
child.setExpanded(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (TableDataTreeSearchManager.getInstance().nodeCanExpand(treeNode.getUserObject().toString())) { |
|
|
|
|
|
|
|
treeNode.setExpanded(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return treeNode; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
/* |
|
|
|
* p:获得选中的NameObject = name + tabledata. |
|
|
|
* p:获得选中的NameObject = name + tabledata. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
public NameObject getSelectedNameObject() { |
|
|
|
public NameObject getSelectedNameObject() { |
|
|
|
TreePath selectedTreePath = this.getSelectionPath(); |
|
|
|
TreePath selectedTreePath = this.getSelectionPath(); |
|
|
|
if (selectedTreePath == null) { |
|
|
|
if (selectedTreePath == null) { |
|
|
@ -248,27 +284,47 @@ public class TableDataTree extends UserObjectRefreshJTree<TableDataSourceOP> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获得选中的NameObject的list,只会返回数据集节点的NameObject |
|
|
|
* 获得选中的数据集节点的NameObject的数组,只会返回数据集节点的NameObject |
|
|
|
* 当多选了数据集或数据列时,也只返回选中的数据集 |
|
|
|
* 当多选了数据集或数据列时,也只返回选中的数据集 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public NameObject[] getSelectedNameObjects() { |
|
|
|
public NameObject[] getSelectedTableDataNameObjects() { |
|
|
|
|
|
|
|
Map<String, List<ExpandMutableTreeNode>> tableDataNodesAndColumnNodes = getSelectedTableDataNodesAndColumnNodes(); |
|
|
|
|
|
|
|
List<ExpandMutableTreeNode> tableDataNodes = tableDataNodesAndColumnNodes.get(TABLE_DATA_NODE); |
|
|
|
|
|
|
|
if (tableDataNodes == null) { |
|
|
|
|
|
|
|
return new NameObject[0]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return tableDataNodes.stream().map(node -> (NameObject) node.getUserObject()).toArray(NameObject[]::new); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 获取选中的数据集节点和列名节点 |
|
|
|
|
|
|
|
* 其中存储过程的子表节点不计入数据集节点中,仅存储过程节点本身计入数据集节点 |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private Map<String, List<ExpandMutableTreeNode>> getSelectedTableDataNodesAndColumnNodes() { |
|
|
|
TreePath[] selectedTreePaths = this.getSelectionPaths(); |
|
|
|
TreePath[] selectedTreePaths = this.getSelectionPaths(); |
|
|
|
if (selectedTreePaths == null) { |
|
|
|
if (selectedTreePaths == null) { |
|
|
|
return new NameObject[0]; |
|
|
|
return new HashMap<>(); |
|
|
|
} |
|
|
|
} |
|
|
|
List<NameObject> result = new ArrayList<>(); |
|
|
|
Map<String, List<ExpandMutableTreeNode>> resultMap = new HashMap<>(); |
|
|
|
|
|
|
|
List<ExpandMutableTreeNode> tableDataNodes = new ArrayList<>(); |
|
|
|
|
|
|
|
List<ExpandMutableTreeNode> columnNodes = new ArrayList<>(); |
|
|
|
|
|
|
|
resultMap.put(TABLE_DATA_NODE, tableDataNodes); |
|
|
|
|
|
|
|
resultMap.put(COLUMN_NODE, columnNodes); |
|
|
|
for (TreePath selectedTreePath : selectedTreePaths) { |
|
|
|
for (TreePath selectedTreePath : selectedTreePaths) { |
|
|
|
if (selectedTreePath == null) { |
|
|
|
if (selectedTreePath == null) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
ExpandMutableTreeNode selectedTreeNode = (ExpandMutableTreeNode) selectedTreePath.getLastPathComponent(); |
|
|
|
ExpandMutableTreeNode selectedTreeNode = (ExpandMutableTreeNode) selectedTreePath.getLastPathComponent(); |
|
|
|
Object selectedUserObject = selectedTreeNode.getUserObject(); |
|
|
|
if (isTableDataNodes(selectedTreeNode)) { |
|
|
|
// 只考虑数据集节点
|
|
|
|
// 数据集节点
|
|
|
|
if (selectedUserObject instanceof NameObject && ((NameObject) selectedUserObject).getObject() instanceof TableDataWrapper) { |
|
|
|
tableDataNodes.add(selectedTreeNode); |
|
|
|
result.add((NameObject) selectedUserObject); |
|
|
|
} else { |
|
|
|
|
|
|
|
// 列名节点
|
|
|
|
|
|
|
|
columnNodes.add(selectedTreeNode); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return result.toArray(new NameObject[0]); |
|
|
|
return resultMap; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -276,8 +332,57 @@ public class TableDataTree extends UserObjectRefreshJTree<TableDataSourceOP> { |
|
|
|
* |
|
|
|
* |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public int getSelectedDsCounts() { |
|
|
|
public int getSelectedTableDataCounts() { |
|
|
|
return getSelectedNameObjects().length; |
|
|
|
return getSelectedTableDataNameObjects().length; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 是否存在单独选了数据列节点,但没选其对应数据集的情况 |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public boolean hasSelectedIndependentColumns() { |
|
|
|
|
|
|
|
Map<String, List<ExpandMutableTreeNode>> tableDataNodesAndColumnNodes = getSelectedTableDataNodesAndColumnNodes(); |
|
|
|
|
|
|
|
List<ExpandMutableTreeNode> tableDataNodes = tableDataNodesAndColumnNodes.get(TABLE_DATA_NODE); |
|
|
|
|
|
|
|
List<ExpandMutableTreeNode> columnNodes = tableDataNodesAndColumnNodes.get(COLUMN_NODE); |
|
|
|
|
|
|
|
if (columnNodes == null || columnNodes.size() == 0) { |
|
|
|
|
|
|
|
// 未选中数据列
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (tableDataNodes == null || tableDataNodes.size() == 0) { |
|
|
|
|
|
|
|
// 选中数据列而未选中数据集
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
boolean result = false; |
|
|
|
|
|
|
|
for (ExpandMutableTreeNode columnNode : columnNodes) { |
|
|
|
|
|
|
|
ExpandMutableTreeNode tableDataNode = getBelongedTableDataNodes(columnNode); |
|
|
|
|
|
|
|
if (!tableDataNodes.contains(tableDataNode)) { |
|
|
|
|
|
|
|
result = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 获取一个节点归属的数据集层级父节点 |
|
|
|
|
|
|
|
* @param treeNode |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private ExpandMutableTreeNode getBelongedTableDataNodes(ExpandMutableTreeNode treeNode) { |
|
|
|
|
|
|
|
if (isTableDataNodes(treeNode)) { |
|
|
|
|
|
|
|
return treeNode; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return getBelongedTableDataNodes((ExpandMutableTreeNode) treeNode.getParent()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isTableDataNodes(ExpandMutableTreeNode treeNode) { |
|
|
|
|
|
|
|
if (treeNode == null) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Object userObject = treeNode.getUserObject(); |
|
|
|
|
|
|
|
if (userObject instanceof NameObject && ((NameObject) userObject).getObject() instanceof AbstractTableDataWrapper) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public TableDataWrapper[] getSelectedDatas() { |
|
|
|
public TableDataWrapper[] getSelectedDatas() { |
|
|
@ -345,4 +450,20 @@ public class TableDataTree extends UserObjectRefreshJTree<TableDataSourceOP> { |
|
|
|
|
|
|
|
|
|
|
|
treeModel.reload(root); |
|
|
|
treeModel.reload(root); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 判断此节点是否为存储过程 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param treeNode |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public boolean isTreeNodeStoreProcedure(ExpandMutableTreeNode treeNode) { |
|
|
|
|
|
|
|
Object userObject = treeNode.getUserObject(); |
|
|
|
|
|
|
|
if (userObject instanceof NameObject) { |
|
|
|
|
|
|
|
NameObject nameObject = (NameObject) userObject; |
|
|
|
|
|
|
|
TableDataWrapper tableDataWrapper = (TableDataWrapper) nameObject.getObject(); |
|
|
|
|
|
|
|
return tableDataWrapper.getTableData() instanceof StoreProcedure; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|