public void addSelectionPathTo(final Object element) {
   DefaultMutableTreeNode node = myAbstractTreeBuilder.getNodeForElement(element);
   if (node != null) {
     final JTree tree = getTree();
     final TreePath path = new TreePath(node.getPath());
     if (node == tree.getModel().getRoot() && !tree.isExpanded(path)) tree.expandPath(path);
     tree.addSelectionPath(path);
   }
 }
Пример #2
0
  private void applySelected(final JTree tree, final DefaultMutableTreeNode node) {
    TreeUtil.unselect(tree, node);
    List<TreePath> selectionPaths = new ArrayList<TreePath>();
    for (List<PathElement> pathElements : mySelectedPaths) {
      applySelectedTo(pathElements, tree.getModel().getRoot(), tree, selectionPaths);
    }

    if (selectionPaths.size() > 1) {
      for (TreePath path : selectionPaths) {
        tree.addSelectionPath(path);
      }
    }
  }