protected void rebuild() {
   storeState();
   ++ourSettingsModificationCount;
   ((SmartTreeStructure) myAbstractTreeBuilder.getTreeStructure()).rebuildTree();
   myAbstractTreeBuilder.updateFromRoot();
   restoreState();
 }
 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;
 }
 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);
   }
 }
 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;
 }
  public void setReferenceSizeWhileInitializing(Dimension size) {
    _setRefSize(size);

    if (size != null) {
      myAbstractTreeBuilder
          .getReady(this)
          .doWhenDone(
              new Runnable() {
                public void run() {
                  _setRefSize(null);
                }
              });
    }
  }
  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;
  }
 public void doUpdate() {
   assert ApplicationManager.getApplication().isUnitTestMode();
   myAbstractTreeBuilder.addRootToUpdate();
 }
 public AbstractTreeStructure getTreeStructure() {
   return myAbstractTreeBuilder.getTreeStructure();
 }
  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();
          }
        };
  }