Example #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();
    }
  } // }}}
Example #2
0
    // {{{ getTreeCellRendererComponent() method
    @Override
    protected void configureTreeCellRendererComponent(
        JTree tree,
        Object value,
        boolean sel,
        boolean expanded,
        boolean leaf,
        int row,
        boolean hasFocus) {
      setIcon(null);
      DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;

      if (node.getUserObject() instanceof HyperSearchOperationNode) {
        setFont(boldFont);

        CountNodes countNodes = new CountNodes();
        traverseNodes(node, countNodes);

        setText(
            jEdit.getProperty(
                "hypersearch-results.result-caption",
                new Object[] {
                  node.toString(),
                  Integer.valueOf(countNodes.resultCount),
                  Integer.valueOf(countNodes.bufferCount)
                }));
      } else if (node.getUserObject() instanceof HyperSearchFolderNode) {
        setFont(plainFont);
        setText(node.toString() + " (" + node.getChildCount() + " files/folders)");
      } else if (node.getUserObject() instanceof HyperSearchFileNode) {
        // file name
        setFont(boldFont);
        HyperSearchFileNode hyperSearchFileNode = (HyperSearchFileNode) node.getUserObject();
        setText(
            jEdit.getProperty(
                "hypersearch-results.file-caption",
                new Object[] {
                  hyperSearchFileNode,
                  Integer.valueOf(hyperSearchFileNode.getCount()),
                  Integer.valueOf(node.getChildCount())
                }));
      } else {
        setFont(plainFont);
      }
    } // }}}
Example #3
0
  /**
   * @param searchNode the result node
   * @param selectNode the node that must be selected, or null
   * @since jEdit 4.3pre12
   */
  public void searchDone(
      final DefaultMutableTreeNode searchNode, final DefaultMutableTreeNode selectNode) {
    stop.setEnabled(false);
    final int nodeCount = searchNode.getChildCount();
    if (nodeCount < 1) {
      searchFailed();
      return;
    }

    caption.setText(
        jEdit.getProperty("hypersearch-results.done", new String[] {trimSearchString()}));

    EventQueue.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            if (!multiStatus) {
              for (int i = 0; i < resultTreeRoot.getChildCount(); i++) {
                resultTreeRoot.remove(0);
              }
            }

            resultTreeRoot.add(searchNode);
            resultTreeModel.reload(resultTreeRoot);

            for (int i = 0; i < nodeCount; i++) {
              TreePath lastNode =
                  new TreePath(((DefaultMutableTreeNode) searchNode.getChildAt(i)).getPath());

              resultTree.expandPath(lastNode);
            }
            TreePath treePath;
            if (selectNode == null) {
              treePath = new TreePath(new Object[] {resultTreeRoot, searchNode});
            } else {
              treePath = new TreePath(selectNode.getPath());
            }
            resultTree.setSelectionPath(treePath);
            resultTree.scrollPathToVisible(treePath);
          }
        });
  } // }}}