Search in sources :

Example 81 with ToolWindow

use of com.intellij.openapi.wm.ToolWindow in project intellij-community by JetBrains.

the class RunContentManagerImpl method showRunContent.

private void showRunContent(@NotNull final Executor executor, @NotNull final RunContentDescriptor descriptor, final long executionId) {
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        return;
    }
    final ContentManager contentManager = getContentManagerForRunner(executor, descriptor);
    RunContentDescriptor oldDescriptor = chooseReuseContentForDescriptor(contentManager, descriptor, executionId, descriptor.getDisplayName());
    final Content content;
    if (oldDescriptor == null) {
        content = createNewContent(descriptor, executor);
    } else {
        content = oldDescriptor.getAttachedContent();
        LOG.assertTrue(content != null);
        getSyncPublisher().contentRemoved(oldDescriptor, executor);
        // is of the same category, can be reused
        Disposer.dispose(oldDescriptor);
    }
    content.setExecutionId(executionId);
    content.setComponent(descriptor.getComponent());
    content.setPreferredFocusedComponent(descriptor.getPreferredFocusComputable());
    content.putUserData(RunContentDescriptor.DESCRIPTOR_KEY, descriptor);
    content.putUserData(EXECUTOR_KEY, executor);
    content.setDisplayName(descriptor.getDisplayName());
    descriptor.setAttachedContent(content);
    String toolWindowId = getToolWindowIdForRunner(executor, descriptor);
    final ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(toolWindowId);
    final ProcessHandler processHandler = descriptor.getProcessHandler();
    if (processHandler != null) {
        final ProcessAdapter processAdapter = new ProcessAdapter() {

            @Override
            public void startNotified(final ProcessEvent event) {
                UIUtil.invokeLaterIfNeeded(() -> {
                    content.setIcon(ExecutionUtil.getLiveIndicator(descriptor.getIcon()));
                    toolWindow.setIcon(ExecutionUtil.getLiveIndicator(myToolwindowIdToBaseIconMap.get(toolWindowId)));
                });
            }

            @Override
            public void processTerminated(final ProcessEvent event) {
                ApplicationManager.getApplication().invokeLater(() -> {
                    boolean alive = false;
                    ContentManager manager = myToolwindowIdToContentManagerMap.get(toolWindowId);
                    if (manager == null)
                        return;
                    for (Content content1 : manager.getContents()) {
                        RunContentDescriptor descriptor1 = getRunContentDescriptorByContent(content1);
                        if (descriptor1 != null) {
                            ProcessHandler handler = descriptor1.getProcessHandler();
                            if (handler != null && !handler.isProcessTerminated()) {
                                alive = true;
                                break;
                            }
                        }
                    }
                    Icon base = myToolwindowIdToBaseIconMap.get(toolWindowId);
                    toolWindow.setIcon(alive ? ExecutionUtil.getLiveIndicator(base) : base);
                    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() {

                @Override
                public void dispose() {
                    processHandler.removeProcessListener(processAdapter);
                }
            });
        }
    }
    if (oldDescriptor == null) {
        contentManager.addContent(content);
        new CloseListener(content, executor);
    }
    content.getManager().setSelectedContent(content);
    if (!descriptor.isActivateToolWindowWhenAdded()) {
        return;
    }
    ApplicationManager.getApplication().invokeLater(() -> {
        ToolWindow window = ToolWindowManager.getInstance(myProject).getToolWindow(toolWindowId);
        // 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 stacktrace wont
        // work correctly
        descriptor.getPreferredFocusComputable();
        window.activate(descriptor.getActivationCallback(), descriptor.isAutoFocusContent(), descriptor.isAutoFocusContent());
    }, myProject.getDisposed());
}
Also used : Disposable(com.intellij.openapi.Disposable) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) ToolWindow(com.intellij.openapi.wm.ToolWindow) ProcessHandler(com.intellij.execution.process.ProcessHandler)

Example 82 with ToolWindow

use of com.intellij.openapi.wm.ToolWindow in project intellij-community by JetBrains.

the class RunContentManagerImpl method registerToolWindow.

private void registerToolWindow(@NotNull final Executor executor, @NotNull ToolWindowManagerEx toolWindowManager) {
    final String toolWindowId = executor.getToolWindowId();
    if (toolWindowManager.getToolWindow(toolWindowId) != null) {
        return;
    }
    final ToolWindow toolWindow = toolWindowManager.registerToolWindow(toolWindowId, true, ToolWindowAnchor.BOTTOM, this, true);
    final ContentManager contentManager = toolWindow.getContentManager();
    contentManager.addDataProvider(new DataProvider() {

        private int myInsideGetData = 0;

        @Override
        public Object getData(String dataId) {
            myInsideGetData++;
            try {
                if (PlatformDataKeys.HELP_ID.is(dataId)) {
                    return executor.getHelpId();
                } else {
                    return myInsideGetData == 1 ? DataManager.getInstance().getDataContext(contentManager.getComponent()).getData(dataId) : null;
                }
            } finally {
                myInsideGetData--;
            }
        }
    });
    toolWindow.setIcon(executor.getToolWindowIcon());
    new ContentManagerWatcher(toolWindow, contentManager);
    initToolWindow(executor, toolWindowId, executor.getToolWindowIcon(), contentManager);
}
Also used : DataProvider(com.intellij.openapi.actionSystem.DataProvider) ToolWindow(com.intellij.openapi.wm.ToolWindow) ContentManagerWatcher(com.intellij.ide.impl.ContentManagerWatcher)

Example 83 with ToolWindow

use of com.intellij.openapi.wm.ToolWindow in project intellij-community by JetBrains.

the class NavigateFromSourceTest method testAutoscrollFromSourceOnOpening.

public void testAutoscrollFromSourceOnOpening() throws Exception {
    final PsiClass[] classes = JavaDirectoryService.getInstance().getClasses(getPackageDirectory());
    PsiClass psiClass = classes[0];
    FileEditorManager.getInstance(getProject()).openFile(psiClass.getContainingFile().getVirtualFile(), true);
    ProjectView projectView = ProjectView.getInstance(getProject());
    ((ProjectViewImpl) projectView).setAutoscrollFromSource(true, ProjectViewPane.ID);
    ToolWindow toolWindow = ToolWindowManager.getInstance(getProject()).getToolWindow(ToolWindowId.PROJECT_VIEW);
    new ProjectViewToolWindowFactory().createToolWindowContent(getProject(), toolWindow);
    projectView.changeView(ProjectViewPane.ID);
    UIUtil.dispatchAllInvocationEvents();
    JComponent component = ((ProjectViewImpl) projectView).getComponent();
    DataContext context = DataManager.getInstance().getDataContext(component);
    PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context);
    assertEquals("Class1.java", ((PsiJavaFile) element).getName());
}
Also used : ToolWindow(com.intellij.openapi.wm.ToolWindow) DataContext(com.intellij.openapi.actionSystem.DataContext) ProjectView(com.intellij.ide.projectView.ProjectView) ProjectViewImpl(com.intellij.ide.projectView.impl.ProjectViewImpl) ProjectViewToolWindowFactory(com.intellij.ide.projectView.impl.ProjectViewToolWindowFactory)

Example 84 with ToolWindow

use of com.intellij.openapi.wm.ToolWindow in project intellij-community by JetBrains.

the class ProjectToolWindowTest method testProjectViewActivate.

public void testProjectViewActivate() throws Exception {
    ToolWindowEP[] extensions = Extensions.getExtensions(ToolWindowEP.EP_NAME);
    for (ToolWindowEP extension : extensions) {
        if (ToolWindowId.PROJECT_VIEW.equals(extension.id)) {
            myManager.initToolWindow(extension);
        }
    }
    DesktopLayout layout = myManager.getLayout();
    WindowInfoImpl info = layout.getInfo(ToolWindowId.PROJECT_VIEW, false);
    assertFalse(info.isVisible());
    info.setVisible(true);
    ToolWindow window = myManager.getToolWindow(ToolWindowId.PROJECT_VIEW);
    assertTrue(window.isVisible());
    ProjectView.getInstance(getProject());
    ProjectViewSharedSettings.Companion.getInstance().setAutoscrollFromSource(true);
    try {
        window.activate(null);
    } finally {
        // cleanup
        info.setVisible(false);
    }
}
Also used : ToolWindow(com.intellij.openapi.wm.ToolWindow) ToolWindowEP(com.intellij.openapi.wm.ToolWindowEP)

Example 85 with ToolWindow

use of com.intellij.openapi.wm.ToolWindow in project intellij-community by JetBrains.

the class UsageContextDataflowToPanel method createPanel.

@NotNull
protected JComponent createPanel(@NotNull PsiElement element, final boolean dataFlowToThis) {
    ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.FIND);
    SliceAnalysisParams params = createParams(element, dataFlowToThis);
    SliceRootNode rootNode = new SliceRootNode(myProject, new DuplicateMap(), JavaSliceUsage.createRootUsage(element, params));
    return new SlicePanel(myProject, dataFlowToThis, rootNode, false, toolWindow) {

        @Override
        public boolean isToShowAutoScrollButton() {
            return false;
        }

        @Override
        public boolean isToShowPreviewButton() {
            return false;
        }

        @Override
        public boolean isToShowCloseButton() {
            return false;
        }

        @Override
        public boolean isAutoScroll() {
            return false;
        }

        @Override
        public void setAutoScroll(boolean autoScroll) {
        }

        @Override
        public boolean isPreview() {
            return false;
        }

        @Override
        public void setPreview(boolean preview) {
        }
    };
}
Also used : ToolWindow(com.intellij.openapi.wm.ToolWindow) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ToolWindow (com.intellij.openapi.wm.ToolWindow)124 Content (com.intellij.ui.content.Content)37 ToolWindowManager (com.intellij.openapi.wm.ToolWindowManager)34 Project (com.intellij.openapi.project.Project)21 ContentManager (com.intellij.ui.content.ContentManager)14 ToolWindowManagerEx (com.intellij.openapi.wm.ex.ToolWindowManagerEx)13 Nullable (org.jetbrains.annotations.Nullable)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 ConsoleView (com.intellij.execution.ui.ConsoleView)5 ToolWindowManagerAdapter (com.intellij.openapi.wm.ex.ToolWindowManagerAdapter)5 NotNull (org.jetbrains.annotations.NotNull)5 RunContentManager (com.intellij.execution.ui.RunContentManager)4 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)3 ProcessEvent (com.intellij.execution.process.ProcessEvent)3 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)3 ProjectView (com.intellij.ide.projectView.ProjectView)3 Presentation (com.intellij.openapi.actionSystem.Presentation)3 DumbAwareRunnable (com.intellij.openapi.project.DumbAwareRunnable)3 ChangesViewContentManager (com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager)3 ToolWindowEP (com.intellij.openapi.wm.ToolWindowEP)3