private void expandOrCollapse(BaseComponent parent, boolean collapse) { for (BaseComponent child : parent.getChildren()) { ((Treenode) child).setCollapsed(collapse); expandOrCollapse(child, collapse); } }
/** * Expand / collapse tree children to specified depth. * * @param parent Tree children whose tree items are to be expanded / collapsed. * @param depth Expand tree items to this depth. Tree items below this depth are collapsed. */ private static void expandChildren(BaseComponent parent, int depth) { if (parent == null || depth <= 0) { return; } depth--; for (Object object : parent.getChildren()) { Treenode item = (Treenode) object; item.setCollapsed(depth <= 0); expandChildren(item, depth); } }
/** * Ensures that this node is visible (i.e., all of its parent tree nodes are expanded. */ public void makeVisible() { BaseComponent node = getParent(); while (node instanceof Treenode) { ((Treenode) node).setCollapsed(false); node = node.getParent(); } scrollIntoView(); }
/** * Recursively create tree items that correspond to the topic tree from the help view. * * @param tc The root node to receive newly created tree nodes. * @param node A topic tree node. * @return Newly created tree node. */ private Treenode addNode(BaseComponent tc, HelpTopicNode node) { HelpTopic topic = node.getTopic(); Treenode parent = new Treenode(); parent.setLabel(topic.getLabel()); parent.setData(topic); topics.put(topic, parent); tc.addChild(parent); for (HelpTopicNode child : node.getChildren()) { addNode(parent, child); } parent.setCollapsed(false); return parent; }