@Nullable
  public FilteringTreeStructure.FilteringNode selectPsiElement(PsiElement element) {
    Set<PsiElement> parents = getAllParents(element);

    FilteringTreeStructure.FilteringNode node =
        (FilteringTreeStructure.FilteringNode) myAbstractTreeBuilder.getRootElement();
    while (node != null) {
      boolean changed = false;
      for (FilteringTreeStructure.FilteringNode n : node.children()) {
        final PsiElement psiElement = getPsi(n);
        if (psiElement != null && parents.contains(psiElement)) {
          node = n;
          changed = true;
          break;
        }
      }
      if (!changed) {
        myAbstractTreeBuilder.select(node);
        if (myAbstractTreeBuilder.getSelectedElements().isEmpty()) {
          TreeUtil.selectFirstNode(myTree);
        }
        myInitialNodeIsLeaf = node.getChildren().length == 0;
        return node;
      }
    }
    TreeUtil.selectFirstNode(myTree);
    return null;
  }
 private void sortChildren(InspectionTreeNode node) {
   final List<TreeNode> children = TreeUtil.childrenToArray(node);
   Collections.sort(children, InspectionResultsViewComparator.getInstance());
   node.removeAllChildren();
   TreeUtil.addChildrenTo(node, children);
   ((DefaultTreeModel) getModel()).reload(node);
 }
 public ActionCallback selectNodeInTree(
     final DefaultMutableTreeNode nodeToSelect, boolean center, final boolean requestFocus) {
   if (requestFocus) {
     myTree.requestFocus();
   }
   if (nodeToSelect != null) {
     return TreeUtil.selectInTree(nodeToSelect, requestFocus, myTree, center);
   } else {
     return TreeUtil.selectFirstNode(myTree);
   }
 }
示例#4
0
 protected void setUp() throws Exception {
   super.setUp();
   myTreeModel.insertNodeInto(myChildA, myRoot, 0);
   myTreeModel.insertNodeInto(myChildB, myRoot, 1);
   myTreeModel.insertNodeInto(myChild2, myChildA, 0);
   myTreeModel.insertNodeInto(new DefaultMutableTreeNode(), myChild2, 0);
   myTreeModel.insertNodeInto(new DefaultMutableTreeNode(), myChildB, 0);
   myChildAPath = TreeUtil.getPathFromRoot(myChildA);
   myChild2Path = TreeUtil.getPathFromRoot(myChild2);
   myChildBPath = TreeUtil.getPathFromRoot(myChildB);
 }
 @Override
 protected Object[] getAllElements() {
   if (myCanExpand) {
     final Object root = myComponent.getModel().getRoot();
     if (root instanceof DefaultMutableTreeNode || root instanceof PathAwareTreeNode) {
       final List<TreePath> paths = new ArrayList<TreePath>();
       TreeUtil.traverseDepth(
           (TreeNode) root,
           new TreeUtil.Traverse() {
             @Override
             public boolean accept(Object node) {
               if (node instanceof DefaultMutableTreeNode) {
                 paths.add(new TreePath(((DefaultMutableTreeNode) node).getPath()));
               } else if (node instanceof PathAwareTreeNode) {
                 paths.add(((PathAwareTreeNode) node).getPath());
               }
               return true;
             }
           });
       return paths.toArray(new TreePath[paths.size()]);
     }
   }
   TreePath[] paths = new TreePath[myComponent.getRowCount()];
   for (int i = 0; i < paths.length; i++) {
     paths[i] = myComponent.getPathForRow(i);
   }
   return paths;
 }
示例#6
0
文件: TreeView.java 项目: jexp/idea2
  public boolean restoreSelection(TreeSelection treeSelection) {
    if (treeSelection.isEmpty()) return false;

    DefaultMutableTreeNode root = (DefaultMutableTreeNode) myTreeModel.getRoot();
    for (int i = 0; i < root.getChildCount(); i++) {
      TreeNode node = root.getChildAt(i);
      if (node instanceof MessageNode) {
        MessageNode messageNode = (MessageNode) node;
        String[] text = messageNode.getText();
        if (text.length == 0) continue;
        if (Comparing.equal(treeSelection.mySelectedTarget, text[0])) {
          TreePath pathToSelect = new TreePath(messageNode.getPath());
          for (Enumeration enumeration = messageNode.children(); enumeration.hasMoreElements(); ) {
            Object o = enumeration.nextElement();
            if (o instanceof MessageNode) {
              messageNode = (MessageNode) o;
              if (Comparing.equal(treeSelection.mySelectedTask, text[0])) {
                pathToSelect = new TreePath(messageNode.getPath());
                break;
              }
            }
          }
          TreeUtil.selectPath(myTree, pathToSelect);
          myTree.expandPath(pathToSelect);
          return true;
        }
      }
    }

    return false;
  }
 @Override
 protected boolean findAdditionalMembers(final Set<UsageInfo> toMakeStatic) {
   if (!toMakeStatic.isEmpty()) {
     myAdditionalMethods = new ArrayList<PsiMethod>();
     if (ApplicationManager.getApplication().isUnitTestMode()) {
       for (UsageInfo usageInfo : toMakeStatic) {
         myAdditionalMethods.add((PsiMethod) usageInfo.getElement());
       }
     } else {
       final JavaCallerChooser chooser =
           new MakeStaticJavaCallerChooser(
               myMember, myProject, methods -> myAdditionalMethods.addAll(methods)) {
             @Override
             protected ArrayList<UsageInfo> getTopLevelItems() {
               return new ArrayList<UsageInfo>(toMakeStatic);
             }
           };
       TreeUtil.expand(chooser.getTree(), 2);
       if (!chooser.showAndGet()) {
         return false;
       }
     }
   }
   return true;
 }
  public InspectionTree(final Project project) {
    super(new InspectionRootNode(project));

    setCellRenderer(new CellRenderer()); // project));
    setShowsRootHandles(true);
    UIUtil.setLineStyleAngled(this);
    addTreeWillExpandListener(new ExpandListener());

    myExpandedUserObjects = new HashSet<Object>();
    myExpandedUserObjects.add(project);

    TreeUtil.installActions(this);
    new TreeSpeedSearch(
        this,
        new Convertor<TreePath, String>() {
          @Override
          public String convert(TreePath o) {
            return InspectionsConfigTreeComparator.getDisplayTextToSort(
                o.getLastPathComponent().toString());
          }
        });

    addTreeSelectionListener(
        new TreeSelectionListener() {
          @Override
          public void valueChanged(TreeSelectionEvent e) {
            TreePath newSelection = e.getNewLeadSelectionPath();
            if (newSelection != null) {
              mySelectionPath = new SelectionPath(newSelection);
            }
          }
        });
  }
 @Override
 public boolean update(DnDEvent aEvent) {
   aEvent.setDropPossible(false);
   aEvent.hideHighlighter();
   final Object object = aEvent.getAttachedObject();
   if (object instanceof PackagingElementDraggingObject) {
     final DefaultMutableTreeNode parent =
         findParentCompositeElementNode(aEvent.getRelativePoint().getPoint(myTree));
     if (parent != null) {
       final PackagingElementDraggingObject draggingObject =
           (PackagingElementDraggingObject) object;
       final PackagingElementNode node = getNode(parent);
       if (node != null && draggingObject.canDropInto(node)) {
         final PackagingElement element = node.getFirstElement();
         if (element instanceof CompositePackagingElement) {
           draggingObject.setTargetNode(node);
           draggingObject.setTargetElement((CompositePackagingElement<?>) element);
           final Rectangle bounds = myTree.getPathBounds(TreeUtil.getPathFromRoot(parent));
           aEvent.setHighlighting(
               new RelativeRectangle(myTree, bounds),
               DnDEvent.DropTargetHighlightingType.RECTANGLE);
           aEvent.setDropPossible(true);
         }
       }
     }
   }
   return false;
 }
 public void selectFirstCertificate() {
   if (!isEmpty()) {
     Tree tree = (Tree) getTree();
     TreePath path = TreeUtil.getFirstLeafNodePath(tree);
     tree.addSelectionPath(path);
   }
 }
  @Override
  public void removeWatches(final List<? extends XDebuggerTreeNode> nodes) {
    List<? extends WatchNode> children = myRootNode.getAllChildren();
    int minIndex = Integer.MAX_VALUE;
    List<XDebuggerTreeNode> toRemove = new ArrayList<XDebuggerTreeNode>();
    if (children != null) {
      for (XDebuggerTreeNode node : nodes) {
        @SuppressWarnings("SuspiciousMethodCalls")
        int index = children.indexOf(node);
        if (index != -1) {
          toRemove.add(node);
          minIndex = Math.min(minIndex, index);
        }
      }
    }
    myRootNode.removeChildren(toRemove);

    List<? extends WatchNode> newChildren = myRootNode.getAllChildren();
    if (newChildren != null && !newChildren.isEmpty()) {
      WatchNode node =
          minIndex < newChildren.size()
              ? newChildren.get(minIndex)
              : newChildren.get(newChildren.size() - 1);
      TreeUtil.selectNode(myTreePanel.getTree(), node);
    }
    updateSessionData();
  }
示例#12
0
 public void apply() throws ConfigurationException {
   processRemovedItems();
   final ConfigurationException[] ex = new ConfigurationException[1];
   TreeUtil.traverse(
       myRoot,
       new TreeUtil.Traverse() {
         public boolean accept(Object node) {
           if (node instanceof MyNode) {
             try {
               final NamedConfigurable configurable = ((MyNode) node).getConfigurable();
               if (isInitialized(configurable) && configurable.isModified()) {
                 configurable.apply();
               }
             } catch (ConfigurationException e) {
               ex[0] = e;
               return false;
             }
           }
           return true;
         }
       });
   if (ex[0] != null) {
     throw ex[0];
   }
   myHasDeletedItems = false;
 }
  private void createTreeModel() {
    final PsiManager psiManager = PsiManager.getInstance(myProject);
    final FileIndex fileIndex =
        myModule != null
            ? ModuleRootManager.getInstance(myModule).getFileIndex()
            : ProjectRootManager.getInstance(myProject).getFileIndex();
    fileIndex.iterateContent(
        new ContentIterator() {
          public boolean processFile(VirtualFile fileOrDir) {
            if (fileOrDir.isDirectory() && fileIndex.isInSourceContent(fileOrDir)) {
              final PsiDirectory psiDirectory = psiManager.findDirectory(fileOrDir);
              LOG.assertTrue(psiDirectory != null);
              PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory);
              if (aPackage != null) {
                addPackage(aPackage);
              }
            }
            return true;
          }
        });

    TreeUtil.sort(
        myModel,
        new Comparator() {
          public int compare(Object o1, Object o2) {
            DefaultMutableTreeNode n1 = (DefaultMutableTreeNode) o1;
            DefaultMutableTreeNode n2 = (DefaultMutableTreeNode) o2;
            PsiNamedElement element1 = (PsiNamedElement) n1.getUserObject();
            PsiNamedElement element2 = (PsiNamedElement) n2.getUserObject();
            return element1.getName().compareToIgnoreCase(element2.getName());
          }
        });
  }
  protected Tree createTree() {
    final Tree tree = new Tree(new DefaultTreeModel(new DefaultMutableTreeNode()));

    tree.setCellRenderer(getTreeCellRenderer());
    UIUtil.setLineStyleAngled(tree);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.addKeyListener(new TreeKeyListener());
    tree.addTreeSelectionListener(new MyTreeSelectionListener());

    if (!myAllowMultiSelection) {
      tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    }

    new DoubleClickListener() {
      @Override
      protected boolean onDoubleClick(MouseEvent e) {
        if (tree.getPathForLocation(e.getX(), e.getY()) != null) {
          doOKAction();
          return true;
        }
        return false;
      }
    }.installOn(tree);

    TreeUtil.installActions(tree);
    return tree;
  }
 public void selectBreakpoint(Breakpoint breakpoint) {
   final CheckedTreeNode node = myDescriptorToNodeMap.get(new BreakpointDescriptor(breakpoint));
   if (node == null) {
     return;
   }
   TreeUtil.selectNode(this, node);
 }
 protected void checkTree(String filter) {
   myPopupFixture.getPopup().setSearchFilterForTests(filter);
   myPopupFixture.getBuilder().refilter(null, false, true);
   myPopupFixture.getBuilder().queueUpdate();
   TreeUtil.selectPath(
       myPopupFixture.getTree(), (TreePath) myPopupFixture.getSpeedSearch().findElement(filter));
   checkTree();
 }
 protected void removeFacetNodes(@NotNull List<Facet> facets) {
   for (Facet facet : facets) {
     MyNode node = findNodeByObject(myRoot, facet);
     if (node != null) {
       removePaths(TreeUtil.getPathFromRoot(node));
     }
   }
 }
示例#18
0
文件: TreeView.java 项目: jexp/idea2
 void scrollToLastMessage() {
   if (myTree == null) return;
   int count = myTree.getRowCount();
   if (count > 0) {
     int row = count - 1;
     TreeUtil.selectPath(myTree, myTree.getPathForRow(row));
   }
 }
示例#19
0
  protected void removePaths(final TreePath... paths) {
    MyNode parentNode = null;
    int idx = -1;
    for (TreePath path : paths) {
      final MyNode node = (MyNode) path.getLastPathComponent();
      final NamedConfigurable namedConfigurable = node.getConfigurable();
      final Object editableObject = namedConfigurable.getEditableObject();
      parentNode = (MyNode) node.getParent();
      idx = parentNode.getIndex(node);
      ((DefaultTreeModel) myTree.getModel()).removeNodeFromParent(node);
      myHasDeletedItems |= wasObjectStored(editableObject);
      fireItemsChangeListener(editableObject);
      onItemDeleted(editableObject);
      namedConfigurable.disposeUIResources();
    }

    if (paths.length > 0) {
      if (parentNode != null && idx != -1) {
        DefaultMutableTreeNode toSelect = null;
        if (idx < parentNode.getChildCount()) {
          toSelect = (DefaultMutableTreeNode) parentNode.getChildAt(idx);
        } else {
          if (idx > 0 && parentNode.getChildCount() > 0) {
            if (idx - 1 < parentNode.getChildCount()) {
              toSelect = (DefaultMutableTreeNode) parentNode.getChildAt(idx - 1);
            } else {
              toSelect = (DefaultMutableTreeNode) parentNode.getFirstChild();
            }
          } else {
            if (parentNode.isRoot() && myTree.isRootVisible()) {
              toSelect = parentNode;
            } else if (parentNode.getChildCount() > 0) {
              toSelect = (DefaultMutableTreeNode) parentNode.getFirstChild();
            }
          }
        }

        if (toSelect != null) {
          TreeUtil.selectInTree(toSelect, true, myTree);
        }
      } else {
        TreeUtil.selectFirstNode(myTree);
      }
    }
  }
 public void actionPerformed(final AnActionEvent e) {
   final Set<PsiFile> selectedScope = getSelectedScope(myLeftTree);
   exclude(selectedScope);
   myExcluded.addAll(selectedScope);
   final TreePath[] paths = myLeftTree.getSelectionPaths();
   for (TreePath path : paths) {
     TreeUtil.removeLastPathComponent(myLeftTree, path);
   }
 }
 public void apply() throws ConfigurationException {
   final List<TreePath> treePaths = TreeUtil.collectExpandedPaths(myActionsTree);
   if (mySelectedSchema != null) {
     CustomizationUtil.optimizeSchema(myActionsTree, mySelectedSchema);
   }
   restorePathsAfterTreeOptimization(treePaths);
   CustomActionsSchema.getInstance().copyFrom(mySelectedSchema);
   setCustomizationSchemaForCurrentProjects();
 }
 public void centerSelectedRow() {
   TreePath path = getTree().getSelectionPath();
   if (path == null) {
     return;
   }
   myAutoScrollToSourceHandler.setShouldAutoScroll(false);
   TreeUtil.showRowCentered(getTree(), getTree().getRowForPath(path), false);
   myAutoScrollToSourceHandler.setShouldAutoScroll(true);
 }
 @Override
 public void actionPerformed(AnActionEvent e) {
   final Component c = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
   if (c != null) {
     final JTree tree = UIUtil.getParentOfType(JTree.class, c);
     if (tree != null) {
       TreeUtil.expandAll(tree);
     }
   }
 }
 public void setSelected(AnActionEvent event, boolean flag) {
   DependencyUISettings.getInstance().UI_SHOW_FILES = flag;
   mySettings.UI_SHOW_FILES = flag;
   if (!flag
       && myLeftTree.getSelectionPath() != null
       && myLeftTree.getSelectionPath().getLastPathComponent() instanceof FileNode) {
     TreeUtil.selectPath(myLeftTree, myLeftTree.getSelectionPath().getParentPath());
   }
   rebuild();
 }
 public void selectPackage(final String qualifiedName) {
   /*ApplicationManager.getApplication().invokeLater(new Runnable() {
   public void run() {*/
   DefaultMutableTreeNode node = findNodeForPackage(qualifiedName);
   if (node != null) {
     TreePath path = new TreePath(node.getPath());
     TreeUtil.selectPath(myTree, path);
   }
   /* }
   }, ModalityState.stateForComponent(getRootPane()));*/
 }
示例#26
0
文件: TreeState.java 项目: jexp/idea2
 private static List<List<PathElement>> createPaths(final JTree tree) {
   final ArrayList<List<PathElement>> result = new ArrayList<List<PathElement>>();
   final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(tree);
   for (final TreePath expandedPath : expandedPaths) {
     final List<PathElement> path = createPath(expandedPath);
     if (path != null) {
       result.add(path);
     }
   }
   return result;
 }
 public void restoreState() {
   myStructureViewState = myFileEditor.getUserData(STRUCTURE_VIEW_STATE_KEY);
   if (myStructureViewState == null) {
     TreeUtil.expand(getTree(), 2);
   } else {
     expandStoredElements();
     selectStoredElements();
     myFileEditor.putUserData(STRUCTURE_VIEW_STATE_KEY, null);
     myStructureViewState = null;
   }
 }
示例#28
0
 protected void initTree() {
   ((DefaultTreeModel) myTree.getModel()).setRoot(myRoot);
   myTree.setRootVisible(false);
   myTree.setShowsRootHandles(true);
   UIUtil.setLineStyleAngled(myTree);
   TreeUtil.installActions(myTree);
   myTree.setCellRenderer(
       new ColoredTreeCellRenderer() {
         public void customizeCellRenderer(
             JTree tree,
             Object value,
             boolean selected,
             boolean expanded,
             boolean leaf,
             int row,
             boolean hasFocus) {
           if (value instanceof MyNode) {
             final MyNode node = ((MyNode) value);
             setIcon(node.getIcon(expanded));
             final Font font = UIUtil.getTreeFont();
             if (node.isDisplayInBold()) {
               setFont(font.deriveFont(Font.BOLD));
             } else {
               setFont(font.deriveFont(Font.PLAIN));
             }
             append(
                 node.getDisplayName(),
                 node.isDisplayInBold()
                     ? SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES
                     : SimpleTextAttributes.REGULAR_ATTRIBUTES);
           }
         }
       });
   initToolbar();
   ArrayList<AnAction> actions = createActions(true);
   if (actions != null) {
     final DefaultActionGroup group = new DefaultActionGroup();
     for (AnAction action : actions) {
       group.add(action);
     }
     actions = getAdditionalActions();
     if (actions != null) {
       group.addSeparator();
       for (AnAction action : actions) {
         group.add(action);
       }
     }
     PopupHandler.installPopupHandler(
         myTree,
         group,
         ActionPlaces.UNKNOWN,
         ActionManager.getInstance()); // popup should follow the selection
   }
 }
  private void installTree() {
    getTree().getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    myAutoScrollToSourceHandler.install(getTree());
    myAutoScrollFromSourceHandler.install();

    TreeUtil.installActions(getTree());
    new TreeSpeedSearch(getTree());

    addTreeKeyListener();
    addTreeMouseListeners();
    restoreState();
  }
    public void restore(BreakpointTree tree) {
      final List<TreePath> pathsToExpand = getPaths(tree, myExpandedUserObjects);
      if (!pathsToExpand.isEmpty()) {
        TreeUtil.restoreExpandedPaths(tree, pathsToExpand);
      }

      final List<TreePath> pathsToSelect = getPaths(tree, mySelectedUserObjects);
      if (!pathsToSelect.isEmpty()) {
        tree.getSelectionModel().clearSelection();
        tree.setSelectionPaths(pathsToSelect.toArray(new TreePath[pathsToSelect.size()]));
      }
    }