/** * Support the subscript operator for TreeNode. * * @param self a TreeNode * @param index the index of the child node to get * @return the child node at the given index * @since 1.6.4 */ public static TreeNode getAt(TreeNode self, int index) { return self.getChildAt(index); }
@Override public void treeExpanded(final TreeExpansionEvent event) { final TreePath treePath = event.getPath(); final Object expandedTreePathObject = treePath.getLastPathComponent(); if (!(expandedTreePathObject instanceof TreeNode)) { return; } final TreeNode expandedTreeNode = (TreeNode) expandedTreePathObject; if (expandedTreeNode.getChildCount() == 1) { final TreeNode descendantTreeNode = expandedTreeNode.getChildAt(0); if (descendantTreeNode.isLeaf()) { return; } final TreePath nextTreePath = treePath.pathByAddingChild(descendantTreeNode); tree.expandPath(nextTreePath); } }
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; }
final TreeNode child = node.getChildAt(0); if (child.isLeaf()) { buffer.append(' ').append(child).append(lineSeparator); final TreeNode child = node.getChildAt(i); if (i == 0) { buffer.append(lineSeparator);
/** * Expand the given tree to the given level, starting from the given node * and path. * * @param tree The tree to be expanded * @param node The node to start from * @param path The path to start from * @param level The number of levels to expand to */ private static void expandNode(final JTree tree, final TreeNode node, final TreePath path, final int level) { if (level <= 0) { return; } tree.expandPath(path); for (int i = 0; i < node.getChildCount(); ++i) { final TreeNode childNode = node.getChildAt(i); expandNode(tree, childNode, path.pathByAddingChild(childNode), level - 1); } }
public TreeNode getChildAt(int childIndex) { if (bean != null && bean instanceof TreeNode) { return ((TreeNode)bean).getChildAt(childIndex); } return null; }
public Object nextElement() { try { return vobj_.getChildAt(pos++); } catch (Exception e) { throw new java.util.NoSuchElementException(); } } }
@Override public Object getChild(Object parent, int index) { if (m_filterIsActive) { if (parent instanceof InvisibleNode) { return ((InvisibleNode) parent).getChildAt(index, m_filterIsActive); } } return ((TreeNode) parent).getChildAt(index); }
protected TreeNode findChild(TreeNode parent, Integer simpleKey) { int childIdx = simpleKey.intValue(); if (childIdx < parent.getChildCount()) { return parent.getChildAt(childIdx); } return null; }
public Iterator<TreeNode> getChildren(TreeNode model) { List<TreeNode> children = new ArrayList<TreeNode>(); int childCount = getChildCountOfTreeNode(model); for (int i = 0; i < childCount; i++) { children.add(model.getChildAt(i)); } return children.iterator(); }
@Override public Object getChild(Object parent, int index) { if (m_filterIsActive) { if (parent instanceof InvisibleNode) { return ((InvisibleNode) parent).getChildAt(index, m_filterIsActive); } } return ((TreeNode) parent).getChildAt(index); }
@Override public Object getChild(Object parent, int index) { if (m_filterIsActive) { if (parent instanceof InvisibleNode) { return ((InvisibleNode) parent).getChildAt(index, m_filterIsActive); } } return ((TreeNode) parent).getChildAt(index); }
@Override public Object getChild(Object parent, int index) { if (m_filterIsActive) { if (parent instanceof InvisibleNode) { return ((InvisibleNode) parent).getChildAt(index, m_filterIsActive); } } return ((TreeNode) parent).getChildAt(index); }
private String getNodeContents(TreeNode node, int level) { StringBuffer strBuff = new StringBuffer(); for (int i = 0; i < level; i++) { strBuff.append('\t'); } strBuff.append(node.toString()); strBuff.append('\n'); for (int i = 0; i < node.getChildCount(); i++) { strBuff.append(getNodeContents(node.getChildAt(i), level + 1)); } return strBuff.toString(); }
private String getNodeContents(TreeNode node, int level) { StringBuffer strBuff = new StringBuffer(); strBuff.append(INDENT.toString(level)); strBuff.append(node.toString().trim()); strBuff.append(NEWLINE); for (int i = 0; i < node.getChildCount(); i++) { strBuff.append(getNodeContents(node.getChildAt(i), level + 1)); } return strBuff.toString(); }
public void expandStandardPaths() { final TreeNode root = (TreeNode) getModel().getRoot(); final DefaultMutableTreeNode schemaNode = (DefaultMutableTreeNode) root.getChildAt(0); final DefaultMutableTreeNode libraryNode = (DefaultMutableTreeNode) root.getChildAt(1); expandPath(new TreePath(schemaNode.getPath())); expandPath(new TreePath(libraryNode.getPath())); }
@Override public void expandPathRecursive( final TreePath path, int maxDepth ) { expandPath( path ); if ( maxDepth <= 0 ) return; maxDepth--; final TreeNode node = (TreeNode) path.getLastPathComponent(); // Going upward is faster because expanding needs to update row indices of rows that follow // and this way there are less rows to follow when expanding a node for ( int i = 0; i < node.getChildCount(); i++ ) expandPathRecursive( path.pathByAddingChild( node.getChildAt( i ) ), maxDepth ); }
@Override public void collapsePathRecursive( final TreePath path ) { final TreeNode node = (TreeNode) path.getLastPathComponent(); // Going downward is faster because collapsing needs to update row indices of rows that follow // and this way there are less rows to follow when collapsing a node for ( int i = node.getChildCount() - 1; i >= 0; i-- ) collapsePathRecursive( path.pathByAddingChild( node.getChildAt( i ) ) ); collapsePath( path ); }
private void setSelectionType(final TreeNode selectedNode, final int newSelectionType) { final TreeNodeInfo info = (TreeNodeInfo) ((DefaultMutableTreeNode) selectedNode).getUserObject(); if (info.getSelected() != newSelectionType) { info.setSelected(newSelectionType); treeModel.nodeChanged(selectedNode); } for (int i = 0; i < selectedNode.getChildCount(); i++) { setSelectionType(selectedNode.getChildAt(i), newSelectionType); } }
@Override public void onDescriptorsUpdated(final DescriptorProvider descriptorProvider) { WidgetUtils.invokeSwingAction(() -> { final TreeNode root = (TreeNode) getModel().getRoot(); final DefaultMutableTreeNode libraryNode = (DefaultMutableTreeNode) root.getChildAt(1); libraryNode.removeAllChildren(); createLibrary(libraryNode); final DefaultTreeModel model = (DefaultTreeModel) getModel(); model.reload(libraryNode); expandStandardPaths(); }); }