示例#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();
    }
  } // }}}
示例#2
0
  /** Removes the given node from its parent. */
  public void removeNodeFromParent(MutableTreeNode node) {
    MutableTreeNode parent = (MutableTreeNode) node.getParent();

    // Ensure that the given node has a parent
    if (parent == null) {
      throw new IllegalArgumentException("node does not have a parent");
    }

    // Remove the node from the parent
    int idx = parent.getIndex(node);
    parent.remove(idx);

    // Notify listeners that the node has been removed
    fireTreeNodesRemoved(this, getPathToRoot(parent), new int[] {idx}, new Object[] {node});
  }
  /* Simple tree node factory method - set's parent and user object.
   */
  private DefaultMutableTreeNode makeNode(Object userObject, MutableTreeNode parent) {

    DefaultMutableTreeNode node = new DefaultMutableTreeNode(userObject);

    if (parent != null) {
      treeModel.insertNodeInto(node, parent, parent.getChildCount());
    }

    return node;
  }
示例#4
0
 /** Inserts the given child node into the given parent at the given index. */
 public void insertNodeInto(MutableTreeNode child, MutableTreeNode parent, int idx) {
   parent.insert(child, idx);
   fireTreeNodesInserted(this, getPathToRoot(parent), new int[] {idx}, new Object[] {child});
 }
示例#5
0
文件: TreeUtil.java 项目: jexp/idea2
 private static void addChildrenTo(final MutableTreeNode node, final List<TreeNode> children) {
   for (final Object aChildren : children) {
     final MutableTreeNode child = (MutableTreeNode) aChildren;
     node.insert(child, node.getChildCount());
   }
 }