/** Marks the path <code>path</code> expanded state to <code>isExpanded</code>. */ public void setExpandedState(TreePath path, boolean isExpanded) { if (isExpanded) ensurePathIsExpanded(path, true); else if (path != null) { TreePath parentPath = path.getParentPath(); // YECK! Make the parent expanded. if (parentPath != null) { FHTreeStateNode parentNode = getNodeForPath(parentPath, false, true); if (parentNode != null) parentNode.makeVisible(); } // And collapse the child. FHTreeStateNode childNode = getNodeForPath(path, true, false); if (childNode != null) childNode.collapse(true); } }
/** * Ensures that all the path components in path are expanded, accept for the last component which * will only be expanded if expandLast is true. Returns true if succesful in finding the path. */ private boolean ensurePathIsExpanded(TreePath aPath, boolean expandLast) { if (aPath != null) { // Make sure the last entry isn't a leaf. if (treeModel.isLeaf(aPath.getLastPathComponent())) { aPath = aPath.getParentPath(); expandLast = true; } if (aPath != null) { FHTreeStateNode lastNode = getNodeForPath(aPath, false, true); if (lastNode != null) { lastNode.makeVisible(); if (expandLast) lastNode.expand(); return true; } } } return false; }