コード例 #1
0
ファイル: TreeUtil.java プロジェクト: jexp/idea2
 private static void expand(JTree tree, TreePath path, int levels) {
   if (levels == 0) return;
   tree.expandPath(path);
   TreeNode node = (TreeNode) path.getLastPathComponent();
   Enumeration children = node.children();
   while (children.hasMoreElements()) {
     expand(tree, path.pathByAddingChild(children.nextElement()), levels - 1);
   }
 }
コード例 #2
0
 public void addSelectionPathTo(final Object element) {
   DefaultMutableTreeNode node = myAbstractTreeBuilder.getNodeForElement(element);
   if (node != null) {
     final JTree tree = getTree();
     final TreePath path = new TreePath(node.getPath());
     if (node == tree.getModel().getRoot() && !tree.isExpanded(path)) tree.expandPath(path);
     tree.addSelectionPath(path);
   }
 }
コード例 #3
0
ファイル: TreeUtil.java プロジェクト: jexp/idea2
  public static ActionCallback selectInTree(
      DefaultMutableTreeNode node, boolean requestFocus, JTree tree, boolean center) {
    if (node == null) return new ActionCallback.Done();

    final TreePath treePath = new TreePath(node.getPath());
    tree.expandPath(treePath);
    if (requestFocus) {
      tree.requestFocus();
    }
    return selectPath(tree, treePath, center);
  }
コード例 #4
0
ファイル: TreeUtil.java プロジェクト: jexp/idea2
 public static void expandAll(final JTree tree) {
   tree.expandPath(new TreePath(tree.getModel().getRoot()));
   int oldRowCount = 0;
   do {
     int rowCount = tree.getRowCount();
     if (rowCount == oldRowCount) break;
     oldRowCount = rowCount;
     for (int i = 0; i < rowCount; i++) {
       tree.expandRow(i);
     }
   } while (true);
 }
コード例 #5
0
 private void restoreUsageExpandState(final Collection<UsageState> states) {
   // always expand the last level group
   final DefaultMutableTreeNode root = (DefaultMutableTreeNode) myTree.getModel().getRoot();
   for (int i = root.getChildCount() - 1; i >= 0; i--) {
     final DefaultMutableTreeNode child = (DefaultMutableTreeNode) root.getChildAt(i);
     if (child instanceof GroupNode) {
       final TreePath treePath = new TreePath(child.getPath());
       myTree.expandPath(treePath);
     }
   }
   myTree.getSelectionModel().clearSelection();
   for (final UsageState usageState : states) {
     usageState.restore();
   }
 }
コード例 #6
0
ファイル: TreeUtil.java プロジェクト: jexp/idea2
  public static ActionCallback selectInTree(
      Project project,
      DefaultMutableTreeNode node,
      boolean requestFocus,
      JTree tree,
      boolean center) {
    if (node == null) return new ActionCallback.Done();

    final TreePath treePath = new TreePath(node.getPath());
    tree.expandPath(treePath);
    if (requestFocus) {
      ActionCallback result = new ActionCallback(2);
      IdeFocusManager.getInstance(project).requestFocus(tree, true).notifyWhenDone(result);
      selectPath(tree, treePath, center).notifyWhenDone(result);
      return result;
    }
    return selectPath(tree, treePath, center);
  }
コード例 #7
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);
  }
コード例 #8
0
ファイル: TreeUtil.java プロジェクト: jexp/idea2
 public static void collapseAll(final JTree tree, final int keepSelectionLevel) {
   final TreePath leadSelectionPath = tree.getLeadSelectionPath();
   // Collapse all
   int row = tree.getRowCount() - 1;
   while (row >= 0) {
     tree.collapseRow(row);
     row--;
   }
   final DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot();
   tree.expandPath(new TreePath(root));
   if (leadSelectionPath != null) {
     final Object[] path = leadSelectionPath.getPath();
     final Object[] pathToSelect =
         new Object
             [path.length > keepSelectionLevel && keepSelectionLevel >= 0
                 ? keepSelectionLevel
                 : path.length];
     System.arraycopy(path, 0, pathToSelect, 0, pathToSelect.length);
     if (pathToSelect.length == 0) return;
     selectPath(tree, new TreePath(pathToSelect));
   }
 }
コード例 #9
0
 private void restorePathsAfterTreeOptimization(final List<TreePath> treePaths) {
   for (final TreePath treePath : treePaths) {
     myActionsTree.expandPath(CustomizationUtil.getPathByUserObjects(myActionsTree, treePath));
   }
 }
コード例 #10
0
ファイル: TreeUtil.java プロジェクト: jexp/idea2
 /**
  * Expands specified paths.
  *
  * @param tree JTree to apply expansion status to
  * @param paths to expand. See {@link #collectExpandedPaths(javax.swing.JTree, java.util.List)}
  */
 public static void restoreExpandedPaths(
     @NotNull final JTree tree, @NotNull final List<TreePath> paths) {
   for (int i = paths.size() - 1; i >= 0; i--) {
     tree.expandPath(paths.get(i));
   }
 }