Esempio 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();
    }
  } // }}}
Esempio n. 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});
  }