From 5f356c1266e7f53add6ba2a46a65f0659edf2ea9 Mon Sep 17 00:00:00 2001 From: phetran_ye <844055991@qq.com> Date: Sun, 25 Apr 2021 09:43:59 +0800 Subject: [PATCH] first commit --- .../dsgroup/CustomTableDataPaneListPane.java | 84 +++ .../plugins/dsgroup/CustomTableDataTree.java | 504 ++++++++++++++++++ .../CustomTableDataTreeDragSource.java | 251 +++++++++ .../dsgroup/CustomTableDataTreePane.java | 448 ++++++++++++++++ .../com/fr/plugins/dsgroup/DSGroupDefine.java | 57 ++ .../com/fr/plugins/dsgroup/LocaleFinder.java | 21 + .../dsgroup/TableDataPaneProcessorImpl.java | 53 ++ .../plugins/dsgroup/fun/DSGroupTableData.java | 121 +++++ .../plugins/dsgroup/locale/locale.properties | 9 + .../dsgroup/locale/locale_en_US.properties | 9 + .../dsgroup/locale/locale_zh_CN.properties | 9 + .../fr/plugins/dsgroup/ui/DSGroupPane.java | 108 ++++ .../fr/plugins/dsgroup/ui/images/query.png | Bin 0 -> 215 bytes 13 files changed, 1674 insertions(+) create mode 100644 src/main/java/com/fr/plugins/dsgroup/CustomTableDataPaneListPane.java create mode 100644 src/main/java/com/fr/plugins/dsgroup/CustomTableDataTree.java create mode 100644 src/main/java/com/fr/plugins/dsgroup/CustomTableDataTreeDragSource.java create mode 100644 src/main/java/com/fr/plugins/dsgroup/CustomTableDataTreePane.java create mode 100644 src/main/java/com/fr/plugins/dsgroup/DSGroupDefine.java create mode 100644 src/main/java/com/fr/plugins/dsgroup/LocaleFinder.java create mode 100644 src/main/java/com/fr/plugins/dsgroup/TableDataPaneProcessorImpl.java create mode 100644 src/main/java/com/fr/plugins/dsgroup/fun/DSGroupTableData.java create mode 100644 src/main/java/com/fr/plugins/dsgroup/locale/locale.properties create mode 100644 src/main/java/com/fr/plugins/dsgroup/locale/locale_en_US.properties create mode 100644 src/main/java/com/fr/plugins/dsgroup/locale/locale_zh_CN.properties create mode 100644 src/main/java/com/fr/plugins/dsgroup/ui/DSGroupPane.java create mode 100644 src/main/java/com/fr/plugins/dsgroup/ui/images/query.png diff --git a/src/main/java/com/fr/plugins/dsgroup/CustomTableDataPaneListPane.java b/src/main/java/com/fr/plugins/dsgroup/CustomTableDataPaneListPane.java new file mode 100644 index 0000000..7c9f91b --- /dev/null +++ b/src/main/java/com/fr/plugins/dsgroup/CustomTableDataPaneListPane.java @@ -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 changedDatas=new HashMap(); + //为更改名称 + 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 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(); + } + + + } diff --git a/src/main/java/com/fr/plugins/dsgroup/CustomTableDataTree.java b/src/main/java/com/fr/plugins/dsgroup/CustomTableDataTree.java new file mode 100644 index 0000000..b74dd72 --- /dev/null +++ b/src/main/java/com/fr/plugins/dsgroup/CustomTableDataTree.java @@ -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 childTreeNodeList = new java.util.ArrayList(); + 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 > 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 treeNodeMap=new HashMap(); + Map preloadTreeNodeMap=new HashMap(); + 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 en:preloadTreeNodeMap.entrySet()){ + root.add(en.getValue()); + } + } + + private void loadDSGroupTreeNode(ExpandMutableTreeNode groupNode,Map nodes,Map 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 tableDatasd=tableDataConfig.getTableDatas(); + tableDataConfig.removeAllTableData(); + Map tableDataMap = new LinkedHashMap(); + + tableDataMap.put(((NameObject) groupToMoveTo.getUserObject()).getName(), + (TableData) ((TableDataWrapper) ((NameObject) groupToMoveTo.getUserObject()).getObject()).getTableData() + ); + + tableDataConfig.setTableDatas(tableDataMap); + Map tableDatas=tableDataConfig.getTableDatas();*/ + //end + + + + String children=getGroupData(groupToMoveTo).getChildrenDSNames(); + TreePath[] paths=getSelectionPaths(); + String chosenChildren=""; + //将选择的节点拼成子节点数据,以防止选择了分组又选择了其下的数据集 + for(int i=0;i-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 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-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-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); + } + } + } + } + +} diff --git a/src/main/java/com/fr/plugins/dsgroup/CustomTableDataTreeDragSource.java b/src/main/java/com/fr/plugins/dsgroup/CustomTableDataTreeDragSource.java new file mode 100644 index 0000000..1d85c0f --- /dev/null +++ b/src/main/java/com/fr/plugins/dsgroup/CustomTableDataTreeDragSource.java @@ -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 stringList = new ArrayList(); + 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 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 tableAddress = new ArrayList(); + 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;i0 + ) 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()); + + }*/ + + +} diff --git a/src/main/java/com/fr/plugins/dsgroup/CustomTableDataTreePane.java b/src/main/java/com/fr/plugins/dsgroup/CustomTableDataTreePane.java new file mode 100644 index 0000000..029cbf0 --- /dev/null +++ b/src/main/java/com/fr/plugins/dsgroup/CustomTableDataTreePane.java @@ -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 map = new HashMap(); + 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 addTableData(String srcName, TableDataSource tableDataSource,boolean var) { + Map tdNameMap = new HashMap(); + 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(); + } + +} diff --git a/src/main/java/com/fr/plugins/dsgroup/DSGroupDefine.java b/src/main/java/com/fr/plugins/dsgroup/DSGroupDefine.java new file mode 100644 index 0000000..01f6008 --- /dev/null +++ b/src/main/java/com/fr/plugins/dsgroup/DSGroupDefine.java @@ -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 classForTableData() { + //return null; + return DSGroupTableData.class; + } + + @Override + public Class classForInitTableData() { + //return null; + return DSGroupTableData.class; + } + + @Override + public Class 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"; + } + + +} diff --git a/src/main/java/com/fr/plugins/dsgroup/LocaleFinder.java b/src/main/java/com/fr/plugins/dsgroup/LocaleFinder.java new file mode 100644 index 0000000..674f418 --- /dev/null +++ b/src/main/java/com/fr/plugins/dsgroup/LocaleFinder.java @@ -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"; + } + +} diff --git a/src/main/java/com/fr/plugins/dsgroup/TableDataPaneProcessorImpl.java b/src/main/java/com/fr/plugins/dsgroup/TableDataPaneProcessorImpl.java new file mode 100644 index 0000000..4c58c4e --- /dev/null +++ b/src/main/java/com/fr/plugins/dsgroup/TableDataPaneProcessorImpl.java @@ -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; + } + +} diff --git a/src/main/java/com/fr/plugins/dsgroup/fun/DSGroupTableData.java b/src/main/java/com/fr/plugins/dsgroup/fun/DSGroupTableData.java new file mode 100644 index 0000000..d74e080 --- /dev/null +++ b/src/main/java/com/fr/plugins/dsgroup/fun/DSGroupTableData.java @@ -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 attrParentDSName=new SimConf(""); + private Conf attrChildrenDSNames=new SimConf(""); + + public Conf getAttrParentDSName() { + return attrParentDSName; + } + + public void setAttrParentDSName(Conf attrParentDSName) { + this.attrParentDSName = attrParentDSName; + } + + public Conf getAttrChildrenDSNames() { + return attrChildrenDSNames; + } + + public void setAttrChildrenDSNames(Conf 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(childrenDSNames); + } + + public String getParentDSName() { + return attrParentDSName.get(); + } + + public void setParentDSName(String parentDSName) { + this.attrParentDSName = new SimConf(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(reader.getAttrAsString("parent_DS_name", StringUtils.EMPTY)); + attrChildrenDSNames = new SimConf(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; + } +} diff --git a/src/main/java/com/fr/plugins/dsgroup/locale/locale.properties b/src/main/java/com/fr/plugins/dsgroup/locale/locale.properties new file mode 100644 index 0000000..2d29a66 --- /dev/null +++ b/src/main/java/com/fr/plugins/dsgroup/locale/locale.properties @@ -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 \ No newline at end of file diff --git a/src/main/java/com/fr/plugins/dsgroup/locale/locale_en_US.properties b/src/main/java/com/fr/plugins/dsgroup/locale/locale_en_US.properties new file mode 100644 index 0000000..2d29a66 --- /dev/null +++ b/src/main/java/com/fr/plugins/dsgroup/locale/locale_en_US.properties @@ -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 \ No newline at end of file diff --git a/src/main/java/com/fr/plugins/dsgroup/locale/locale_zh_CN.properties b/src/main/java/com/fr/plugins/dsgroup/locale/locale_zh_CN.properties new file mode 100644 index 0000000..c310ca3 --- /dev/null +++ b/src/main/java/com/fr/plugins/dsgroup/locale/locale_zh_CN.properties @@ -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 \ No newline at end of file diff --git a/src/main/java/com/fr/plugins/dsgroup/ui/DSGroupPane.java b/src/main/java/com/fr/plugins/dsgroup/ui/DSGroupPane.java new file mode 100644 index 0000000..a677fd7 --- /dev/null +++ b/src/main/java/com/fr/plugins/dsgroup/ui/DSGroupPane.java @@ -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 { + + //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="提示:
"; + info+="1.选中分组,然后添加数据集即可在该分组下添加数据集。
"; + info+="2.拖动数据集到某分组上即可将数据集添加到该分组下。
"; + info+="3.拖动数据集到数据集面板空白处即可将该数据集移到最外部。
 "; + 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()); + } + }*/ +} + diff --git a/src/main/java/com/fr/plugins/dsgroup/ui/images/query.png b/src/main/java/com/fr/plugins/dsgroup/ui/images/query.png new file mode 100644 index 0000000000000000000000000000000000000000..a186bdee8fd20cbc36493b23f1590752e2851055 GIT binary patch literal 215 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`^E_P~Ln>}1CoEulp!-inDdzj` zpe66hZLP#~{-5{1!0>R_{;7*f_y12mtYo_X^~Wr+l|LW0pG|wX%l@Cz*8Sg@Z@%An zve_^|pLxPZ;nimydYK%Y3wH9XdZx}C$GUa@_2kWwE1s3FEqHsrY=YDtwg-n5oDZ-) z_#&?u^ZWKZCGiFxNj5ft9=9g8D}Rp7oxqV8aPQ#kDIb9pW2(cdCn*dM1)c@;JeOJx PbSZ