コード例 #1
0
 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()]));
 }
コード例 #2
0
  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()));
    }
  }