public static TreePath[] selectMaximals(final TreePath[] paths) { if (paths == null) return new TreePath[0]; final TreePath[] noDuplicates = removeDuplicates(paths); final ArrayList<TreePath> result = new ArrayList<TreePath>(); for (final TreePath path : noDuplicates) { final ArrayList<TreePath> otherPaths = new ArrayList<TreePath>(Arrays.asList(noDuplicates)); otherPaths.remove(path); if (!isDescendants(path, otherPaths.toArray(new TreePath[otherPaths.size()]))) result.add(path); } return result.toArray(new TreePath[result.size()]); }
private static TreePath[] removeDuplicates(final TreePath[] paths) { final ArrayList<TreePath> result = new ArrayList<TreePath>(); for (final TreePath path : paths) { if (!result.contains(path)) result.add(path); } return result.toArray(new TreePath[result.size()]); }
public static TreePath getPathFromRoot(TreeNode node) { final ArrayList<TreeNode> path = new ArrayList<TreeNode>(); do { path.add(node); node = node.getParent(); } while (node != null); Collections.reverse(path); return new TreePath(path.toArray()); }
public void selectElements(ClassMember[] elements) { ArrayList<TreePath> selectionPaths = new ArrayList<TreePath>(); for (ClassMember element : elements) { MemberNode treeNode = myElementToNodeMap.get(element); if (treeNode != null) { selectionPaths.add(new TreePath(((DefaultMutableTreeNode) treeNode).getPath())); } } myTree.setSelectionPaths(selectionPaths.toArray(new TreePath[selectionPaths.size()])); }
private void restoreSelection(Pair<ElementNode, List<ElementNode>> pair) { List<ElementNode> selectedNodes = pair.second; DefaultMutableTreeNode root = getRootNode(); ArrayList<TreePath> toSelect = new ArrayList<TreePath>(); for (ElementNode node : selectedNodes) { DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) node; if (root.isNodeDescendant(treeNode)) { toSelect.add(new TreePath(treeNode.getPath())); } } if (!toSelect.isEmpty()) { myTree.setSelectionPaths(toSelect.toArray(new TreePath[toSelect.size()])); } ElementNode leadNode = pair.first; if (leadNode != null) { myTree.setLeadSelectionPath(new TreePath(((DefaultMutableTreeNode) leadNode).getPath())); } }