📄 connectionstreepanel.java
字号:
/** * Returns the database connection associated with the specified path. * * @return the connection properties object */ protected DatabaseConnection getConnectionAt(TreePath path) { if (path != null) { Object object = path.getLastPathComponent(); if (object instanceof BrowserTreeNode) { return getDatabaseConnection((BrowserTreeNode)object); } } return null; } /** * Removes the tree listener. */ protected void removeTreeListener() { tree.removeTreeSelectionListener(this); } /** * Adds the tree listener. */ protected void addTreeListener() { tree.addTreeSelectionListener(this); } /** * Selects the specified node. */ protected void setNodeSelected(DefaultMutableTreeNode node) { TreePath path = new TreePath(node.getPath()); tree.setSelectionPath(path); } /** * Removes the selected tree node (database object) from the tree. */ public void removeSelectedNode() { // remove the listener tree.removeTreeSelectionListener(this); // store the current row int row = tree.getSelectionRows()[0]; // retrieve the current selection node BrowserTreeNode node = (BrowserTreeNode)tree.getLastPathComponent(); tree.removeNode(node); // add listener and select row above tree.addTreeSelectionListener(this); row = (row == 0 ? 1 : row - 1); tree.setSelectionRow(row); } /** * Creates a new connection and adds it to the bottom * of the list. */ public void newConnection() { newConnection(null); } /** * Creates a new connection based on the specified connection. * * @param dc - the connection the new one is to be based on */ public void newConnection(DatabaseConnection dc) { if (dc == null) { String name = buildConnectionName("New Connection"); dc = new DatabaseConnection(name); } ConnectionObject metaObject = new ConnectionObject(dc); connections.add(dc); BrowserTreeNode node = new BrowserTreeNode(metaObject, true); tree.addToRoot(node); } /** * Moves the selected connection (host node) down in the list. */ public void moveConnectionDown() { tree.moveSelectionDown(); // adjust the position of the connection Object object = tree.getLastPathComponent(); moveNode((BrowserTreeNode)object, DynamicTree.MOVE_DOWN); } private void moveNode(BrowserTreeNode node, int direction) { ConnectionObject metaObject = (ConnectionObject)node.getDatabaseUserObject(); DatabaseConnection dc = metaObject.getDatabaseConnection(); int currentIndex = connections.indexOf(dc); if (currentIndex == 0 && direction == DynamicTree.MOVE_UP) { return; } int newIndex = -1; if (direction == DynamicTree.MOVE_UP) { newIndex = currentIndex - 1; } else { newIndex = currentIndex + 1; if (newIndex > (connections.size() - 1)) { return; } } connections.remove(currentIndex); connections.insertElementAt(dc, newIndex); // save the connections //viewPanel.saveConnections(); } /** * Indicates that a node name has changed and fires a call * to repaint the tree display. */ protected void nodeNameValueChanged(ConnectionObject metaObject) { TreeNode node = tree.getNodeFromRoot(metaObject); if (node != null) { tree.nodeChanged(node); } } /** * Ensures we have a browser panel and that it is visible. */ private void checkBrowserPanel() { controller.checkBrowserPanel(); } /** * Override min size for split pane insertion. * * @return the enforced minimum size */ /* public Dimension getMinimumSize() { return new Dimension(250, 80); } */ /** * Returns the currently selected node's user object where the * node is a BrowserTreeNode and the user object is a DatabaseObject. * If the above is not met, null is returned. * * @return the user object of the selected node where the * user object is a DatabaseObject */ protected BrowserTreeNode getSelectedBrowserNode() { // if path is null return null if (tree.isSelectionEmpty()) { return null; } // make sure we have a BrowserTreeNode Object object = tree.getLastPathComponent(); if (!(object instanceof BrowserTreeNode)) { return null; } return (BrowserTreeNode)object; } /** * Returns the whether the currently selected node's user object * is a parent type where the node is a BrowserTreeNode and the * user object is a DatabaseObject. If the above is not met, false is * returned, otherwise the object is evaluated. * * @return true | false */ protected boolean isTypeParentSelected() { // if path is null return null if (tree.isSelectionEmpty()) { return false; } // make sure we have a BrowserTreeNode Object object = tree.getLastPathComponent(); if (!(object instanceof BrowserTreeNode)) { return false; } // return the parent connection meta object return ((BrowserTreeNode)object).isTypeParent(); } /** * Returns the currently selected node's user object where the * node is a BrowserTreeNode and the user object is a DatabaseObject. * If the above is not met, null is returned. * * @return the user object of the selected node where the * user object is a DatabaseObject */ protected DatabaseObject getSelectedDatabaseObject() { // if path is null return null if (tree.isSelectionEmpty()) { return null; } // make sure we have a BrowserTreeNode Object object = tree.getLastPathComponent(); if (!(object instanceof BrowserTreeNode)) { return null; } // return the parent connection meta object BrowserTreeNode node = (BrowserTreeNode)object; return node.getDatabaseUserObject(); } /** * Returns the selected meta object host node. * * @return the selected host node meta object */ protected ConnectionObject getSelectedMetaObject() { // if path is null return null if (tree.isSelectionEmpty()) { return null; } // make sure we have a BrowserTreeNode Object object = tree.getLastPathComponent(); if (!(object instanceof BrowserTreeNode)) { return null; } // return the parent connection meta object BrowserTreeNode node = (BrowserTreeNode)object; BrowserTreeNode parent = getParentNode(node); return ((ConnectionObject)parent.getDatabaseUserObject()); } /** * Returns the selected database connection. * * @return the selected connection properties object */ public DatabaseConnection getSelectedDatabaseConnection() { ConnectionObject object = getSelectedMetaObject(); if (object != null) { return object.getDatabaseConnection(); } return null; } // ------------------------------------------ // ConnectionListner implementation // ------------------------------------------ /** * Indicates a connection has been established. * * @param the encapsulating event */ public void connected(ConnectionEvent connectionEvent) { DatabaseConnection dc = connectionEvent.getSource(); BrowserTreeNode node = getParentConnectionNode(dc); ConnectionObject metaObject = (ConnectionObject)node.getDatabaseUserObject(); TreePath path = new TreePath(node.getPath()); TreeExpansionEvent _e = new TreeExpansionEvent(tree, path); treeExpanded(_e); tree.nodeStructureChanged(node); } /** * Indicates a connection has been closed. * * @param the encapsulating event */ public void disconnected(ConnectionEvent connectionEvent) { DatabaseConnection dc = connectionEvent.getSource(); BrowserTreeNode node = getParentConnectionNode(dc); node.setExpanded(false); node.removeAllChildren(); tree.nodeStructureChanged(node); // check if we select the root node if (rootSelectOnDisconnect) { tree.setSelectionRow(0); } // otherwise select the host node else { tree.setSelectionPath(new TreePath(node.getPath())); } } // ------------------------------------------ /** * Returns the previosuly selected path before the current * selection. * * @return the previous path */ protected TreePath getOldSelectionPath() { return oldSelectionPath; } /** * Returns the previously selected browse node before the * current selection. * * @return the previous node selection */ protected BrowserTreeNode getOldBrowserNodeSelection() { Object object = getOldSelectionPath().getLastPathComponent(); if (object != null && object instanceof BrowserTreeNode) { return (BrowserTreeNode)object; } return null; } protected BrowserTreeNode getParentConnectionNode(DatabaseConnection dc) { for (Enumeration i = tree.getRootNode().children(); i.hasMoreElements();) { Object object = i.nextElement(); if (object instanceof BrowserTreeNode) { BrowserTreeNode node = (BrowserTreeNode)object; object = node.getUserObject(); if (object instanceof ConnectionObject) { ConnectionObject conn = (ConnectionObject)object; if (conn.getDatabaseConnection() == dc) { return node; } } } } return null; } /** * Notification that the currently selected node (a host) * has had their associated db connection closed. */ protected void selectedNodeDisconnected() { Object object = tree.getLastPathComponent(); if (!(object instanceof BrowserTreeNode)) { return; } // remove all choldren from the host node // of the current path BrowserTreeNode node = (BrowserTreeNode)object; if (!(node.getUserObject() instanceof ConnectionObject)) { node = getParentNode(node); } node.setExpanded(false); BrowserTreeNode parent = getParentNode(node); parent.removeAllChildren(); tree.nodeStructureChanged(parent); } /** * Notification that the currently selected node (a host) * has had their associated db connection created. */ protected void selectedNodeConnected() { if (tree.isSelectionEmpty()) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -