/** * Adds a root to the tree if it's not already in there. * * @return false if dir is already in the tree */ public boolean addRoot(File dir) { // remove from deselected in any case boolean changed = deselected.remove(dir); // check if already included for (File root : roots) { if (FileUtils.isAncestor(root, dir)) { if (root.equals(dir)) { if (changed) { directoryTreeModel.valueForPathChanged(getTreePath(dir), null); } return changed; } // make sure it is included removeFromPath(dir); TreePath path = getTreePath(dir); directoryTree.scrollPathToVisible(path); return changed; } else if (FileUtils.isAncestor(dir, root)) { removeRoot(root); addDirToTree(dir); // expand to root and its parent, since expand has no effect if root // doesn't have subfolders setExpanded(root); // guaranteed to not be null since at least dir is its real ancestor setExpanded(root.getParentFile()); return true; } } addDirToTree(dir); setRootExpanded(); return true; }