Ejemplo n.º 1
0
  // {{{ removeSelectedNode() method
  private void removeSelectedNode() {
    TreePath path = resultTree.getSelectionPath();
    if (path == null) return;

    MutableTreeNode value = (MutableTreeNode) path.getLastPathComponent();

    if (path.getPathCount() > 1) {
      // Adjust selection so that repeating some removals
      // behave naturally.
      TreePath parentPath = path.getParentPath();
      MutableTreeNode parent = (MutableTreeNode) parentPath.getLastPathComponent();
      int removingIndex = parent.getIndex(value);
      int nextIndex = removingIndex + 1;
      if (nextIndex < parent.getChildCount()) {
        TreeNode next = parent.getChildAt(nextIndex);
        resultTree.setSelectionPath(parentPath.pathByAddingChild(next));
      } else {
        resultTree.setSelectionPath(parentPath);
      }

      resultTreeModel.removeNodeFromParent(value);
    }

    HyperSearchOperationNode.removeNodeFromCache(value);
    if (resultTreeRoot.getChildCount() == 0) {
      hideDockable();
    }
  } // }}}
 private void captureUsagesExpandState(TreePath pathFrom, final Collection<UsageState> states) {
   if (!myTree.isExpanded(pathFrom)) {
     return;
   }
   final DefaultMutableTreeNode node = (DefaultMutableTreeNode) pathFrom.getLastPathComponent();
   final int childCount = node.getChildCount();
   for (int idx = 0; idx < childCount; idx++) {
     final TreeNode child = node.getChildAt(idx);
     if (child instanceof UsageNode) {
       final Usage usage = ((UsageNode) child).getUsage();
       states.add(
           new UsageState(
               usage,
               myTree.getSelectionModel().isPathSelected(pathFrom.pathByAddingChild(child))));
     } else {
       captureUsagesExpandState(pathFrom.pathByAddingChild(child), states);
     }
   }
 }
Ejemplo n.º 3
0
  TreePath getTreePath(TreeNode treeNode) {

    TreeNode parent = treeNode.getParent();
    if (parent == null) {
      return new TreePath(treeNode);
    } else {
      TreePath ptp = getTreePath(parent);
      ptp = ptp.pathByAddingChild(treeNode);
      return ptp;
    }
  }
 public void restore() {
   final UsageNode node = myUsageNodes.get(myUsage);
   if (node == NULL_NODE || node == null) {
     return;
   }
   final DefaultMutableTreeNode parentGroupingNode = (DefaultMutableTreeNode) node.getParent();
   if (parentGroupingNode != null) {
     final TreePath treePath = new TreePath(parentGroupingNode.getPath());
     myTree.expandPath(treePath);
     if (mySelected) {
       myTree.addSelectionPath(treePath.pathByAddingChild(node));
     }
   }
 }