public Service getSelectedService() { DefaultMutableTreeNode node = getSelectedNode(); if (node == null || node.getUserObject() == null) return null; if (node.getUserObject() instanceof Service) return (Service)node.getUserObject(); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode)node.getParent(); if (parentNode == null || parentNode.getUserObject() == null) return null; if (parentNode.getUserObject() instanceof Service) return (Service)parentNode.getUserObject(); return null; }
private int countLoops() { DefaultMutableTreeNode treeNode = stack.getLastLeaf(); int counter = 0; if (treeNode.getParent() != null) { // for some unknown reasons the parent of treeNode might be null, // see bug 1597987 // see https://sourceforge.net/p/pmd/bugs/606/ int childCount = treeNode.getParent().getChildCount(); for (int i = 0; i < childCount; i++) { DefaultMutableTreeNode tNode = (DefaultMutableTreeNode) treeNode.getParent().getChildAt(i); PathElement e = (PathElement) tNode.getUserObject(); if (e != null && !e.isPseudoPathElement()) { counter++; } } } return counter; }
private void removeFromTree() { DefaultMutableTreeNode last = stack.getLastLeaf(); if (last == null) { System.out.println("removeFromTree - last == null"); return; } DefaultMutableTreeNode parent = (DefaultMutableTreeNode) last.getParent(); if (parent != null) { // for some unknown reasons parent might be null, see bug 1597987 parent.remove(last); } last = stack.getLastLeaf(); if (last == null || last.getUserObject() == null) { return; } PathElement e = (PathElement) last.getUserObject(); if (e != null && e.isPseudoPathElement()) { this.removeFromTree(); } }
@Override public void actionPerformed(ActionEvent e) { if (checkBoxTree.getSelectionPath() != null) { DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) checkBoxTree.getSelectionPath().getLastPathComponent(); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) selectedNode.getParent(); if (parentNode != null) { DefaultMutableTreeNode immediateSiblingNode = directionUp ? (DefaultMutableTreeNode) parentNode.getChildBefore(selectedNode) : (DefaultMutableTreeNode) parentNode.getChildAfter(selectedNode); if (immediateSiblingNode != null) { parentNode.insert(immediateSiblingNode, parentNode.getIndex(selectedNode)); ((DefaultTreeModel) checkBoxTree.getModel()).nodeStructureChanged(parentNode); checkBoxTree.setSelectionPath(new TreePath(selectedNode.getPath())); } } } } }
protected void addRecordToParent() { TreeNode parent = getParent(); if (parent == null) { return; } ((CategoryNode) parent).addRecordFromChild(); } //--------------------------------------------------------------------------
private void logNode(DefaultMutableTreeNode theTreeNode, String message) { if (!LOGGER.isDebugEnabled()) { return; } DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) theTreeNode.getParent(); Node theNode = (Node) theTreeNode.getUserObject(); Node theParentNode = parentNode == null ? null : (Node) parentNode.getUserObject(); @SuppressWarnings({"unchecked"}) Enumeration<DefaultMutableTreeNode> children = theTreeNode.children(); LOGGER.debug( message + ": " + theNode + ", " + theNode.type + ", parent " + theParentNode + (theParentNode == null ? "" : ", " + theParentNode.type)); while (children.hasMoreElements()) { DefaultMutableTreeNode treeNode = children.nextElement(); Node child = (Node) treeNode.getUserObject(); LOGGER.debug("\t" + child.toString() + ", " + child.type); } }
public void setChildren() { if (!gotChildren) { if (type == NodeType.TABLE) { DefaultMutableTreeNode theParentTreeNode = (DefaultMutableTreeNode) treeNode.getParent(); Node theParentNode = (Node) theParentTreeNode.getUserObject(); // This is a table, parent is a schema List<DbColumn> columns = jdbcMetaData.getAllDbColumns( theParentNode.name, name); for (DbColumn column : columns) { Node columnNode = new Node( column.name, NodeType.COLUMN, treeNode, column); MutableTreeNode columnTreeNode = new DefaultMutableTreeNode(columnNode, false); treeNode.add(columnTreeNode); } } } gotChildren = true; } }
protected void showPopup(CategoryNode node, int x, int y) { JPopupMenu popup = new JPopupMenu(); popup.setSize(150, 400); // // Configure the Popup // if (node.getParent() == null) { popup.add(createRemoveMenuItem()); popup.addSeparator(); } popup.add(createSelectDescendantsMenuItem(node)); popup.add(createUnselectDescendantsMenuItem(node)); popup.addSeparator(); popup.add(createExpandMenuItem(node)); popup.add(createCollapseMenuItem(node)); popup.addSeparator(); popup.add(createPropertiesMenuItem(node)); popup.show(_renderer, x, y); }
@Override public void actionPerformed(ActionEvent e) { Object source = e.getSource(); JCheckBox columnCheckBox = (JCheckBox) source; this.nodeModel.setSelected(columnCheckBox.isSelected()); DefaultTreeModel treeModel = (DefaultTreeModel) MediatorGui.treeDatabase().getModel(); DefaultMutableTreeNode tableNode = (DefaultMutableTreeNode) this.currentTableNode.getParent(); int tableChildCount = treeModel.getChildCount(tableNode); boolean isOneChildSelected = false; for (int i = 0 ; i < tableChildCount ; i++) { DefaultMutableTreeNode currentChild = (DefaultMutableTreeNode) treeModel.getChild(tableNode, i); if (currentChild.getUserObject() instanceof AbstractNodeModel) { AbstractNodeModel columnTreeNodeModel = (AbstractNodeModel) currentChild.getUserObject(); if (columnTreeNodeModel.isSelected()) { isOneChildSelected = true; break; } } } AbstractNodeModel nodeUserObject = (AbstractNodeModel) tableNode.getUserObject(); nodeUserObject.setContainingSelection(isOneChildSelected); }
/** * Removes any inactive nodes from the Category tree. */ protected int removeUnusedNodes() { int count = 0; CategoryNode root = _categoryModel.getRootCategoryNode(); Enumeration enumeration = root.depthFirstEnumeration(); while (enumeration.hasMoreElements()) { CategoryNode node = (CategoryNode) enumeration.nextElement(); if (node.isLeaf() && node.getNumberOfContainedRecords() == 0 && node.getParent() != null) { _categoryModel.removeNodeFromParent(node); count++; } } return count; }
@Override public void previousHierarchyLevel() { if (parent != null) { currentNode = parent; parent = (DefaultMutableTreeNode) parent.getParent(); } }
String result = "\n"; Enumeration<?> enumer = root.preorderEnumeration(); while (enumer.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) enumer.nextElement(); String nodeValue = String.valueOf(node.getUserObject()); String indent = ""; while (node.getParent() != null) { indent += " "; node = (DefaultMutableTreeNode) node.getParent(); } result += indent + nodeValue + "\n"; }
/** * @param clazz */ Container getParentComponent(final DefaultMutableTreeNode child, final Class<?> clazz) { final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) child.getParent(); return getContainer(parent, clazz); }
protected void addRecordToParent() { TreeNode parent = getParent(); if (parent == null) { return; } ((CategoryNode) parent).addRecordFromChild(); } //--------------------------------------------------------------------------
protected void addRecordToParent() { TreeNode parent = getParent(); if (parent == null) { return; } ((CategoryNode) parent).addRecordFromChild(); } //--------------------------------------------------------------------------
public void removeFolder(DefaultMutableTreeNode node) { ArrayList<WhereConditionColumnWrapper> allChildCols = getAllChildCols(node); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); parent.remove(node); for (WhereConditionColumnWrapper col : allChildCols) { parent.add(new DefaultMutableTreeNode(col)); } } }
public void invertExpand(DefaultMutableTreeNode node) { if (node.isLeaf()) node = (DefaultMutableTreeNode) node.getParent(); TreePath path = new TreePath(node.getPath()); // no better way to get TreePath from TreeNode :( if (isExpanded(path)) { collapsePath(path); } else { expandPath(path); } }
public void removePackage(Object[]path){ DefaultMutableTreeNode dmn=this.getPath(path); for (int k=0;k<path.length;k++){ System.err.print(path[k].toString()+","); } if (dmn.getParent()!=null){ dmn.removeFromParent(); this.reload(); } else System.err.println("null package"); }
protected Component getPrevious(final DefaultMutableTreeNode childNode) { final DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) childNode.getParent(); if (parentNode == null || parentNode.getUserObject() == null) { return null; } final int childNodeIndex = parentNode.getIndex(childNode); final Component c = getPrevious(parentNode, childNodeIndex - 1); if (c == null) { return getPrevious(parentNode); } return c; }