コード例 #1
0
ファイル: HyperSearchResults.java プロジェクト: SELab/jEdit
  // {{{ 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
ファイル: HyperSearchResults.java プロジェクト: SELab/jEdit
  private void goToSelectedNode(int mode) {
    TreePath path = resultTree.getSelectionPath();
    if (path == null) return;

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
    Object value = node.getUserObject();

    // do nothing if clicked "foo (showing n occurrences in m files)"
    if (node.getParent() != resultTreeRoot && value instanceof HyperSearchNode) {
      HyperSearchNode n = (HyperSearchNode) value;
      Buffer buffer = n.getBuffer(view);
      if (buffer == null) return;

      EditPane pane;

      switch (mode) {
        case M_OPEN:
          pane = view.goToBuffer(buffer);
          break;
        case M_OPEN_NEW_VIEW:
          pane = jEdit.newView(view, buffer, false).getEditPane();
          break;
        case M_OPEN_NEW_PLAIN_VIEW:
          pane = jEdit.newView(view, buffer, true).getEditPane();
          break;
        case M_OPEN_NEW_SPLIT:
          pane = view.splitHorizontally();
          break;
        default:
          throw new IllegalArgumentException("Bad mode: " + mode);
      }

      n.goTo(pane);
    }
  } // }}}
コード例 #3
0
ファイル: ConfigEditor.java プロジェクト: caomw/viper-toolkit
 public void actionPerformed(ActionEvent event) {
   JTree tree = getTree();
   TreePath path = tree.getSelectionPath();
   if (path == null) {
     sheet.getLogger().warning("Warning: User must select a node to attach a new config to");
     // XXX add a message telling users to select a node
   } else {
     createAttrConfigForNode((Node) path.getLastPathComponent());
   }
 }
コード例 #4
0
ファイル: Browser.java プロジェクト: tdanford/nrc-wildlife
 public void editSelected() {
   TreePath selected = tree.getSelectionPath();
   if (selected != null) {
     DefaultMutableTreeNode node = (DefaultMutableTreeNode) selected.getLastPathComponent();
     Object obj = node.getUserObject();
     if (obj instanceof CavityDBObject) {
       CavityDBObject dbObj = (CavityDBObject) obj;
       new ObjectEditingFrame(new ObjectEditingPanel(dbObj));
     }
   }
 }
コード例 #5
0
ファイル: TreeUtil.java プロジェクト: jexp/idea2
 public static void moveSelectedRow(final JTree tree, final int direction) {
   final TreePath selectionPath = tree.getSelectionPath();
   final DefaultMutableTreeNode treeNode =
       (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
   final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) treeNode.getParent();
   final int idx = parent.getIndex(treeNode);
   parent.remove(treeNode);
   parent.insert(treeNode, idx + direction);
   ((DefaultTreeModel) tree.getModel()).reload(parent);
   selectNode(tree, treeNode);
 }
コード例 #6
0
  /** Add child to the currently selected node, or the root node if no selection */
  public DefaultMutableTreeNode addNode(Object termId, Object termName) {
    DefaultMutableTreeNode parentNode = null;
    TreePath parentPath = tree.getSelectionPath();

    if (parentPath == null) {
      parentNode = rootNode;
    } else {
      parentNode = (DefaultMutableTreeNode) (parentPath.getLastPathComponent());
    }

    return addNode(parentNode, termId, termName, true);
  }
コード例 #7
0
ファイル: ConfigEditor.java プロジェクト: caomw/viper-toolkit
 public void actionPerformed(ActionEvent event) {
   JTree tree = getTree();
   TreePath path = tree.getSelectionPath();
   if (path == null) {
     sheet.getLogger().warning("Warning: User must select a node to delete");
     // XXX add message telling users to select a node
   } else {
     Node selected = (Node) path.getLastPathComponent();
     try {
       Node parent = selected.getParent();
       if (parent != null) {
         parent.removeChild(selected);
         select(parent);
       }
     } catch (UnsupportedOperationException uox) {
       sheet.getLogger().warning("Cannot delete node: " + selected);
     }
   }
 }
コード例 #8
0
  /**
   * Processes an idChanged event. Search is different from all other navigators in that you while
   * search tree is synchronized the highlighting doesn't occur unless selected from the search
   * navigator.
   */
  public void idChanged(HelpModelEvent e) {
    ID id = e.getID();
    URL url = e.getURL();
    HelpModel helpModel = searchnav.getModel();
    debug("idChanged(" + e + ")");

    if (e.getSource() != helpModel) {
      debug("Internal inconsistency!");
      debug("  " + e.getSource() + " != " + helpModel);
      throw new Error("Internal error");
    }

    TreePath s = tree.getSelectionPath();
    if (s != null) {
      Object o = s.getLastPathComponent();
      // should require only a TreeNode
      if (o instanceof DefaultMutableTreeNode) {
        DefaultMutableTreeNode tn = (DefaultMutableTreeNode) o;
        SearchTOCItem item = (SearchTOCItem) tn.getUserObject();
        if (item != null) {
          ID nId = item.getID();
          if (nId != null && nId.equals(id)) {
            return;
          }
        }
      }
    }

    DefaultMutableTreeNode node = findIDorURL(topNode, id, url);
    if (node == null) {
      // node doesn't exist. Need to clear the selection.
      debug("node didn't exist");
      tree.clearSelection();
      return;
    }
    TreePath path = new TreePath(node.getPath());
    tree.expandPath(path);
    tree.setSelectionPath(path);
    tree.scrollPathToVisible(path);
  }
コード例 #9
0
 protected void enableSetIconButton(ActionManager actionManager) {
   final TreePath selectionPath = myTree.getSelectionPath();
   Object userObject = null;
   if (selectionPath != null) {
     userObject =
         ((DefaultMutableTreeNode) selectionPath.getLastPathComponent()).getUserObject();
     if (userObject instanceof String) {
       final AnAction action = actionManager.getAction((String) userObject);
       if (action != null
           && action.getTemplatePresentation() != null
           && action.getTemplatePresentation().getIcon() != null) {
         mySetIconButton.setEnabled(true);
         return;
       }
     }
   }
   mySetIconButton.setEnabled(
       myTextField.getText().length() != 0
           && selectionPath != null
           && new DefaultMutableTreeNode(selectionPath).isLeaf()
           && !(userObject instanceof Separator));
 }
コード例 #10
0
 @Nullable
 private Object getSelectedObject() {
   TreePath selectionPath = myTree.getSelectionPath();
   if (selectionPath == null) return null;
   return ((DefaultMutableTreeNode) selectionPath.getLastPathComponent()).getUserObject();
 }
コード例 #11
0
ファイル: TreeUtil.java プロジェクト: jexp/idea2
 private static int getSelectedRow(final JTree tree) {
   return tree.getRowForPath(tree.getSelectionPath());
 }
コード例 #12
0
ファイル: TreeUtil.java プロジェクト: jexp/idea2
 /**
  * Removes last component in the current selection path.
  *
  * @param tree to remove selected node from.
  */
 public static void removeSelected(@NotNull final JTree tree) {
   final TreePath selectionPath = tree.getSelectionPath();
   if (selectionPath == null) return;
   removeLastPathComponent((DefaultTreeModel) tree.getModel(), selectionPath)
       .restoreSelection(tree);
 }