Beispiel #1
0
  public void initToolWindow(ToolWindow toolWindow) {
    // Create panels

    Content allTodosContent =
        ContentFactory.SERVICE
            .getInstance()
            .createContent(null, IdeBundle.message("title.project"), false);
    myAllTodos =
        new TodoPanel(myProject, myAllPanelSettings, false, allTodosContent) {
          protected TodoTreeBuilder createTreeBuilder(
              JTree tree, DefaultTreeModel treeModel, Project project) {
            AllTodosTreeBuilder builder = new AllTodosTreeBuilder(tree, treeModel, project);
            builder.init();
            return builder;
          }
        };
    allTodosContent.setComponent(myAllTodos);
    Disposer.register(this, myAllTodos);

    Content currentFileTodosContent =
        ContentFactory.SERVICE
            .getInstance()
            .createContent(null, IdeBundle.message("title.todo.current.file"), false);
    myCurrentFileTodos =
        new CurrentFileTodosPanel(myProject, myCurrentPanelSettings, currentFileTodosContent) {
          protected TodoTreeBuilder createTreeBuilder(
              JTree tree, DefaultTreeModel treeModel, Project project) {
            CurrentFileTodosTreeBuilder builder =
                new CurrentFileTodosTreeBuilder(tree, treeModel, project);
            builder.init();
            return builder;
          }
        };
    Disposer.register(this, myCurrentFileTodos);
    currentFileTodosContent.setComponent(myCurrentFileTodos);

    myChangeListTodosContent =
        ContentFactory.SERVICE
            .getInstance()
            .createContent(
                null,
                IdeBundle.message(
                    "changelist.todo.title",
                    ChangeListManager.getInstance(myProject).getDefaultChangeList().getName()),
                false);
    myChangeListTodos =
        new ChangeListTodosPanel(myProject, myCurrentPanelSettings, myChangeListTodosContent) {
          protected TodoTreeBuilder createTreeBuilder(
              JTree tree, DefaultTreeModel treeModel, Project project) {
            ChangeListTodosTreeBuilder builder =
                new ChangeListTodosTreeBuilder(tree, treeModel, project);
            builder.init();
            return builder;
          }
        };
    Disposer.register(this, myChangeListTodos);
    myChangeListTodosContent.setComponent(myChangeListTodos);

    myContentManager = toolWindow.getContentManager();

    myContentManager.addContent(allTodosContent);
    myContentManager.addContent(currentFileTodosContent);
    if (myVCSManager.getAllActiveVcss().length > 0) {
      myVcsListener.myIsVisible = true;
      myContentManager.addContent(myChangeListTodosContent);
    }

    Content content = myContentManager.getContent(mySelectedIndex);
    content = content == null ? allTodosContent : content;
    myContentManager.setSelectedContent(content);
  }
  public void showRunContent(
      @NotNull final Executor executor, final RunContentDescriptor descriptor) {
    if (ApplicationManager.getApplication().isUnitTestMode()) return;

    final ContentManager contentManager = getContentManagerForRunner(executor);
    RunContentDescriptor oldDescriptor =
        chooseReuseContentForDescriptor(contentManager, descriptor);

    final Content content;

    if (oldDescriptor != null) {
      content = oldDescriptor.getAttachedContent();
      getSyncPublisher().contentRemoved(oldDescriptor, executor);
      oldDescriptor.dispose(); // is of the same category, can be reused
    } else {
      content = createNewContent(contentManager, descriptor, executor);
      final Icon icon = descriptor.getIcon();
      content.setIcon(icon == null ? executor.getToolWindowIcon() : icon);
    }

    content.setComponent(descriptor.getComponent());
    content.putUserData(DESCRIPTOR_KEY, descriptor);
    final ProcessHandler processHandler = descriptor.getProcessHandler();
    if (processHandler != null) {
      final ProcessAdapter processAdapter =
          new ProcessAdapter() {
            public void startNotified(final ProcessEvent event) {
              LaterInvocator.invokeLater(
                  new Runnable() {
                    public void run() {
                      final Icon icon = descriptor.getIcon();
                      content.setIcon(icon == null ? executor.getToolWindowIcon() : icon);
                    }
                  });
            }

            public void processTerminated(final ProcessEvent event) {
              LaterInvocator.invokeLater(
                  new Runnable() {
                    public void run() {
                      final Icon icon = descriptor.getIcon();
                      content.setIcon(
                          icon == null
                              ? executor.getDisabledIcon()
                              : IconLoader.getTransparentIcon(icon));
                    }
                  });
            }
          };
      processHandler.addProcessListener(processAdapter);
      final Disposable disposer = content.getDisposer();
      if (disposer != null) {
        Disposer.register(
            disposer,
            new Disposable() {
              public void dispose() {
                processHandler.removeProcessListener(processAdapter);
              }
            });
      }
    }
    content.setDisplayName(descriptor.getDisplayName());
    descriptor.setAttachedContent(content);
    content.getManager().setSelectedContent(content);

    ApplicationManager.getApplication()
        .invokeLater(
            new Runnable() {
              public void run() {
                ToolWindow window =
                    ToolWindowManager.getInstance(myProject)
                        .getToolWindow(executor.getToolWindowId());
                // let's activate tool window, but don't move focus
                //
                // window.show() isn't valid here, because it will not
                // mark the window as "last activated" windows and thus
                // some action like navigation up/down in stactrace wont
                // work correctly
                window.activate(null, false, false);
              }
            });
  }