phetran_ye
4 years ago
commit
5f356c1266
13 changed files with 1674 additions and 0 deletions
@ -0,0 +1,84 @@ |
|||||||
|
package com.fr.plugins.dsgroup; |
||||||
|
|
||||||
|
import com.fr.base.TableData; |
||||||
|
import com.fr.design.data.datapane.TableDataPaneListPane; |
||||||
|
import com.fr.design.data.tabledata.wrapper.TableDataWrapper; |
||||||
|
import com.fr.file.DatasourceManager; |
||||||
|
import com.fr.file.DatasourceManagerProvider; |
||||||
|
import com.fr.file.TableDataConfig; |
||||||
|
import com.fr.general.NameObject; |
||||||
|
import com.fr.plugins.dsgroup.fun.DSGroupTableData; |
||||||
|
import com.fr.stable.Nameable; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.LinkedHashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by phetran_ye on 2019-03-12. |
||||||
|
*/ |
||||||
|
public class CustomTableDataPaneListPane extends TableDataPaneListPane { |
||||||
|
Map<String,TableData> changedDatas=new HashMap<String, TableData>(); |
||||||
|
//为更改名称
|
||||||
|
public void rename(String oldName, String newName) { |
||||||
|
super.rename(oldName, newName); |
||||||
|
DatasourceManagerProvider datasourceManager = DatasourceManager.getProviderInstance(); |
||||||
|
Iterator iterator=datasourceManager.getTableDataNameIterator(); |
||||||
|
boolean isChanged; |
||||||
|
String separator= DSGroupTableData.getSeparator(); |
||||||
|
String newNameToReplaceWith=separator+newName+separator; |
||||||
|
String oldNameToMatchWith=separator+oldName+separator; |
||||||
|
while(iterator.hasNext()){ |
||||||
|
isChanged=false; |
||||||
|
String name=(String)iterator.next(); |
||||||
|
if(datasourceManager.getTableData(name) instanceof DSGroupTableData){ |
||||||
|
DSGroupTableData tableData=(DSGroupTableData)datasourceManager.getTableData(name); |
||||||
|
String childNodes=tableData.getChildrenDSNames(); |
||||||
|
|
||||||
|
childNodes=separator+childNodes+separator; |
||||||
|
|
||||||
|
if(childNodes.indexOf(oldNameToMatchWith)>-1){ |
||||||
|
childNodes=childNodes.replace(oldNameToMatchWith,newNameToReplaceWith).replaceAll("^"+separator+"{1}","").replaceAll(separator+"${1}",""); |
||||||
|
tableData.setChildrenDSNames(childNodes); |
||||||
|
isChanged=true; |
||||||
|
} |
||||||
|
String parentNode=tableData.getParentDSName(); |
||||||
|
if(parentNode.equals(oldName)){ |
||||||
|
parentNode=newName; |
||||||
|
tableData.setParentDSName(parentNode); |
||||||
|
isChanged=true; |
||||||
|
} |
||||||
|
if(isChanged){ |
||||||
|
changedDatas.put(name,tableData); |
||||||
|
//datasourceManager.removeTableData(name);
|
||||||
|
//datasourceManager.putTableData(name, tableData);
|
||||||
|
/*datasourceManager.getTableDataModifyDetails().put(name, tableData); |
||||||
|
update(datasourceManager);*/ |
||||||
|
//getDsNameChangedMap().put(name,name);
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void update(TableDataConfig dataConfig){ |
||||||
|
LinkedHashMap<String,TableData> tableDatas = new LinkedHashMap(); |
||||||
|
Nameable[] tableDataArray = this.update(); |
||||||
|
for (int i = 0; i < tableDataArray.length; i++) { |
||||||
|
NameObject nameObject = (NameObject) tableDataArray[i]; |
||||||
|
if(changedDatas.containsKey(nameObject.getName())){ |
||||||
|
tableDatas.put(nameObject.getName(),changedDatas.get(nameObject.getName())); |
||||||
|
}else{ |
||||||
|
tableDatas.put(nameObject.getName(), (TableData) nameObject.getObject()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
dataConfig.setTableDatas(tableDatas); |
||||||
|
changedDatas.clear(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,504 @@ |
|||||||
|
package com.fr.plugins.dsgroup; |
||||||
|
|
||||||
|
import com.fr.base.BaseUtils; |
||||||
|
|
||||||
|
import com.fr.base.TableData; |
||||||
|
import com.fr.config.utils.UniqueKey; |
||||||
|
import com.fr.design.actions.server.GlobalTableDataAction; |
||||||
|
|
||||||
|
import com.fr.design.data.DesignTableDataManager; |
||||||
|
import com.fr.design.data.datapane.TableDataSourceOP; |
||||||
|
import com.fr.design.data.datapane.TableDataTree; |
||||||
|
|
||||||
|
import com.fr.design.data.datapane.TableDataTreePane; |
||||||
|
import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper; |
||||||
|
import com.fr.design.gui.itree.refreshabletree.UserObjectOP; |
||||||
|
import com.fr.file.DatasourceManager; |
||||||
|
import com.fr.file.DatasourceManagerProvider; |
||||||
|
import com.fr.file.ProcedureConfig; |
||||||
|
import com.fr.file.TableDataConfig; |
||||||
|
import com.fr.general.NameObject; |
||||||
|
import com.fr.design.constants.UIConstants; |
||||||
|
import com.fr.design.data.tabledata.wrapper.TableDataWrapper; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; |
||||||
|
import com.fr.design.icon.IconPathConstants; |
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.plugins.dsgroup.fun.DSGroupTableData; |
||||||
|
import com.fr.third.apache.log4j.Logger; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import javax.swing.tree.DefaultMutableTreeNode; |
||||||
|
import javax.swing.tree.DefaultTreeCellRenderer; |
||||||
|
import javax.swing.tree.DefaultTreeModel; |
||||||
|
import javax.swing.tree.TreePath; |
||||||
|
import java.awt.*; |
||||||
|
import java.lang.reflect.Field; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.LinkedHashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by phetran_ye on 2018/8/12. |
||||||
|
*/ |
||||||
|
public class CustomTableDataTree extends TableDataTree { |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
private CustomTableDataTreePane pane; |
||||||
|
public void setPane(CustomTableDataTreePane p){ |
||||||
|
this.pane=p; |
||||||
|
} |
||||||
|
/** |
||||||
|
* Constructor. |
||||||
|
*/ |
||||||
|
|
||||||
|
// CellRenderer
|
||||||
|
private DefaultTreeCellRenderer tableDataTreeCellRenderer = new DefaultTreeCellRenderer() { |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
@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); |
||||||
|
ExpandMutableTreeNode treeNode = (ExpandMutableTreeNode) value; |
||||||
|
Object userObj = treeNode.getUserObject(); |
||||||
|
if (userObj instanceof String) { |
||||||
|
// p:这个是column field.
|
||||||
|
this.setIcon(BaseUtils.readIcon("com/fr/design/images/data/field.png")); |
||||||
|
this.setText((String) userObj); |
||||||
|
} else if (userObj instanceof NameObject) { |
||||||
|
NameObject nameObject = (NameObject) userObj; |
||||||
|
this.setText(nameObject.getName()); |
||||||
|
if (nameObject.getObject() instanceof TableDataWrapper) { |
||||||
|
TableDataWrapper tableDataWrappe = (TableDataWrapper) nameObject.getObject(); |
||||||
|
this.setIcon(tableDataWrappe.getIcon()); |
||||||
|
} else if (nameObject.getObject() instanceof Integer) { |
||||||
|
int num = (Integer) nameObject.getObject(); |
||||||
|
if (num == TableDataSourceOP.SERVER_TABLE_DATA) { |
||||||
|
this.setIcon(BaseUtils.readIcon(IconPathConstants.STD_SHOW_ICON_PATH)); |
||||||
|
} else if (num == TableDataSourceOP.STORE_PRECEDURE_DATA) { |
||||||
|
this.setIcon(BaseUtils.readIcon(IconPathConstants.SP_SHOW_ICON_PATH)); |
||||||
|
} else { |
||||||
|
this.setIcon(BaseUtils.readIcon(IconPathConstants.DS_QUERY_ICON_PATH)); |
||||||
|
} |
||||||
|
} else { |
||||||
|
this.setIcon(BaseUtils.readIcon("/com/fr/design/images/data/store_procedure.png")); |
||||||
|
} |
||||||
|
} else if (userObj == PENDING) { |
||||||
|
this.setIcon(null); |
||||||
|
this.setText(PENDING.toString()); |
||||||
|
} |
||||||
|
// 这里新建一个Label作为render是因为JTree在动态刷新的时候,节点上render画布的的宽度不会变,会使得一部分比较长的数据显示为"..."
|
||||||
|
UILabel label = new UILabel(); |
||||||
|
label.setText(getText()); |
||||||
|
label.setIcon(getIcon()); |
||||||
|
Dimension dim = label.getPreferredSize(); |
||||||
|
dim.height += 2; |
||||||
|
this.setSize(dim); |
||||||
|
this.setPreferredSize(dim); |
||||||
|
this.setBackgroundNonSelectionColor(UIConstants.TREE_BACKGROUND); |
||||||
|
this.setTextSelectionColor(Color.WHITE); |
||||||
|
this.setBackgroundSelectionColor(UIConstants.FLESH_BLUE); |
||||||
|
return this; |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
public DefaultTreeCellRenderer getTableDataTreeCellRenderer() { |
||||||
|
return tableDataTreeCellRenderer; |
||||||
|
} |
||||||
|
|
||||||
|
public void setTableDataTreeCellRenderer(DefaultTreeCellRenderer tableDataTreeCellRenderer) { |
||||||
|
this.tableDataTreeCellRenderer = tableDataTreeCellRenderer; |
||||||
|
} |
||||||
|
|
||||||
|
protected void refreshTreeNode(ExpandMutableTreeNode eTreeNode, String childName) { |
||||||
|
if (interceptRefresh(eTreeNode)) { |
||||||
|
return; |
||||||
|
} |
||||||
|
boolean refreshall = childName.isEmpty(); |
||||||
|
ExpandMutableTreeNode[] new_nodes = loadChildTreeNodes(eTreeNode); |
||||||
|
|
||||||
|
java.util.List<DefaultMutableTreeNode> childTreeNodeList = new java.util.ArrayList<DefaultMutableTreeNode>(); |
||||||
|
for (int i = 0, len = eTreeNode.getChildCount(); i < len; i++) { |
||||||
|
if (eTreeNode.getChildAt(i) instanceof ExpandMutableTreeNode) { |
||||||
|
childTreeNodeList.add((ExpandMutableTreeNode) eTreeNode.getChildAt(i)); |
||||||
|
} else { |
||||||
|
childTreeNodeList.add((DefaultMutableTreeNode) eTreeNode.getChildAt(i)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
eTreeNode.removeAllChildren(); |
||||||
|
|
||||||
|
for (int ci = 0; ci < new_nodes.length; ci++) { |
||||||
|
Object cUserObject = new_nodes[ci].getUserObject(); |
||||||
|
ExpandMutableTreeNode cTreeNode = null; |
||||||
|
for (int ni = 0, nlen = childTreeNodeList.size(); ni < nlen; ni++) { |
||||||
|
cTreeNode = (ExpandMutableTreeNode) childTreeNodeList.get(ni); |
||||||
|
if (ComparatorUtils.equals(cTreeNode.getUserObject(), cUserObject)) { |
||||||
|
if (!refreshall && !ComparatorUtils.equals(childName, ((NameObject) cUserObject).getName())) { |
||||||
|
new_nodes[ci] = cTreeNode; |
||||||
|
break; |
||||||
|
} |
||||||
|
new_nodes[ci].setExpanded(cTreeNode.isExpanded()); |
||||||
|
if (cTreeNode.getChildCount()>0 && cTreeNode.getFirstChild() instanceof ExpandMutableTreeNode && cTreeNode.isExpanded()) { |
||||||
|
checkChildNodes(cTreeNode, new_nodes[ci]); |
||||||
|
} |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
//eTreeNode.add(new_nodes[ci]);
|
||||||
|
} |
||||||
|
loadTreeNode(eTreeNode); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
protected void checkChildNodes(ExpandMutableTreeNode oldNode, ExpandMutableTreeNode newNode) { |
||||||
|
for (int i = 0; i < oldNode.getChildCount(); i++) { |
||||||
|
ExpandMutableTreeNode oldChild = (ExpandMutableTreeNode) oldNode.getChildAt(i); |
||||||
|
for (int j = 0; j < newNode.getChildCount(); j++) { |
||||||
|
ExpandMutableTreeNode newChild = (ExpandMutableTreeNode) newNode.getChildAt(j); |
||||||
|
newChild.removeAllChildren(); |
||||||
|
ExpandMutableTreeNode[] nodes = CustomTableDataTree.this.loadChildTreeNodes(newChild); |
||||||
|
for (int k = 0; k < nodes.length; k++) { |
||||||
|
newChild.add(nodes[k]); |
||||||
|
} |
||||||
|
if (newChild.getChildCount() > 1 && ((ExpandMutableTreeNode) newChild.getFirstChild()).getUserObject() == PENDING) { |
||||||
|
newChild.remove(0); |
||||||
|
} |
||||||
|
if (ComparatorUtils.equals(oldChild.getUserObject(), newChild.getUserObject())) { |
||||||
|
newChild.setExpanded(oldChild.isExpanded()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/* |
||||||
|
* p:获得选中的NameObject = name + tabledata. |
||||||
|
*/ |
||||||
|
public NameObject getSelectedNameObject() { |
||||||
|
TreePath selectedTreePath = this.getSelectionPath(); |
||||||
|
if (selectedTreePath == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
ExpandMutableTreeNode selectedTreeNode = (ExpandMutableTreeNode) selectedTreePath.getLastPathComponent(); |
||||||
|
Object selectedUserObject = selectedTreeNode.getUserObject(); |
||||||
|
ExpandMutableTreeNode parentTreeNode = (ExpandMutableTreeNode) selectedTreeNode.getParent(); |
||||||
|
Object parentUserObject = parentTreeNode.getUserObject(); |
||||||
|
if (parentUserObject instanceof NameObject && ((NameObject) parentUserObject).getObject() instanceof Integer) { |
||||||
|
if (selectedUserObject instanceof NameObject) { |
||||||
|
return (NameObject) selectedUserObject; |
||||||
|
} |
||||||
|
} else { |
||||||
|
parentTreeNode = (ExpandMutableTreeNode) selectedTreeNode.getParent(); |
||||||
|
parentUserObject = parentTreeNode.getUserObject(); |
||||||
|
|
||||||
|
if (parentUserObject != null) { |
||||||
|
if (!(parentUserObject instanceof NameObject)) { |
||||||
|
return (NameObject) selectedUserObject; |
||||||
|
} |
||||||
|
//分组数据集下的子节点返回自身
|
||||||
|
else if(isGroupData(selectedTreeNode)){ |
||||||
|
return (NameObject) selectedUserObject; |
||||||
|
} |
||||||
|
else { |
||||||
|
return (NameObject) parentUserObject; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return null; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public TableDataWrapper[] getSelectedDatas() { |
||||||
|
TreePath[] selectedTreePaths = this.getSelectionPaths(); |
||||||
|
if (selectedTreePaths == null || selectedTreePaths.length == 0) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
TableDataWrapper[] nameobjs = new TableDataWrapper[selectedTreePaths.length]; |
||||||
|
for (int i = 0; i < selectedTreePaths.length; i++) { |
||||||
|
TreePath selectedTreePath = selectedTreePaths[i]; |
||||||
|
ExpandMutableTreeNode selectedTreeNode = (ExpandMutableTreeNode) selectedTreePath.getLastPathComponent(); |
||||||
|
Object selectedUserObject = selectedTreeNode.getUserObject(); |
||||||
|
ExpandMutableTreeNode parentTreeNode = (ExpandMutableTreeNode) selectedTreeNode.getParent(); |
||||||
|
Object parentUserObject = parentTreeNode.getUserObject(); |
||||||
|
if (parentUserObject instanceof NameObject && ((NameObject) parentUserObject).getObject() instanceof Integer) { |
||||||
|
if (selectedUserObject instanceof NameObject) { |
||||||
|
Object obj = ((NameObject) selectedUserObject).getObject(); |
||||||
|
if (obj instanceof TableDataWrapper) { |
||||||
|
nameobjs[i] = (TableDataWrapper) obj; |
||||||
|
} |
||||||
|
} |
||||||
|
} else { |
||||||
|
return new TableDataWrapper[0]; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return nameobjs; |
||||||
|
} |
||||||
|
|
||||||
|
public NameObject getRealSelectedNameObject() { |
||||||
|
TreePath selectedTreePath = this.getSelectionPath(); |
||||||
|
if (selectedTreePath == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
ExpandMutableTreeNode selectedTreeNode = (ExpandMutableTreeNode) selectedTreePath.getLastPathComponent(); |
||||||
|
Object selectedUserObject = selectedTreeNode.getUserObject(); |
||||||
|
if (selectedUserObject instanceof NameObject) { |
||||||
|
return (NameObject) selectedUserObject; |
||||||
|
} |
||||||
|
|
||||||
|
selectedTreeNode = (ExpandMutableTreeNode) selectedTreeNode.getParent(); |
||||||
|
selectedUserObject = selectedTreeNode.getUserObject(); |
||||||
|
if (selectedUserObject instanceof NameObject) { |
||||||
|
return (NameObject) selectedUserObject; |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* p:添加一个NameObject节点. |
||||||
|
*/ |
||||||
|
public void addNameObject(NameObject no) { |
||||||
|
if (no == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
DefaultTreeModel treeModel = (DefaultTreeModel) this.getModel(); |
||||||
|
|
||||||
|
// 新建一个放着NameObject的newChildTreeNode,加到Root下面
|
||||||
|
ExpandMutableTreeNode root = (ExpandMutableTreeNode) treeModel.getRoot(); |
||||||
|
|
||||||
|
ExpandMutableTreeNode newChildTreeNode = new ExpandMutableTreeNode(no); |
||||||
|
root.add(newChildTreeNode); |
||||||
|
newChildTreeNode.add(new ExpandMutableTreeNode()); |
||||||
|
|
||||||
|
treeModel.reload(root); |
||||||
|
} |
||||||
|
|
||||||
|
public <T extends UserObjectOP<?>> void populate(T userObject,Object o) { |
||||||
|
DefaultTreeModel treeModel = (DefaultTreeModel) this.getModel(); |
||||||
|
ExpandMutableTreeNode root = (ExpandMutableTreeNode) treeModel.getRoot(); |
||||||
|
root.setUserObject(userObject); |
||||||
|
root.removeAllChildren(); |
||||||
|
|
||||||
|
loadTreeNode(root); |
||||||
|
|
||||||
|
treeModel.reload(root); |
||||||
|
root.expandCurrentTreeNode(this); |
||||||
|
} |
||||||
|
|
||||||
|
public String getDSName(ExpandMutableTreeNode tn){ |
||||||
|
return ((NameObject)tn.getUserObject()).getName(); |
||||||
|
} |
||||||
|
|
||||||
|
public DSGroupTableData getGroupData(ExpandMutableTreeNode tn){ |
||||||
|
return (DSGroupTableData)((TableDataWrapper) ((NameObject)tn.getUserObject()).getObject()).getTableData(); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean isGroupData(ExpandMutableTreeNode tn){ |
||||||
|
if(null==tn) return false; |
||||||
|
if(!(tn.getUserObject() instanceof NameObject)) return false; |
||||||
|
return ((TableDataWrapper) ((NameObject)tn.getUserObject()).getObject()).getTableData() instanceof DSGroupTableData; |
||||||
|
} |
||||||
|
|
||||||
|
private void loadTreeNode(ExpandMutableTreeNode root){ |
||||||
|
Map<String,ExpandMutableTreeNode> treeNodeMap=new HashMap<String,ExpandMutableTreeNode>(); |
||||||
|
Map<String,ExpandMutableTreeNode> preloadTreeNodeMap=new HashMap<String,ExpandMutableTreeNode>(); |
||||||
|
ExpandMutableTreeNode[] children = loadChildTreeNodes(root); |
||||||
|
for(ExpandMutableTreeNode etn:children){ |
||||||
|
treeNodeMap.put(getDSName(etn),etn); |
||||||
|
preloadTreeNodeMap.put(getDSName(etn),etn); |
||||||
|
} |
||||||
|
for(ExpandMutableTreeNode etn:children){ |
||||||
|
if(isGroupData(etn)) loadDSGroupTreeNode(etn, treeNodeMap,preloadTreeNodeMap); |
||||||
|
} |
||||||
|
|
||||||
|
for(Map.Entry<String,ExpandMutableTreeNode> en:preloadTreeNodeMap.entrySet()){ |
||||||
|
root.add(en.getValue()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void loadDSGroupTreeNode(ExpandMutableTreeNode groupNode,Map<String,ExpandMutableTreeNode> nodes,Map<String,ExpandMutableTreeNode> leftNodes){ |
||||||
|
if(getGroupData(groupNode).getChildrenDSNames().equals("")) return; |
||||||
|
String[] nodeNames=getGroupData(groupNode).getChildrenDSNames().split(DSGroupTableData.getSeparator()); |
||||||
|
groupNode.removeAllChildren(); |
||||||
|
if(!getGroupData(groupNode).getParentDSName().equals("")) leftNodes.remove(groupNode); |
||||||
|
for(int i=0;i<nodeNames.length;i++){ |
||||||
|
if(isGroupData(nodes.get(nodeNames[i]))) |
||||||
|
loadDSGroupTreeNode(nodes.get(nodeNames[i]), nodes, leftNodes); |
||||||
|
groupNode.add(nodes.get(nodeNames[i])); |
||||||
|
leftNodes.remove(nodeNames[i]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void moveToGroup(ExpandMutableTreeNode groupToMoveTo){ |
||||||
|
|
||||||
|
//test
|
||||||
|
/*DefaultTreeModel treeModel = (DefaultTreeModel) this.getModel(); |
||||||
|
ExpandMutableTreeNode root = (ExpandMutableTreeNode) treeModel.getRoot(); |
||||||
|
root.setUserObject(pane.getOp()); |
||||||
|
ExpandMutableTreeNode[] nodes = loadChildTreeNodes(root); |
||||||
|
//DesignTableDataManager.clearGlobalDs();
|
||||||
|
for (int i = 0; i < nodes.length; i++) { |
||||||
|
NameObject nameObject = (NameObject) nodes[i].getUserObject(); |
||||||
|
TableData tableData=((TableDataWrapper) nameObject.getObject()).getTableData(); |
||||||
|
//tableDataConfig.addTableData(nameObject.getName(), ((TableDataWrapper) nameObject.getObject()).getTableData());
|
||||||
|
} |
||||||
|
|
||||||
|
TableDataConfig tableDataConfig=TableDataConfig.getInstance(); |
||||||
|
TableData tableData=tableDataConfig.getTableData("数据库查询1"); |
||||||
|
Map<String,TableData> tableDatasd=tableDataConfig.getTableDatas(); |
||||||
|
tableDataConfig.removeAllTableData(); |
||||||
|
Map<String,TableData> tableDataMap = new LinkedHashMap<String,TableData>(); |
||||||
|
|
||||||
|
tableDataMap.put(((NameObject) groupToMoveTo.getUserObject()).getName(), |
||||||
|
(TableData) ((TableDataWrapper) ((NameObject) groupToMoveTo.getUserObject()).getObject()).getTableData() |
||||||
|
); |
||||||
|
|
||||||
|
tableDataConfig.setTableDatas(tableDataMap); |
||||||
|
Map<String,TableData> tableDatas=tableDataConfig.getTableDatas();*/ |
||||||
|
//end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
String children=getGroupData(groupToMoveTo).getChildrenDSNames(); |
||||||
|
TreePath[] paths=getSelectionPaths(); |
||||||
|
String chosenChildren=""; |
||||||
|
//将选择的节点拼成子节点数据,以防止选择了分组又选择了其下的数据集
|
||||||
|
for(int i=0;i<paths.length;i++){ |
||||||
|
//分组本身
|
||||||
|
if(((ExpandMutableTreeNode) paths[i].getLastPathComponent()).equals(groupToMoveTo)) continue; |
||||||
|
//待分组的节点是分组
|
||||||
|
if(isGroupData((ExpandMutableTreeNode) paths[i].getLastPathComponent())){ |
||||||
|
chosenChildren+=DSGroupTableData.getSeparator()+getGroupData((ExpandMutableTreeNode) paths[i].getLastPathComponent()).getChildrenDSNames(); |
||||||
|
} |
||||||
|
} |
||||||
|
chosenChildren+=DSGroupTableData.getSeparator(); |
||||||
|
for(int i=0;i<paths.length;i++){ |
||||||
|
//分组本身
|
||||||
|
if(((ExpandMutableTreeNode) paths[i].getLastPathComponent()).equals(groupToMoveTo)) continue; |
||||||
|
//待分组的节点是分组
|
||||||
|
if(isGroupData((ExpandMutableTreeNode) paths[i].getLastPathComponent())){ |
||||||
|
getGroupData((ExpandMutableTreeNode) paths[i].getLastPathComponent()).setParentDSName( |
||||||
|
getDSName(groupToMoveTo) |
||||||
|
); |
||||||
|
|
||||||
|
} |
||||||
|
//选中的节点是该分组下的节点
|
||||||
|
if(chosenChildren.indexOf( |
||||||
|
DSGroupTableData.getSeparator()+ |
||||||
|
getDSName((ExpandMutableTreeNode) paths[i].getLastPathComponent())+ |
||||||
|
DSGroupTableData.getSeparator() |
||||||
|
)>-1 |
||||||
|
) continue; |
||||||
|
if(i==0){ |
||||||
|
children+=((children==null||children.equals(""))?"":DSGroupTableData.getSeparator())+ |
||||||
|
getDSName((ExpandMutableTreeNode) paths[i].getLastPathComponent()); |
||||||
|
}else { |
||||||
|
children+= ((children==null||children.equals(""))?"":DSGroupTableData.getSeparator())+ |
||||||
|
getDSName((ExpandMutableTreeNode) paths[i].getLastPathComponent()); |
||||||
|
} |
||||||
|
deleteNodeToMoveFromParent((ExpandMutableTreeNode) paths[i].getLastPathComponent()); |
||||||
|
} |
||||||
|
getGroupData(groupToMoveTo).setChildrenDSNames(children); |
||||||
|
TableDataSourceOP op=pane.getOp(); |
||||||
|
fireChangeEvent(); |
||||||
|
|
||||||
|
refreshChildByName(getDSName(groupToMoveTo)); |
||||||
|
} |
||||||
|
|
||||||
|
public void moveToRoot(){ |
||||||
|
TreePath[] paths=getSelectionPaths(); |
||||||
|
for(int i=0;i<paths.length;i++){ |
||||||
|
ExpandMutableTreeNode selectedNode=(ExpandMutableTreeNode) paths[i].getLastPathComponent(); |
||||||
|
//如果选中的节点有字段直接返回 防止拖动字段值影响拖动
|
||||||
|
if(!(selectedNode.getUserObject() instanceof NameObject)) return; |
||||||
|
deleteNodeToMoveFromParent(selectedNode); |
||||||
|
} |
||||||
|
fireChangeEvent(); |
||||||
|
refresh(); |
||||||
|
} |
||||||
|
|
||||||
|
private void fireChangeEvent(){ |
||||||
|
TableDataSourceOP op=pane.getOp(); |
||||||
|
if (op!=null) { |
||||||
|
if(op.getDataMode()==0){ |
||||||
|
pane.getTC().fireTargetModified(); |
||||||
|
}else if(op.getDataMode()==1){//服务器数据集直接保存
|
||||||
|
TableDataConfig tableDataConfig = TableDataConfig.getInstance(); |
||||||
|
DefaultTreeModel treeModel = (DefaultTreeModel) this.getModel(); |
||||||
|
ExpandMutableTreeNode root = (ExpandMutableTreeNode) treeModel.getRoot(); |
||||||
|
root.setUserObject(pane.getOp()); |
||||||
|
ExpandMutableTreeNode[] nodes = loadChildTreeNodes(root); |
||||||
|
|
||||||
|
LinkedHashMap<String,TableData> tableDatas = new LinkedHashMap(); |
||||||
|
for (int i = 0; i < nodes.length; i++) { |
||||||
|
if(isGroupData(nodes[i])){ |
||||||
|
NameObject nameObject = (NameObject) nodes[i].getUserObject(); |
||||||
|
TableData newData=((TableDataWrapper) nameObject.getObject()).getTableData(); |
||||||
|
((UniqueKey)newData).setNameSpace(null); |
||||||
|
//tableDataConfig.removeTableData(nameObject.getName());
|
||||||
|
((DSGroupTableData)tableDataConfig.getTableData(nameObject.getName())).setAttrParentDSName(((DSGroupTableData)newData).getAttrParentDSName()); |
||||||
|
((DSGroupTableData)tableDataConfig.getTableData(nameObject.getName())).setAttrChildrenDSNames(((DSGroupTableData)newData).getAttrChildrenDSNames()); |
||||||
|
} |
||||||
|
/*NameObject nameObject = (NameObject) nodes[i].getUserObject(); |
||||||
|
TableData tableData=((TableDataWrapper) nameObject.getObject()).getTableData(); |
||||||
|
((UniqueKey)tableData).setNameSpace(null); |
||||||
|
tableDatas.put(nameObject.getName(),tableData);*/ |
||||||
|
} |
||||||
|
//tableDataConfig.setTableDatas(tableDatas);
|
||||||
|
//new GlobalTableDataAction().actionPerformed(null);
|
||||||
|
//new GlobalTableDataAction().fireDSChanged();
|
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
//删除节点原分组子节点信息
|
||||||
|
protected void deleteNodeToMoveFromParent(ExpandMutableTreeNode node){ |
||||||
|
DefaultTreeModel treeModel = (DefaultTreeModel) this.getModel(); |
||||||
|
ExpandMutableTreeNode root = (ExpandMutableTreeNode) treeModel.getRoot(); |
||||||
|
ExpandMutableTreeNode[] children = loadChildTreeNodes(root); |
||||||
|
String separator=DSGroupTableData.getSeparator(); |
||||||
|
for(int i=0;i<children.length;i++){ |
||||||
|
if(isGroupData(children[i])){ |
||||||
|
String childNodes=getGroupData(children[i]).getChildrenDSNames(); |
||||||
|
childNodes=separator+childNodes+separator; |
||||||
|
String nodeName=separator+getDSName(node)+separator; |
||||||
|
if(childNodes.indexOf(nodeName)>-1){ |
||||||
|
childNodes=childNodes.replace(nodeName,separator).replaceAll("^"+separator+"{1}","").replaceAll(separator+"${1}",""); |
||||||
|
getGroupData(children[i]).setChildrenDSNames(childNodes); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
//更新了某个分组数据集名称
|
||||||
|
public void updateNodeName(String oldName,String newName){ |
||||||
|
DefaultTreeModel treeModel = (DefaultTreeModel) this.getModel(); |
||||||
|
ExpandMutableTreeNode root = (ExpandMutableTreeNode) treeModel.getRoot(); |
||||||
|
ExpandMutableTreeNode[] children = loadChildTreeNodes(root); |
||||||
|
String separator=DSGroupTableData.getSeparator(); |
||||||
|
String newNameToReplaceWith=separator+newName+separator; |
||||||
|
String oldNameToMatchWith=separator+oldName+separator; |
||||||
|
for(int i=0;i<children.length;i++){ |
||||||
|
if(isGroupData(children[i])){ |
||||||
|
DSGroupTableData tableData=getGroupData(children[i]); |
||||||
|
String childNodes=tableData.getChildrenDSNames(); |
||||||
|
childNodes=separator+childNodes+separator; |
||||||
|
if(childNodes.indexOf(oldNameToMatchWith)>-1){ |
||||||
|
childNodes=childNodes.replace(oldNameToMatchWith,newNameToReplaceWith).replaceAll("^"+separator+"{1}","").replaceAll(separator+"${1}",""); |
||||||
|
getGroupData(children[i]).setChildrenDSNames(childNodes); |
||||||
|
} |
||||||
|
String parentNode=tableData.getParentDSName(); |
||||||
|
if(parentNode.equals(oldName)){ |
||||||
|
parentNode=newName; |
||||||
|
tableData.setParentDSName(parentNode); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,251 @@ |
|||||||
|
package com.fr.plugins.dsgroup; |
||||||
|
|
||||||
|
import com.fr.design.data.datapane.TableDataTree; |
||||||
|
import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; |
||||||
|
import com.fr.design.mainframe.dnd.ArrayTransferable; |
||||||
|
import com.fr.general.NameObject; |
||||||
|
import com.fr.plugins.dsgroup.fun.DSGroupTableData; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import javax.swing.tree.TreePath; |
||||||
|
import java.awt.*; |
||||||
|
import java.awt.dnd.*; |
||||||
|
import java.util.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by phetran_ye on 2018/8/20. |
||||||
|
*/ |
||||||
|
public class CustomTableDataTreeDragSource extends DragSourceAdapter implements DragGestureListener { |
||||||
|
private DragSource source; |
||||||
|
private String[][] doubleArray; |
||||||
|
private Point orginPoint; |
||||||
|
private Point orginPointInScreen; |
||||||
|
private CustomTableDataTree tree; |
||||||
|
|
||||||
|
public CustomTableDataTreeDragSource(JTree tree, int actions) { |
||||||
|
source = new DragSource(); |
||||||
|
source.createDefaultDragGestureRecognizer(tree, actions, this); |
||||||
|
if(tree instanceof CustomTableDataTree) this.tree=(CustomTableDataTree)tree; |
||||||
|
/*toolTipPopup.setLayout(new BorderLayout()); |
||||||
|
toolTipPopup.setPreferredSize(new Dimension(50,50)); |
||||||
|
toolTipPanel.add(toolTipLabel);*/ |
||||||
|
} |
||||||
|
|
||||||
|
TreePath groupToMoveTo; |
||||||
|
/*private JPopupMenu toolTipPopup= new JPopupMenu(); |
||||||
|
private JPanel toolTipPanel = new JPanel(); |
||||||
|
private JLabel toolTipLabel=new JLabel();*/ |
||||||
|
|
||||||
|
/* |
||||||
|
* Drag Gesture Handler |
||||||
|
*/ |
||||||
|
public void dragGestureRecognized(DragGestureEvent dge) { |
||||||
|
//
|
||||||
|
if(null==orginPoint) orginPoint=dge.getDragOrigin(); |
||||||
|
//
|
||||||
|
groupToMoveTo =null; |
||||||
|
Component comp = dge.getComponent(); |
||||||
|
if (comp instanceof TableDataTree) { |
||||||
|
|
||||||
|
java.util.List<String[]> stringList = new ArrayList<String[]>(); |
||||||
|
TableDataTree tree = (TableDataTree) comp; |
||||||
|
|
||||||
|
TreePath[] paths = tree.getSelectionPaths(); |
||||||
|
if (paths == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
doubleArray = null; |
||||||
|
setnameArray(paths, stringList); |
||||||
|
|
||||||
|
source.startDrag(dge, DragSource.DefaultLinkDrop, new ArrayTransferable(doubleArray), this); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void setnameArray(TreePath[] paths, java.util.List<String[]> stringList) { |
||||||
|
for (int i = 0; i < paths.length; i++) { |
||||||
|
if ((paths[i] == null) || (paths[i].getPathCount() <= 1)) { |
||||||
|
return;// We can't move the root node or an empty selection
|
||||||
|
} |
||||||
|
ExpandMutableTreeNode segmentMutableTreeNode = (ExpandMutableTreeNode) paths[i].getLastPathComponent(); |
||||||
|
Object userObj = segmentMutableTreeNode.getUserObject(); |
||||||
|
java.util.List<String> tableAddress = new ArrayList<String>(); |
||||||
|
String displayName; |
||||||
|
StringBuffer dsNameBuf = new StringBuffer(); |
||||||
|
if (userObj instanceof NameObject) { |
||||||
|
continue; |
||||||
|
} else { |
||||||
|
if (!(userObj instanceof String)) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
displayName = (String) userObj; |
||||||
|
// james 读取表名
|
||||||
|
while (segmentMutableTreeNode.getParent().getParent() != null) { |
||||||
|
segmentMutableTreeNode = (ExpandMutableTreeNode) segmentMutableTreeNode.getParent(); |
||||||
|
if(tree.isGroupData(segmentMutableTreeNode)){ |
||||||
|
continue; |
||||||
|
} |
||||||
|
ExpandMutableTreeNode datasheetExpandMutableTreeNode = segmentMutableTreeNode; |
||||||
|
Object parentUserObj = datasheetExpandMutableTreeNode.getUserObject(); |
||||||
|
if (parentUserObj instanceof NameObject && !(((NameObject) parentUserObj).getObject() instanceof Integer)) { |
||||||
|
NameObject nameObject = (NameObject) parentUserObj; |
||||||
|
tableAddress.add(nameObject.getName()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
for (int j = tableAddress.size() - 1; j > -1; j--) { |
||||||
|
dsNameBuf.append(tableAddress.get(j)); |
||||||
|
if (j != 0) { |
||||||
|
dsNameBuf.append('_'); |
||||||
|
} |
||||||
|
} |
||||||
|
String dsName; |
||||||
|
if (dsNameBuf.toString() != null) { |
||||||
|
dsName = dsNameBuf.toString(); |
||||||
|
} else { |
||||||
|
return; |
||||||
|
} |
||||||
|
String[] attributes = {dsName, displayName}; |
||||||
|
stringList.add(attributes); |
||||||
|
Object[] bo = stringList.toArray(); |
||||||
|
doubleArray = new String[bo.length][]; |
||||||
|
for (int io = 0; io < bo.length; io++) { |
||||||
|
if (bo[io] instanceof String[]) { |
||||||
|
doubleArray[io] = (String[]) bo[io]; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void dragOver(DragSourceDragEvent dsde) { |
||||||
|
DragSourceContext dsc = dsde.getDragSourceContext(); |
||||||
|
Component comp=dsc.getComponent(); |
||||||
|
TableDataTree tree = (TableDataTree) comp; |
||||||
|
Point p=dsde.getLocation(); |
||||||
|
if(null==orginPointInScreen) orginPointInScreen=p; |
||||||
|
TreePath path = tree.getPathForLocation((int)(orginPoint.getX()+p.getX()-orginPointInScreen.getX()), |
||||||
|
(int)(orginPoint.getY()+p.getY()-orginPointInScreen.getY())) ; |
||||||
|
if(null==path){ |
||||||
|
if(null!= groupToMoveTo){ |
||||||
|
tree.removeSelectionPath(groupToMoveTo); |
||||||
|
groupToMoveTo=null; |
||||||
|
} |
||||||
|
}else{ |
||||||
|
//移入选择的分组是之前选中的节点之一不做任何处理
|
||||||
|
TreePath[] paths=tree.getSelectionPaths(); |
||||||
|
for(int i=0;i<paths.length;i++){ |
||||||
|
if(paths[i].equals(path)) return; |
||||||
|
} |
||||||
|
if( |
||||||
|
((CustomTableDataTree) tree).isGroupData((ExpandMutableTreeNode) path.getLastPathComponent()) |
||||||
|
){ |
||||||
|
|
||||||
|
if(null==groupToMoveTo){ |
||||||
|
tree.addSelectionPath(path); |
||||||
|
groupToMoveTo =path; |
||||||
|
}else if(!groupToMoveTo.equals(path)){ |
||||||
|
tree.addSelectionPath(path); |
||||||
|
tree.removeSelectionPath(groupToMoveTo); |
||||||
|
groupToMoveTo =path; |
||||||
|
} |
||||||
|
|
||||||
|
}else{ |
||||||
|
if(null!= groupToMoveTo){ |
||||||
|
tree.removeSelectionPath(groupToMoveTo); |
||||||
|
groupToMoveTo=null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
//显示tooltip
|
||||||
|
//showTooltip("hello",p,pane);
|
||||||
|
/* ToolTipManager.sharedInstance().registerComponent(tree); |
||||||
|
tree.setToolTipText("haha"); |
||||||
|
Object o=tree.getActionMap(); |
||||||
|
Action action = tree.getActionMap().get("postTip"); |
||||||
|
*//*if (action == null) // no tooltip
|
||||||
|
return;*//*
|
||||||
|
ActionEvent ae = new ActionEvent(tree, ActionEvent.ACTION_PERFORMED, |
||||||
|
"postTip", EventQueue.getMostRecentEventTime(), 0); |
||||||
|
action.actionPerformed(ae);*/ |
||||||
|
/*JToolTip toolTip=pane.createToolTip(); |
||||||
|
toolTip.setLocation(p); |
||||||
|
toolTip.setVisible(true); |
||||||
|
toolTip.setTipText("haha");*/ |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void dragDropEnd(DragSourceDropEvent dsde) { |
||||||
|
DragSourceContext dsc = dsde.getDragSourceContext(); |
||||||
|
Component comp=dsc.getComponent(); |
||||||
|
CustomTableDataTree tree = (CustomTableDataTree) comp; |
||||||
|
Point p=dsde.getLocation(); |
||||||
|
if(null==orginPoint||null==orginPointInScreen) return; |
||||||
|
TreePath path = tree.getPathForLocation((int)(orginPoint.getX()+p.getX()-orginPointInScreen.getX()), |
||||||
|
(int)(orginPoint.getY()+p.getY()-orginPointInScreen.getY())) ; |
||||||
|
//没选中意味移到根路径下
|
||||||
|
if(null==path) { |
||||||
|
tree.moveToRoot(); |
||||||
|
} |
||||||
|
//移入的分组如果是选中的节点之一,不做处理,移入后该分组自动选择这里不判断了
|
||||||
|
/*TreePath[] paths=tree.getSelectionPaths(); |
||||||
|
for(int i=0;i<paths.length;i++){ |
||||||
|
if(paths[i].equals(path)) return; |
||||||
|
}*/ |
||||||
|
//将数据集或者分组移动到该分组下
|
||||||
|
if(null!= groupToMoveTo && groupToMoveTo.equals(path)){ |
||||||
|
tree.moveToGroup((ExpandMutableTreeNode) groupToMoveTo.getLastPathComponent()); |
||||||
|
} |
||||||
|
orginPoint=null; |
||||||
|
orginPointInScreen=null; |
||||||
|
groupToMoveTo =null; |
||||||
|
} |
||||||
|
|
||||||
|
/*private void moveToGroup(CustomTableDataTree tree,TreePath group){ |
||||||
|
String children=tree.getGroupData((ExpandMutableTreeNode) groupToMoveTo.getLastPathComponent()).getChildrenDSNames(); |
||||||
|
TreePath[] paths=tree.getSelectionPaths(); |
||||||
|
|
||||||
|
String chosenChildren=DSGroupTableData.getSeparator(); |
||||||
|
for(int i=0;i<paths.length;i++){ |
||||||
|
//待分组的节点是分组
|
||||||
|
if(tree.isGroupData((ExpandMutableTreeNode) paths[i].getLastPathComponent())){ |
||||||
|
chosenChildren+=DSGroupTableData.getSeparator()+tree.getGroupData((ExpandMutableTreeNode) paths[i].getLastPathComponent()).getChildrenDSNames(); |
||||||
|
} |
||||||
|
} |
||||||
|
chosenChildren+=DSGroupTableData.getSeparator(); |
||||||
|
for(int i=0;i<paths.length;i++){ |
||||||
|
//?if(path.equals(paths[i])) continue;
|
||||||
|
//待分组的节点是分组
|
||||||
|
if(tree.isGroupData((ExpandMutableTreeNode) paths[i].getLastPathComponent())){ |
||||||
|
tree.getGroupData((ExpandMutableTreeNode)paths[i].getLastPathComponent()).setParentDSName( |
||||||
|
tree.getDSName((ExpandMutableTreeNode) groupToMoveTo.getLastPathComponent()) |
||||||
|
); |
||||||
|
|
||||||
|
} |
||||||
|
//选中的节点是该分组下的节点
|
||||||
|
if(chosenChildren.indexOf( |
||||||
|
DSGroupTableData.getSeparator()+ |
||||||
|
tree.getDSName((ExpandMutableTreeNode) paths[i].getLastPathComponent())+ |
||||||
|
DSGroupTableData.getSeparator() |
||||||
|
)>0 |
||||||
|
) continue; |
||||||
|
children+= DSGroupTableData.getSeparator()+tree.getDSName((ExpandMutableTreeNode) paths[i].getLastPathComponent()); |
||||||
|
} |
||||||
|
tree.getGroupData((ExpandMutableTreeNode) groupToMoveTo.getLastPathComponent()).setChildrenDSNames(children); |
||||||
|
pane.getTC().fireTargetModified(); |
||||||
|
tree.refreshChildByName(tree.getDSName((ExpandMutableTreeNode) groupToMoveTo.getLastPathComponent())); |
||||||
|
}*/ |
||||||
|
//提示信息
|
||||||
|
/*private void showTooltip(String text,Point p,Component comp){ |
||||||
|
toolTipLabel.setText(text); |
||||||
|
toolTipPopup.show(comp, (int) p.getX(), (int) p.getX()); |
||||||
|
|
||||||
|
}*/ |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,448 @@ |
|||||||
|
package com.fr.plugins.dsgroup; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by phetran_ye on 2018/8/8. |
||||||
|
*/ |
||||||
|
import com.fr.base.BaseUtils; |
||||||
|
import com.fr.base.TableData; |
||||||
|
import com.fr.base.io.BaseBook; |
||||||
|
import com.fr.data.TableDataSource; |
||||||
|
import com.fr.data.impl.TableDataSourceDependent; |
||||||
|
import com.fr.design.DesignModelAdapter; |
||||||
|
import com.fr.design.ExtraDesignClassManager; |
||||||
|
import com.fr.design.actions.UpdateAction; |
||||||
|
import com.fr.design.constants.UIConstants; |
||||||
|
import com.fr.design.data.BasicTableDataTreePane; |
||||||
|
import com.fr.design.data.BasicTableDataUtils; |
||||||
|
import com.fr.design.data.DesignTableDataManager; |
||||||
|
import com.fr.design.data.datapane.TableDataSourceOP; |
||||||
|
import com.fr.design.data.datapane.TableDataTree; |
||||||
|
import com.fr.design.data.datapane.TableDataTreePane; |
||||||
|
import com.fr.design.data.tabledata.StoreProcedureWorkerListener; |
||||||
|
import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane; |
||||||
|
import com.fr.design.data.tabledata.wrapper.AbstractTableDataWrapper; |
||||||
|
import com.fr.design.dialog.BasicDialog; |
||||||
|
import com.fr.design.dialog.BasicPane; |
||||||
|
import com.fr.design.dialog.DialogActionAdapter; |
||||||
|
import com.fr.design.file.HistoryTemplateListCache; |
||||||
|
import com.fr.design.fun.TableDataPaneProcessor; |
||||||
|
import com.fr.design.gui.ibutton.UIHeadGroup; |
||||||
|
import com.fr.design.gui.icontainer.UIResizableContainer; |
||||||
|
import com.fr.design.gui.icontainer.UIScrollPane; |
||||||
|
import com.fr.design.gui.itextfield.UITextField; |
||||||
|
import com.fr.design.gui.itoolbar.UIToolbar; |
||||||
|
import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.design.icon.IconPathConstants; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.mainframe.DesignerContext; |
||||||
|
import com.fr.design.mainframe.JTemplate; |
||||||
|
import com.fr.design.mainframe.WestRegionContainerPane; |
||||||
|
import com.fr.design.mainframe.chart.gui.data.TableDataPane; |
||||||
|
import com.fr.design.menu.MenuDef; |
||||||
|
import com.fr.design.menu.SeparatorDef; |
||||||
|
import com.fr.design.menu.ToolBarDef; |
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
import com.fr.general.GeneralContext; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.general.NameObject; |
||||||
|
import com.fr.plugin.context.PluginContext; |
||||||
|
import com.fr.plugin.injectable.PluginModule; |
||||||
|
import com.fr.plugin.manage.PluginFilter; |
||||||
|
import com.fr.plugin.observer.PluginEvent; |
||||||
|
import com.fr.plugin.observer.PluginEventListener; |
||||||
|
import com.fr.plugins.dsgroup.fun.DSGroupTableData; |
||||||
|
import com.fr.stable.core.PropertyChangeAdapter; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import java.awt.*; |
||||||
|
import java.awt.dnd.DnDConstants; |
||||||
|
import java.awt.event.ActionEvent; |
||||||
|
import java.awt.event.MouseAdapter; |
||||||
|
import java.awt.event.MouseEvent; |
||||||
|
import java.util.Collections; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
public class CustomTableDataTreePane extends BasicTableDataTreePane { |
||||||
|
|
||||||
|
public static final int PLUGIN_LISTENER_PRIORITY = 1; |
||||||
|
private TableDataSourceOP op; |
||||||
|
private CustomTableDataTree dataTree; |
||||||
|
private EditAction editAction; |
||||||
|
private RemoveAction removeAction; |
||||||
|
private PreviewTableDataAction previewTableDataAction; |
||||||
|
private static CustomTableDataTreePane singleton = new CustomTableDataTreePane(); |
||||||
|
//前一个默认pane
|
||||||
|
private static TableDataTreePane exPane; |
||||||
|
//前一个自定义pane
|
||||||
|
private static CustomTableDataTreePane exCustomPane; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public synchronized static BasicTableDataTreePane getInstance(DesignModelAdapter<?, ?> tc) { |
||||||
|
|
||||||
|
if (singleton.tc == null) { |
||||||
|
singleton.addMenuDef.clearShortCuts(); |
||||||
|
singleton.createAddMenuDef(); |
||||||
|
} |
||||||
|
|
||||||
|
singleton.tc = tc; |
||||||
|
singleton.op = new TableDataSourceOP(tc); |
||||||
|
singleton.op.setDataMode(singleton.buttonGroup.getSelectedIndex() == 0 ? TEMPLATE_TABLE_DATA : SERVER_TABLE_DATA); |
||||||
|
singleton.refreshDockingView(); |
||||||
|
|
||||||
|
WestRegionContainerPane wp=WestRegionContainerPane.getInstance(); |
||||||
|
JComponent downPane=wp.getDownPane(); |
||||||
|
if(downPane!=singleton) { |
||||||
|
wp.replaceDownPane(singleton); |
||||||
|
} |
||||||
|
return singleton; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private CustomTableDataTreePane() { |
||||||
|
this.setLayout(new BorderLayout(4, 0)); |
||||||
|
this.setBorder(null); |
||||||
|
dataTree = new CustomTableDataTree(); |
||||||
|
ToolTipManager.sharedInstance().registerComponent(dataTree); |
||||||
|
ToolTipManager.sharedInstance().setDismissDelay(3000); |
||||||
|
ToolTipManager.sharedInstance().setInitialDelay(0); |
||||||
|
addMenuDef = new MenuDef(Toolkit.i18nText("Fine-Design_Basic_Action_Add")); |
||||||
|
addMenuDef.setIconPath(IconPathConstants.ADD_POPMENU_ICON_PATH); |
||||||
|
createAddMenuDef(); |
||||||
|
GeneralContext.listenPluginRunningChanged(new PluginEventListener(PLUGIN_LISTENER_PRIORITY) { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void on(PluginEvent event) { |
||||||
|
WestRegionContainerPane wp=WestRegionContainerPane.getInstance(); |
||||||
|
JComponent downPane=wp.getDownPane(); |
||||||
|
BasicTableDataTreePane pane=TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter()); |
||||||
|
if(downPane!=pane) { |
||||||
|
wp.replaceDownPane(pane); |
||||||
|
} |
||||||
|
addMenuDef.clearShortCuts(); |
||||||
|
createAddMenuDef(); |
||||||
|
} |
||||||
|
}, new PluginFilter() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean accept(PluginContext context) { |
||||||
|
|
||||||
|
return context.contain(PluginModule.ExtraDesign); |
||||||
|
} |
||||||
|
}); |
||||||
|
GeneralContext.listenPluginRunningChanged(new PluginEventListener() { |
||||||
|
public void on(PluginEvent event){ |
||||||
|
this.reloadCurrTemplate(); |
||||||
|
} |
||||||
|
private void reloadCurrTemplate() { |
||||||
|
JTemplate temp = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
||||||
|
if (this.accept(temp)) { |
||||||
|
temp.refreshResource(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private boolean accept(JTemplate<?, ?> temp) { |
||||||
|
return temp != null && temp.getEditingFILE() != null && temp.getEditingFILE().exists(); |
||||||
|
} |
||||||
|
}, new PluginFilter() { |
||||||
|
public boolean accept(PluginContext cxt) { |
||||||
|
return cxt.contain("TableDataDefineProvider"); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
editAction = new EditAction(); |
||||||
|
removeAction = new RemoveAction(); |
||||||
|
previewTableDataAction = new PreviewTableDataAction(dataTree); |
||||||
|
connectionTableAction = new ConnectionTableAction(); |
||||||
|
ToolBarDef toolbarDef = new ToolBarDef(); |
||||||
|
toolbarDef.addShortCut(addMenuDef,SeparatorDef.DEFAULT, editAction, removeAction, SeparatorDef.DEFAULT, previewTableDataAction, connectionTableAction); |
||||||
|
UIToolbar toolBar = ToolBarDef.createJToolBar(); |
||||||
|
toolBar.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIConstants.TOOLBAR_BORDER_COLOR)); |
||||||
|
toolBar.setBorderPainted(true); |
||||||
|
toolbarDef.updateToolBar(toolBar); |
||||||
|
|
||||||
|
JPanel toolbarPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
toolbarPane.add(toolBar, BorderLayout.CENTER); |
||||||
|
this.add(toolbarPane, BorderLayout.NORTH); |
||||||
|
|
||||||
|
UIScrollPane scrollPane = new UIScrollPane(dataTree); |
||||||
|
scrollPane.setBorder(null); |
||||||
|
initbuttonGroup(); |
||||||
|
JPanel jPanel = new JPanel(new BorderLayout(0, 0)); |
||||||
|
JPanel buttonPane = new JPanel(new GridLayout()); |
||||||
|
buttonPane.add(buttonGroup, BorderLayout.CENTER); |
||||||
|
jPanel.add(buttonPane, BorderLayout.NORTH); |
||||||
|
jPanel.add(scrollPane, BorderLayout.CENTER); |
||||||
|
this.add(jPanel, BorderLayout.CENTER); |
||||||
|
dataTree.addMouseListener(new MouseAdapter() { |
||||||
|
@Override |
||||||
|
public void mousePressed(MouseEvent e) { |
||||||
|
checkButtonEnabled(); |
||||||
|
} |
||||||
|
}); |
||||||
|
dataTree.addKeyListener(getTableTreeNodeListener(editAction, previewTableDataAction, removeAction, op, dataTree)); |
||||||
|
// TreeCellEditor
|
||||||
|
dataTree.setEditable(true); |
||||||
|
TableDataTreeCellEditor treeCellEditor = new TableDataTreeCellEditor(new UITextField(), dataTree, this); |
||||||
|
treeCellEditor.addCellEditorListener(treeCellEditor); |
||||||
|
dataTree.setCellEditor(treeCellEditor); |
||||||
|
dataTree.setPane(this); |
||||||
|
new CustomTableDataTreeDragSource(dataTree, DnDConstants.ACTION_COPY); |
||||||
|
checkButtonEnabled(); |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
protected DesignModelAdapter getTC(){ |
||||||
|
return tc; |
||||||
|
} |
||||||
|
|
||||||
|
protected void checkButtonEnabled() { |
||||||
|
super.checkButtonEnabled(editAction, previewTableDataAction, removeAction, op, dataTree); |
||||||
|
//新版本去掉
|
||||||
|
/*int selectioncount = dataTree.getSelectionCount(); |
||||||
|
if (selectioncount == 1 && dataTree.isGroupData((ExpandMutableTreeNode) dataTree.getSelectionPath().getLastPathComponent())) { |
||||||
|
previewTableDataAction.setEnabled(false); |
||||||
|
}*/ |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 刷新 |
||||||
|
*/ |
||||||
|
public void refreshDockingView() { |
||||||
|
populate(new TableDataSourceOP(tc)); |
||||||
|
this.checkButtonEnabled(); |
||||||
|
} |
||||||
|
|
||||||
|
protected void initbuttonGroup() { |
||||||
|
// Icon[] iconArray = {BaseUtils.readIcon("/com/fr/design/images/data/datasource.png"), BaseUtils.readIcon("/com/fr/design/images/data/dock/serverdatabase.png")};
|
||||||
|
final Integer[] modeArray = {TEMPLATE_TABLE_DATA, SERVER_TABLE_DATA}; |
||||||
|
String[] textArray = new String[]{Toolkit.i18nText("Fine-Design_Basic_Tabledata_Source_Type_Template"), Toolkit.i18nText("Fine-Design_Basic_DS_Server_TableData")}; |
||||||
|
buttonGroup = new UIHeadGroup(textArray) { |
||||||
|
public void tabChanged(int index) { |
||||||
|
if (op != null) { |
||||||
|
op.setDataMode(modeArray[buttonGroup.getSelectedIndex()]); |
||||||
|
addMenuDef.setEnabled(modeArray[buttonGroup.getSelectedIndex()] == TEMPLATE_TABLE_DATA ? true : false); |
||||||
|
refreshDockingView(); |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
||||||
|
buttonGroup.setNeedLeftRightOutLine(false); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 编辑面板 |
||||||
|
* |
||||||
|
* @param uPanel 面板 |
||||||
|
* @param originalName 原始名字 |
||||||
|
*/ |
||||||
|
public void dgEdit(final AbstractTableDataPane<?> uPanel, String originalName,final boolean isUpdate) { |
||||||
|
uPanel.addStoreProcedureWorkerListener(new StoreProcedureWorkerListener() { |
||||||
|
public void fireDoneAction() { |
||||||
|
if (dataTree.getSelectionPath() == null) { |
||||||
|
dataTree.refresh(); |
||||||
|
} else { |
||||||
|
Object object = dataTree.getSelectionPath().getLastPathComponent(); |
||||||
|
int[] rows = dataTree.getSelectionRows(); |
||||||
|
dataTree.refreshChildByName(object.toString()); |
||||||
|
dataTree.setSelectionRows(rows); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
final NamePane nPanel = uPanel.asNamePane(); |
||||||
|
nPanel.setObjectName(originalName); |
||||||
|
final String oldName = originalName; |
||||||
|
final BasicDialog dg; |
||||||
|
allDSNames = DesignTableDataManager.getAllDSNames(tc.getBook()); |
||||||
|
dg = nPanel.showLargeWindow(SwingUtilities.getWindowAncestor(CustomTableDataTreePane.this), new DialogActionAdapter() { |
||||||
|
public void doOk() { |
||||||
|
DesignTableDataManager.setThreadLocal(DesignTableDataManager.NO_PARAMETER); |
||||||
|
tc.renameTableData(oldName, nPanel.getObjectName(), false); |
||||||
|
TableDataSource tds = tc.getBook(); |
||||||
|
TableData td = uPanel.updateBean(); |
||||||
|
|
||||||
|
if (td instanceof TableDataSourceDependent) { |
||||||
|
((TableDataSourceDependent) td).setTableDataSource(tds); |
||||||
|
} |
||||||
|
String tdName = nPanel.getObjectName(); |
||||||
|
tds.putTableData(tdName, td); |
||||||
|
Map<String, String> map = new HashMap<String, String>(); |
||||||
|
if (!ComparatorUtils.equals(oldName, tdName)) { |
||||||
|
map.put(oldName, tdName); |
||||||
|
} |
||||||
|
fireDSChanged(map); |
||||||
|
tc.fireTargetModified(); |
||||||
|
tc.parameterChanged(); |
||||||
|
|
||||||
|
int[] rows = dataTree.getSelectionRows(); |
||||||
|
//选择了一个数据集后新增分组 如果当前选择的节点是分组&&(!(td instanceof DSGroupTableData))
|
||||||
|
if(isUpdate) { |
||||||
|
//更新数据集
|
||||||
|
dataTree.updateNodeName(oldName,tdName); |
||||||
|
dataTree.refreshChildByName(tdName); |
||||||
|
}else{ |
||||||
|
//新增数据集
|
||||||
|
if(dataTree.getSelectionPaths()!=null&&dataTree.getSelectionPaths().length==1){//在分组下新增分组
|
||||||
|
ExpandMutableTreeNode tn=(ExpandMutableTreeNode)dataTree.getSelectionPaths()[0].getLastPathComponent(); |
||||||
|
if(dataTree.isGroupData(tn)){//在分组下新增分组
|
||||||
|
String children=dataTree.getGroupData(tn).getChildrenDSNames(); |
||||||
|
children+=((children==null||children.equals(""))?"":DSGroupTableData.getSeparator())+tdName; |
||||||
|
dataTree.getGroupData(tn).setChildrenDSNames(children); |
||||||
|
dataTree.refreshChildByName(dataTree.getDSName(tn));//待研究区别
|
||||||
|
//tn.expandCurrentTreeNode(dataTree);待研究怎么展开
|
||||||
|
if(td instanceof DSGroupTableData){//修改当前分组的父分组
|
||||||
|
((DSGroupTableData) td).setParentDSName(dataTree.getDSName(tn)); |
||||||
|
} |
||||||
|
}else{ |
||||||
|
dataTree.refreshChildByName(tdName); |
||||||
|
} |
||||||
|
}else{ |
||||||
|
dataTree.refreshChildByName(tdName); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
dataTree.setSelectionRows(rows); |
||||||
|
} |
||||||
|
}); |
||||||
|
nPanel.addPropertyChangeListener(new PropertyChangeAdapter() { |
||||||
|
@Override |
||||||
|
public void propertyChange() { |
||||||
|
doPropertyChange(dg, nPanel, oldName); |
||||||
|
} |
||||||
|
}); |
||||||
|
dg.setVisible(true); |
||||||
|
} |
||||||
|
|
||||||
|
private class EditAction extends UpdateAction { |
||||||
|
public EditAction() { |
||||||
|
this.setName(Toolkit.i18nText("Fine-Design_Basic_Edit")); |
||||||
|
this.setMnemonic('E'); |
||||||
|
this.setSmallIcon(BaseUtils.readIcon(IconPathConstants.TD_EDIT_ICON_PATH)); |
||||||
|
} |
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent e) { |
||||||
|
final NameObject selectedNO = dataTree.getRealSelectedNameObject(); |
||||||
|
if (selectedNO != null) { |
||||||
|
DesignTableDataManager.removeSelectedColumnNames(selectedNO.getName()); |
||||||
|
dgEdit(((AbstractTableDataWrapper) selectedNO.getObject()).creatTableDataPane(), selectedNO.getName(), true); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private class RemoveAction extends UpdateAction { |
||||||
|
|
||||||
|
public RemoveAction() { |
||||||
|
this.setName(Toolkit.i18nText("Fine-Design_Basic_Remove")); |
||||||
|
this.setMnemonic('R'); |
||||||
|
this.setSmallIcon(BaseUtils.readIcon(IconPathConstants.TD_REMOVE_ICON_PATH)); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void actionPerformed(ActionEvent e) { |
||||||
|
NameObject selectedNO = dataTree.getRealSelectedNameObject(); |
||||||
|
|
||||||
|
if (selectedNO == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
int returnVal = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Utils_Are_You_Sure_To_Remove_The_Selected_Item") + ":" + selectedNO.getName() + "?", |
||||||
|
Inter.getLocText("FR-Designer_Remove"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); |
||||||
|
if (returnVal == JOptionPane.OK_OPTION) { |
||||||
|
op.removeAction(selectedNO.getName()); |
||||||
|
dataTree.deleteNodeToMoveFromParent((ExpandMutableTreeNode) dataTree.getLastSelectedPathComponent()); |
||||||
|
dataTree.refresh(); |
||||||
|
dataTree.requestFocus(); |
||||||
|
dataTree.setSelectionRow(dataTree.getRowCount() - 1); |
||||||
|
fireDSChanged(); |
||||||
|
checkButtonEnabled(); |
||||||
|
DesignTableDataManager.removeSelectedColumnNames(selectedNO.getName()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void populate(TableDataSourceOP op) { |
||||||
|
this.op = op; |
||||||
|
dataTree.populate(op,null); |
||||||
|
checkButtonEnabled(); |
||||||
|
} |
||||||
|
|
||||||
|
public TableDataSourceOP getOp(){ |
||||||
|
return op; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public TableDataTree getDataTree() { |
||||||
|
return dataTree; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 合并数据集 |
||||||
|
* @param srcName 数据集来源(比如报表块,就是报表块的名称) |
||||||
|
* @param tableDataSource 数据集 |
||||||
|
*/ |
||||||
|
public Map<String, String> addTableData(String srcName, TableDataSource tableDataSource,boolean var) { |
||||||
|
Map<String, String> tdNameMap = new HashMap<String,String>(); |
||||||
|
allDSNames = DesignTableDataManager.getAllDSNames(tc.getBook()); |
||||||
|
DesignTableDataManager.setThreadLocal(DesignTableDataManager.NO_PARAMETER); |
||||||
|
TableDataSource tds = tc.getBook(); |
||||||
|
Iterator tdIterator = tableDataSource.getTableDataNameIterator(); |
||||||
|
while (tdIterator.hasNext()) { |
||||||
|
String tdName = (String) tdIterator.next(); |
||||||
|
String oldName = tdName; |
||||||
|
TableData td = tableDataSource.getTableData(tdName); |
||||||
|
boolean var1 = this.isDsNameRepeaded(tdName); |
||||||
|
tdName= BasicTableDataUtils.getTableDataName(var,tds,tdName,srcName,var1); |
||||||
|
tds.putTableData(tdName, td); |
||||||
|
if (!ComparatorUtils.equals(oldName, tdName)) { |
||||||
|
tdNameMap.put(oldName, tdName); |
||||||
|
} |
||||||
|
} |
||||||
|
tc.parameterChanged(); |
||||||
|
dataTree.refresh(); |
||||||
|
return Collections.unmodifiableMap(tdNameMap); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void addDataPane(AbstractTableDataPane<?> abstractTableDataPane, String s) { |
||||||
|
NamePane namePane=abstractTableDataPane.asNamePane(); |
||||||
|
namePane.setObjectName(s); |
||||||
|
this.allDSNames = DesignTableDataManager.getAllDSNames(this.tc.getBook()); |
||||||
|
DesignTableDataManager.setThreadLocal(DesignTableDataManager.NO_PARAMETER); |
||||||
|
this.tc.renameTableData(s, namePane.getObjectName(), false); |
||||||
|
BaseBook book = this.tc.getBook(); |
||||||
|
TableData td = (TableData)abstractTableDataPane.updateBean(); |
||||||
|
if (td instanceof TableDataSourceDependent) { |
||||||
|
((TableDataSourceDependent)td).setTableDataSource(book); |
||||||
|
} |
||||||
|
|
||||||
|
String oName = namePane.getObjectName(); |
||||||
|
book.putTableData(oName, td); |
||||||
|
HashMap tdMap = new HashMap(); |
||||||
|
if (!ComparatorUtils.equals(s, oName)) { |
||||||
|
tdMap.put(s, oName); |
||||||
|
} |
||||||
|
|
||||||
|
this.fireDSChanged(tdMap); |
||||||
|
this.tc.fireTargetModified(); |
||||||
|
this.tc.parameterChanged(); |
||||||
|
int[] rows = this.dataTree.getSelectionRows(); |
||||||
|
this.dataTree.refreshChildByName(oName); |
||||||
|
this.dataTree.setSelectionRows(rows); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void removeTableData(String tdName) { |
||||||
|
BaseBook book = this.tc.getBook(); |
||||||
|
book.removeTableData(tdName); |
||||||
|
this.dataTree.refresh(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,57 @@ |
|||||||
|
package com.fr.plugins.dsgroup; |
||||||
|
|
||||||
|
import com.fr.base.TableData; |
||||||
|
import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane; |
||||||
|
import com.fr.design.fun.ServerTableDataDefineProvider; |
||||||
|
import com.fr.design.fun.impl.AbstractTableDataDefineProvider; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.plugin.transform.ExecuteFunctionRecord; |
||||||
|
import com.fr.plugin.transform.FunctionRecorder; |
||||||
|
import com.fr.plugins.dsgroup.fun.DSGroupTableData; |
||||||
|
import com.fr.plugins.dsgroup.ui.DSGroupPane; |
||||||
|
import com.fr.stable.fun.FunctionHelper; |
||||||
|
import com.fr.stable.fun.FunctionProcessor; |
||||||
|
import com.fr.stable.fun.impl.AbstractFunctionProcessor; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by phetran_ye on 2018/9/25. |
||||||
|
*/ |
||||||
|
@FunctionRecorder |
||||||
|
public class DSGroupDefine extends AbstractTableDataDefineProvider implements ServerTableDataDefineProvider { |
||||||
|
|
||||||
|
@Override |
||||||
|
@ExecuteFunctionRecord |
||||||
|
public Class<? extends TableData> classForTableData() { |
||||||
|
//return null;
|
||||||
|
return DSGroupTableData.class; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Class<? extends TableData> classForInitTableData() { |
||||||
|
//return null;
|
||||||
|
return DSGroupTableData.class; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Class<? extends AbstractTableDataPane> appearanceForTableData() { |
||||||
|
return DSGroupPane.class; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String nameForTableData() { |
||||||
|
return Inter.getLocText("Data_Set_Group"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String prefixForTableData() { |
||||||
|
return "group"; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public String iconPathForTableData() { |
||||||
|
return "/com/fr/plugins/dsgroup/ui/images/query.png"; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
package com.fr.plugins.dsgroup; |
||||||
|
|
||||||
|
import com.fr.stable.fun.impl.AbstractLocaleFinder; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by phetran_ye on 2018/8/7. |
||||||
|
*/ |
||||||
|
public class LocaleFinder extends AbstractLocaleFinder { |
||||||
|
@Override |
||||||
|
|
||||||
|
public int currentAPILevel() { |
||||||
|
return CURRENT_LEVEL; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
|
||||||
|
public String find() { |
||||||
|
return "com/fr/plugins/dsgroup/locale/locale"; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,53 @@ |
|||||||
|
package com.fr.plugins.dsgroup; |
||||||
|
|
||||||
|
import com.fr.base.BaseUtils; |
||||||
|
|
||||||
|
import com.fr.design.DesignModelAdapter; |
||||||
|
import com.fr.design.actions.server.GlobalTableDataAction; |
||||||
|
import com.fr.design.data.BasicTableDataTreePane; |
||||||
|
import com.fr.design.data.datapane.TableDataPaneController; |
||||||
|
import com.fr.design.data.datapane.TableDataPaneListPane; |
||||||
|
import com.fr.design.data.datapane.TableDataSourceOP; |
||||||
|
import com.fr.design.data.datapane.TableDataTreePane; |
||||||
|
import com.fr.design.designer.TargetComponent; |
||||||
|
import com.fr.design.fun.impl.AbstractTDPaneProcessor; |
||||||
|
import com.fr.design.gui.imenu.UIMenu; |
||||||
|
import com.fr.design.mainframe.WestRegionContainerPane; |
||||||
|
import com.fr.design.menu.ShortCut; |
||||||
|
import com.fr.general.Inter; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import java.lang.reflect.Field; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Created by phetran_ye on 2018/8/8. |
||||||
|
*/ |
||||||
|
public class TableDataPaneProcessorImpl extends AbstractTDPaneProcessor { |
||||||
|
|
||||||
|
@Override |
||||||
|
public BasicTableDataTreePane createTableDataTreePane(DesignModelAdapter<?, ?> tc) { |
||||||
|
return CustomTableDataTreePane.getInstance(tc); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public TableDataPaneController createServerTableDataPane(DesignModelAdapter<?, ?> tc) { |
||||||
|
return new CustomTableDataPaneListPane(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public ShortCut createServerTDAction() { |
||||||
|
return new GlobalTableDataAction(); |
||||||
|
} |
||||||
|
|
||||||
|
/* @Override |
||||||
|
public int layerIndex() { |
||||||
|
return 3; |
||||||
|
}*/ |
||||||
|
|
||||||
|
@Override |
||||||
|
public int currentAPILevel() { |
||||||
|
return CURRENT_LEVEL; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,121 @@ |
|||||||
|
package com.fr.plugins.dsgroup.fun; |
||||||
|
|
||||||
|
|
||||||
|
import com.fr.config.holder.Conf; |
||||||
|
import com.fr.config.holder.impl.SimConf; |
||||||
|
import com.fr.data.AbstractParameterTableData; |
||||||
|
import com.fr.design.mainframe.WestRegionContainerPane; |
||||||
|
import com.fr.general.data.DataModel; |
||||||
|
import com.fr.script.Calculator; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
import com.fr.stable.xml.XMLPrintWriter; |
||||||
|
import com.fr.stable.xml.XMLableReader; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by richie on 2016/10/8. |
||||||
|
*/ |
||||||
|
public class DSGroupTableData extends AbstractParameterTableData { |
||||||
|
|
||||||
|
private static final String XML_ATTR_TAG = "QueryTableDataAttr"; |
||||||
|
|
||||||
|
private static String separator="&;"; |
||||||
|
private Conf<String> attrParentDSName=new SimConf<String>(""); |
||||||
|
private Conf<String> attrChildrenDSNames=new SimConf<String>(""); |
||||||
|
|
||||||
|
public Conf<String> getAttrParentDSName() { |
||||||
|
return attrParentDSName; |
||||||
|
} |
||||||
|
|
||||||
|
public void setAttrParentDSName(Conf<String> attrParentDSName) { |
||||||
|
this.attrParentDSName = attrParentDSName; |
||||||
|
} |
||||||
|
|
||||||
|
public Conf<String> getAttrChildrenDSNames() { |
||||||
|
return attrChildrenDSNames; |
||||||
|
} |
||||||
|
|
||||||
|
public void setAttrChildrenDSNames(Conf<String> attrChildrenDSNames) { |
||||||
|
this.attrChildrenDSNames = attrChildrenDSNames; |
||||||
|
} |
||||||
|
|
||||||
|
public static String getSeparator() { |
||||||
|
return separator; |
||||||
|
} |
||||||
|
|
||||||
|
public String getChildrenDSNames() { |
||||||
|
return attrChildrenDSNames.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setChildrenDSNames(String childrenDSNames) { |
||||||
|
this.attrChildrenDSNames = new SimConf<String>(childrenDSNames); |
||||||
|
} |
||||||
|
|
||||||
|
public String getParentDSName() { |
||||||
|
return attrParentDSName.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setParentDSName(String parentDSName) { |
||||||
|
this.attrParentDSName = new SimConf<String>(parentDSName); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*public DSGroupTableData() { |
||||||
|
processParameters(); |
||||||
|
}*/ |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public DataModel createDataModel(Calculator calculator) { |
||||||
|
//return new QueryDataModel(processParameters(calculator));
|
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/* @Override |
||||||
|
public ParameterProvider[] getParameters(Calculator c) { |
||||||
|
processParameters(); |
||||||
|
return super.getParameters(c); |
||||||
|
} |
||||||
|
|
||||||
|
private void processParameters() { |
||||||
|
if (this.parameters == null && StringUtils.isNotEmpty(text)) { |
||||||
|
this.parameters = ParameterHelper.analyze4Parameters(text, false); |
||||||
|
} |
||||||
|
}*/ |
||||||
|
|
||||||
|
/*@Override |
||||||
|
protected ParameterProvider[] processParameters(Calculator calculator) { |
||||||
|
processParameters(); |
||||||
|
return Calculator.processParameters(calculator, this.parameters); |
||||||
|
}*/ |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public void readXML(XMLableReader reader) { |
||||||
|
super.readXML(reader); |
||||||
|
if (reader.isChildNode()) { |
||||||
|
String tagName = reader.getTagName(); |
||||||
|
if (tagName.equals(XML_ATTR_TAG)) { |
||||||
|
attrParentDSName = new SimConf<String>(reader.getAttrAsString("parent_DS_name", StringUtils.EMPTY)); |
||||||
|
attrChildrenDSNames = new SimConf<String>(reader.getAttrAsString("children_DS_names", StringUtils.EMPTY)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void writeXML(XMLPrintWriter writer) { |
||||||
|
super.writeXML(writer); |
||||||
|
writer.startTAG(XML_ATTR_TAG); |
||||||
|
writer.attr("parent_DS_name", attrParentDSName.get()); |
||||||
|
writer.attr("children_DS_names", attrChildrenDSNames.get()); |
||||||
|
writer.end(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object clone() throws CloneNotSupportedException { |
||||||
|
DSGroupTableData cloned = (DSGroupTableData)super.clone(); |
||||||
|
cloned.setAttrParentDSName(attrParentDSName); |
||||||
|
cloned.setAttrChildrenDSNames(attrChildrenDSNames); |
||||||
|
return cloned; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
Plugin-Data_Set_Group=Data Set Group |
||||||
|
Data_Set_Group=Data Set Group |
||||||
|
Default_Group_Name=unnamed group |
||||||
|
Template=Template |
||||||
|
DS-TableData=DS-TableData |
||||||
|
DS-Server_TableData=DS-Server_TableData |
||||||
|
FR-Designer_Edit=FR-Designer_Edit |
||||||
|
FR-Designer_Remove=FR-Designer_Remove |
||||||
|
Utils-Are_you_sure_to_remove_the_selected_item=Are you sure to remove the selected item |
@ -0,0 +1,9 @@ |
|||||||
|
Plugin-Data_Set_Group=Data Set Group |
||||||
|
Data_Set_Group=Data Set Group |
||||||
|
Default_Group_Name=unnamed group |
||||||
|
Template=Template |
||||||
|
DS-TableData=DS-TableData |
||||||
|
DS-Server_TableData=DS-Server_TableData |
||||||
|
FR-Designer_Edit=FR-Designer_Edit |
||||||
|
FR-Designer_Remove=FR-Designer_Remove |
||||||
|
Utils-Are_you_sure_to_remove_the_selected_item=Are you sure to remove the selected item |
@ -0,0 +1,9 @@ |
|||||||
|
Plugin-Data_Set_Group=\u6570\u636e\u96c6\u5206\u7ec4 |
||||||
|
Data_Set_Group=\u6570\u636e\u96c6\u5206\u7ec4 |
||||||
|
Default_Group_Name=\u672a\u547d\u540d\u5206\u7ec4 |
||||||
|
Template=\u6a21\u677f |
||||||
|
DS-TableData=\u6570\u636e\u96c6 |
||||||
|
DS-Server_TableData=\u670d\u52a1\u5668\u6570\u636e\u96c6 |
||||||
|
FR-Designer_Edit=\u7f16\u8f91 |
||||||
|
FR-Designer_Remove=\u5220\u9664 |
||||||
|
Utils-Are_you_sure_to_remove_the_selected_item=\u4f60\u786e\u5b9e\u51b3\u5b9a\u5220\u9664\u9009\u4e2d\u7684\u9879 |
@ -0,0 +1,108 @@ |
|||||||
|
package com.fr.plugins.dsgroup.ui; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by phetran_ye on 2018/8/7. |
||||||
|
*/ |
||||||
|
import com.fr.base.BaseUtils; |
||||||
|
import com.fr.design.ExtraDesignClassManager; |
||||||
|
import com.fr.design.actions.UpdateAction; |
||||||
|
import com.fr.design.data.datapane.preview.PreviewTablePane; |
||||||
|
import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane; |
||||||
|
import com.fr.design.fun.TableDataPaneProcessor; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.gui.itextfield.UITextField; |
||||||
|
import com.fr.design.gui.itoolbar.UIToolbar; |
||||||
|
import com.fr.design.layout.TableLayout; |
||||||
|
import com.fr.design.layout.TableLayoutHelper; |
||||||
|
import com.fr.design.mainframe.WestRegionContainerPane; |
||||||
|
import com.fr.design.menu.ToolBarDef; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.plugins.dsgroup.fun.DSGroupTableData; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import java.awt.*; |
||||||
|
import java.awt.event.ActionEvent; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by richie on 2016/10/8. |
||||||
|
*/ |
||||||
|
public class DSGroupPane extends AbstractTableDataPane<DSGroupTableData> { |
||||||
|
|
||||||
|
//private static final String PREVIEW_BUTTON = Inter.getLocText("Preview");
|
||||||
|
|
||||||
|
|
||||||
|
private UITextField contentTextField; |
||||||
|
private DSGroupTableData tableData; |
||||||
|
|
||||||
|
|
||||||
|
public DSGroupPane() { |
||||||
|
WestRegionContainerPane wp=WestRegionContainerPane.getInstance(); |
||||||
|
setLayout(new BorderLayout()); |
||||||
|
//add(createToolBar(), BorderLayout.NORTH);
|
||||||
|
JPanel contentPane = new JPanel(); |
||||||
|
JLabel infoLbl=new JLabel(); |
||||||
|
String info="<html><body>提示:<br>"; |
||||||
|
info+="1.选中分组,然后添加数据集即可在该分组下添加数据集。<br>"; |
||||||
|
info+="2.拖动数据集到某分组上即可将数据集添加到该分组下。<br>"; |
||||||
|
info+="3.拖动数据集到数据集面板空白处即可将该数据集移到最外部。<br> </body></html>"; |
||||||
|
infoLbl.setText(info); |
||||||
|
String ss="你好"; |
||||||
|
contentPane.setLayout(new BorderLayout()); |
||||||
|
contentPane.add(infoLbl, BorderLayout.NORTH); |
||||||
|
add(contentPane, BorderLayout.CENTER); |
||||||
|
//addChildrenToParent(contentPane);
|
||||||
|
} |
||||||
|
|
||||||
|
/*private JToolBar createToolBar() { |
||||||
|
ToolBarDef toolBarDef = new ToolBarDef(); |
||||||
|
//toolBarDef.addShortCut(new PreviewQueryTableDataAction());
|
||||||
|
UIToolbar editToolBar = ToolBarDef.createJToolBar(); |
||||||
|
toolBarDef.updateToolBar(editToolBar); |
||||||
|
return editToolBar; |
||||||
|
}*/ |
||||||
|
|
||||||
|
/* private void addChildrenToParent(JPanel contentPane) { |
||||||
|
double p = TableLayout.PREFERRED; |
||||||
|
double f = TableLayout.FILL; |
||||||
|
double[] rowSize = {p}; |
||||||
|
double[] columnSize = {p, f}; |
||||||
|
|
||||||
|
JPanel panel = TableLayoutHelper.createTableLayoutPane(new Component[][]{ |
||||||
|
{new UILabel("名字"), contentTextField = new UITextField()} |
||||||
|
}, rowSize, columnSize); |
||||||
|
contentPane.add(panel, BorderLayout.CENTER); |
||||||
|
}*/ |
||||||
|
|
||||||
|
@Override |
||||||
|
public void populateBean(DSGroupTableData ob) { |
||||||
|
/*if (ob != null) { |
||||||
|
contentTextField.setText(ob.getText()); |
||||||
|
}*/ |
||||||
|
tableData=ob; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public DSGroupTableData updateBean() { |
||||||
|
//DSGroupTableData tableData = new DSGroupTableData();
|
||||||
|
//tableData.setText(contentTextField.getText());
|
||||||
|
return tableData; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
|
return Inter.getLocText("Data_Set_Group"); |
||||||
|
} |
||||||
|
|
||||||
|
/*private class PreviewQueryTableDataAction extends UpdateAction { |
||||||
|
public PreviewQueryTableDataAction() { |
||||||
|
this.setName(PREVIEW_BUTTON); |
||||||
|
this.setMnemonic('P'); |
||||||
|
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/preview.png")); |
||||||
|
} |
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent evt) { |
||||||
|
PreviewTablePane.previewTableData(DSGroupPane.this.updateBean()); |
||||||
|
} |
||||||
|
}*/ |
||||||
|
} |
||||||
|
|
After Width: | Height: | Size: 215 B |
Loading…
Reference in new issue