/** * Scans the directory structure starting at root, looking for folders that are either empty or * contain files, adding them to the set. * * <p> * * @param children set to which nodes are added. * @param fo file object to examine. * @param root root of the package hierarchy. * @param query true to query for visibility of files. */ private static void findVisiblePackages( Set<Node> children, FileObject fo, FileObject root, boolean query) { VisibilityQuery vq = VisibilityQuery.getDefault(); if (query && !vq.isVisible(fo)) { return; } FileObject[] kids = fo.getChildren(); boolean hasSubfolders = false; boolean hasFiles = false; for (int ii = 0; ii < kids.length; ii++) { if (!query || vq.isVisible(kids[ii])) { if (kids[ii].isFolder()) { findVisiblePackages(children, kids[ii], root, query); hasSubfolders = true; } else { hasFiles = true; } } } if (hasFiles || !hasSubfolders) { DataFolder df = DataFolder.findFolder(fo); PackageNode pn = new PackageNode(root, df); children.add(pn); } }
@Override protected void addNotify() { super.addNotify(); Set<Node> children = new TreeSet<Node>(); FileObject[] kids = sourceRoot.getChildren(); boolean archive = FileUtil.isArchiveFile(sourceRoot); VisibilityQuery vq = VisibilityQuery.getDefault(); for (int ii = 0; ii < kids.length; ii++) { if (archive || vq.isVisible(kids[ii])) { if (kids[ii].isFolder()) { findVisiblePackages(children, kids[ii], sourceRoot, !archive); } else { try { DataObject data = DataObject.find(kids[ii]); // For sorting, wrap a filter around the node. Node node = new SortableNode(data.getNodeDelegate()); children.add(node); } catch (DataObjectNotFoundException donfe) { // in that case, ignore the file } } } } // Add the children to our own set (which should be empty). Node[] kidsArray = children.toArray(new Node[children.size()]); super.add(kidsArray); }