コード例 #1
0
 protected void rebuild() {
   storeState();
   ++ourSettingsModificationCount;
   ((SmartTreeStructure) myAbstractTreeBuilder.getTreeStructure()).rebuildTree();
   myAbstractTreeBuilder.updateFromRoot();
   restoreState();
 }
コード例 #2
0
 public boolean select(final Object element, final boolean requestFocus) {
   myAbstractTreeBuilder
       .getReady(this)
       .doWhenDone(
           new Runnable() {
             public void run() {
               expandPathToElement(element)
                   .doWhenDone(
                       new AsyncResult.Handler<AbstractTreeNode>() {
                         public void run(AbstractTreeNode abstractTreeNode) {
                           myAbstractTreeBuilder.select(
                               abstractTreeNode,
                               new Runnable() {
                                 public void run() {
                                   if (requestFocus) {
                                     IdeFocusManager.getInstance(myProject)
                                         .requestFocus(myAbstractTreeBuilder.getTree(), false);
                                   }
                                 }
                               });
                         }
                       });
             }
           });
   return true;
 }
コード例 #3
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);
   }
 }
コード例 #4
0
 private ArrayList<AbstractTreeNode> getPathToElement(Object element) {
   ArrayList<AbstractTreeNode> result = new ArrayList<AbstractTreeNode>();
   final AbstractTreeStructure treeStructure = myAbstractTreeBuilder.getTreeStructure();
   if (treeStructure != null) {
     addToPath(
         (AbstractTreeNode) treeStructure.getRootElement(),
         element,
         result,
         new THashSet<Object>());
   }
   return result;
 }
コード例 #5
0
  public void setReferenceSizeWhileInitializing(Dimension size) {
    _setRefSize(size);

    if (size != null) {
      myAbstractTreeBuilder
          .getReady(this)
          .doWhenDone(
              new Runnable() {
                public void run() {
                  _setRefSize(null);
                }
              });
    }
  }
コード例 #6
0
  public AsyncResult<AbstractTreeNode> expandPathToElement(Object element) {
    if (myAbstractTreeBuilder == null) return new AsyncResult.Rejected<AbstractTreeNode>();

    ArrayList<AbstractTreeNode> pathToElement = getPathToElement(element);
    if (pathToElement.isEmpty()) return new AsyncResult.Rejected<AbstractTreeNode>();

    final AsyncResult<AbstractTreeNode> result = new AsyncResult<AbstractTreeNode>();
    final AbstractTreeNode toExpand = pathToElement.get(pathToElement.size() - 1);
    myAbstractTreeBuilder.expand(
        toExpand,
        new Runnable() {
          public void run() {
            result.setDone(toExpand);
          }
        });

    return result;
  }
コード例 #7
0
 public void doUpdate() {
   assert ApplicationManager.getApplication().isUnitTestMode();
   myAbstractTreeBuilder.addRootToUpdate();
 }
コード例 #8
0
 public AbstractTreeStructure getTreeStructure() {
   return myAbstractTreeBuilder.getTreeStructure();
 }
コード例 #9
0
  public StructureViewComponent(
      final FileEditor editor,
      final StructureViewModel structureViewModel,
      final Project project,
      final boolean showRootNode) {
    super(true, true);

    myProject = project;
    myFileEditor = editor;
    myTreeModel = structureViewModel;
    myTreeModelWrapper = new TreeModelWrapper(myTreeModel, this);

    SmartTreeStructure treeStructure =
        new SmartTreeStructure(project, myTreeModelWrapper) {
          public void rebuildTree() {
            if (!isDisposed()) {
              super.rebuildTree();
            }
          }

          public boolean isToBuildChildrenInBackground(final Object element) {
            return getRootElement() == element;
          }

          protected TreeElementWrapper createTree() {
            return new StructureViewTreeElementWrapper(myProject, myModel.getRoot(), myModel);
          }

          @Override
          public String toString() {
            return "structure view tree structure(model=" + myTreeModel + ")";
          }
        };

    final DefaultTreeModel model =
        new DefaultTreeModel(new DefaultMutableTreeNode(treeStructure.getRootElement()));
    myTree = new Tree(model);
    myTree.setRootVisible(showRootNode);
    myTree.setShowsRootHandles(true);

    myAbstractTreeBuilder =
        new StructureTreeBuilder(
            project,
            myTree,
            (DefaultTreeModel) myTree.getModel(),
            treeStructure,
            myTreeModelWrapper) {
          @Override
          protected boolean validateNode(Object child) {
            return isValid(child);
          }
        };
    Disposer.register(this, myAbstractTreeBuilder);
    Disposer.register(
        myAbstractTreeBuilder,
        new Disposable() {
          public void dispose() {
            storeState();
          }
        });

    setContent(ScrollPaneFactory.createScrollPane(myAbstractTreeBuilder.getTree()));

    myAbstractTreeBuilder.getTree().setCellRenderer(new NodeRenderer());

    myAutoScrollToSourceHandler = new MyAutoScrollToSourceHandler();
    myAutoScrollFromSourceHandler = new MyAutoScrollFromSourceHandler(myProject, this);

    JComponent toolbarComponent =
        ActionManager.getInstance()
            .createActionToolbar(ActionPlaces.STRUCTURE_VIEW_TOOLBAR, createActionGroup(), true)
            .getComponent();
    setToolbar(toolbarComponent);

    installTree();

    myCopyPasteDelegator =
        new CopyPasteDelegator(myProject, getTree()) {
          @NotNull
          protected PsiElement[] getSelectedElements() {
            return getSelectedPsiElements();
          }
        };
  }