Example usage for com.intellij.openapi.wm ToolWindow activate

List of usage examples for com.intellij.openapi.wm ToolWindow activate

Introduction

In this page you can find the example usage for com.intellij.openapi.wm ToolWindow activate.

Prototype

void activate(@Nullable Runnable runnable, boolean autoFocusContents, boolean forced);

Source Link

Usage

From source file:com.android.tools.idea.run.editor.AndroidDebuggerImplBase.java

License:Apache License

protected static boolean activateDebugSessionWindow(@NotNull Project project,
        @NotNull RunContentDescriptor descriptor) {
    final ProcessHandler processHandler = descriptor.getProcessHandler();
    final Content content = descriptor.getAttachedContent();

    if (processHandler == null || content == null) {
        return false;
    }//from   ww w .j  av a  2s . c  om

    final Executor executor = DefaultDebugExecutor.getDebugExecutorInstance();

    if (processHandler.isProcessTerminated()) {
        ExecutionManager.getInstance(project).getContentManager().removeRunContent(executor, descriptor);
        return false;
    }
    content.getManager().setSelectedContent(content);
    ToolWindow window = ToolWindowManager.getInstance(project).getToolWindow(executor.getToolWindowId());
    window.activate(null, false, true);
    return true;
}

From source file:com.android.tools.idea.run.util.LaunchUtils.java

License:Apache License

public static void showNotification(@NotNull final Project project, @NotNull final Executor executor,
        @NotNull final String sessionName, @NotNull final String message,
        @NotNull final NotificationType type) {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override//from w  w w . j  av a 2  s .c o  m
        public void run() {
            if (project.isDisposed()) {
                return;
            }

            String toolWindowId = executor.getToolWindowId();
            final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(toolWindowId);
            if (toolWindow.isVisible()) {
                return;
            }

            final String notificationMessage = "Session <a href=''>'" + sessionName + "'</a>: " + message;

            NotificationGroup group = getNotificationGroup(toolWindowId);
            group.createNotification("", notificationMessage, type, new NotificationListener() {
                @Override
                public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
                    if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                        final RunContentManager contentManager = ExecutionManager.getInstance(project)
                                .getContentManager();

                        for (RunContentDescriptor d : contentManager.getAllDescriptors()) {
                            if (sessionName.equals(d.getDisplayName())) {
                                final Content content = d.getAttachedContent();
                                if (content != null) {
                                    content.getManager().setSelectedContent(content);
                                }
                                toolWindow.activate(null, true, true);
                                break;
                            }
                        }
                    }
                }
            }).notify(project);
        }

        @NotNull
        private NotificationGroup getNotificationGroup(@NotNull String toolWindowId) {
            String displayId = "Launch Notifications for " + toolWindowId;
            NotificationGroup group = NotificationGroup.findRegisteredGroup(displayId);
            if (group == null) {
                group = NotificationGroup.toolWindowGroup(displayId, toolWindowId);
            }
            return group;
        }
    });
}

From source file:com.google.idea.blaze.base.scope.scopes.IssuesScope.java

License:Open Source License

private void focusProblemsView() {
    ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
    ToolWindow toolWindow = toolWindowManager.getToolWindow("Problems");
    if (toolWindow != null) {
        toolWindow.activate(null, false, false);
    }/*from  w ww.  j a va  2s .co m*/
}

From source file:com.intellij.execution.ui.RunContentManagerImpl.java

License:Apache License

public void showRunContent(@NotNull final Executor executor, @NotNull final RunContentDescriptor descriptor,
        final long executionId) {
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        return;// www.  j  a  va  2s.c o m
    }

    final ContentManager contentManager = getContentManagerForRunner(executor);
    RunContentDescriptor oldDescriptor = chooseReuseContentForDescriptor(contentManager, descriptor,
            executionId, descriptor.getDisplayName());
    final Content content;
    if (oldDescriptor == null) {
        content = createNewContent(contentManager, descriptor, executor);
        Icon icon = descriptor.getIcon();
        content.setIcon(icon == null ? executor.getToolWindowIcon() : icon);
    } else {
        content = oldDescriptor.getAttachedContent();
        LOG.assertTrue(content != null);
        getSyncPublisher().contentRemoved(oldDescriptor, executor);
        Disposer.dispose(oldDescriptor); // is of the same category, can be reused
    }

    content.setExecutionId(executionId);
    content.setComponent(descriptor.getComponent());
    content.setPreferredFocusedComponent(descriptor.getPreferredFocusComputable());
    content.putUserData(DESCRIPTOR_KEY, descriptor);
    final ToolWindow toolWindow = ToolWindowManager.getInstance(myProject)
            .getToolWindow(executor.getToolWindowId());
    final ProcessHandler processHandler = descriptor.getProcessHandler();
    if (processHandler != null) {
        final ProcessAdapter processAdapter = new ProcessAdapter() {
            @Override
            public void startNotified(final ProcessEvent event) {
                UIUtil.invokeLaterIfNeeded(new Runnable() {
                    @Override
                    public void run() {
                        content.setIcon(ExecutionUtil.getLiveIndicator(descriptor.getIcon()));
                        toolWindow.setIcon(ExecutionUtil
                                .getLiveIndicator(myToolwindowIdToBaseIconMap.get(executor.getToolWindowId())));
                    }
                });
            }

            @Override
            public void processTerminated(final ProcessEvent event) {
                ApplicationManager.getApplication().invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        boolean alive = false;
                        String toolWindowId = executor.getToolWindowId();
                        ContentManager manager = myToolwindowIdToContentManagerMap.get(toolWindowId);
                        if (manager == null)
                            return;
                        for (Content content : manager.getContents()) {
                            RunContentDescriptor descriptor = getRunContentDescriptorByContent(content);
                            if (descriptor != null) {
                                ProcessHandler handler = descriptor.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);
                }
            });
        }
    }
    content.setDisplayName(descriptor.getDisplayName());
    descriptor.setAttachedContent(content);
    content.getManager().setSelectedContent(content);

    if (!descriptor.isActivateToolWindowWhenAdded()) {
        return;
    }

    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        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 stacktrace wont
            // work correctly
            descriptor.getPreferredFocusComputable();
            window.activate(descriptor.getActivationCallback(), descriptor.isAutoFocusContent(),
                    descriptor.isAutoFocusContent());
        }
    }, myProject.getDisposed());
}

From source file:org.jetbrains.android.actions.AndroidProcessChooserDialog.java

License:Apache License

private void closeOldSessionAndRun(final String debugPort) {
    final String configurationName = getRunConfigurationName(debugPort);
    final Collection<RunContentDescriptor> descriptors = ExecutionHelper.findRunningConsoleByTitle(myProject,
            new NotNullFunction<String, Boolean>() {
                @NotNull/*from  w  w  w .j a  v  a 2s . c o m*/
                @Override
                public Boolean fun(String title) {
                    return configurationName.equals(title);
                }
            });

    if (descriptors.size() > 0) {
        final RunContentDescriptor descriptor = descriptors.iterator().next();
        final ProcessHandler processHandler = descriptor.getProcessHandler();
        final Content content = descriptor.getAttachedContent();

        if (processHandler != null && content != null) {
            final Executor executor = DefaultDebugExecutor.getDebugExecutorInstance();

            if (processHandler.isProcessTerminated()) {
                ExecutionManager.getInstance(myProject).getContentManager().removeRunContent(executor,
                        descriptor);
            } else {
                content.getManager().setSelectedContent(content);
                ToolWindow window = ToolWindowManager.getInstance(myProject)
                        .getToolWindow(executor.getToolWindowId());
                window.activate(null, false, true);
                return;
            }
        }
    }

    runSession(debugPort);
}

From source file:org.jetbrains.android.run.AndroidDebugRunner.java

License:Apache License

private static void showNotification(final Project project, final Executor executor,
        final RunContentDescriptor descriptor, final String status, final boolean notifySelectedContent,
        final NotificationType type) {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override/*w w  w.j a  v a  2s  .co m*/
        public void run() {
            if (project.isDisposed()) {
                return;
            }
            final String sessionName = descriptor.getDisplayName();
            final ToolWindow toolWindow = ToolWindowManager.getInstance(project)
                    .getToolWindow(executor.getToolWindowId());
            final Content content = descriptor.getAttachedContent();
            final String notificationMessage;
            if (content != null && content.isSelected() && toolWindow.isVisible()) {
                if (!notifySelectedContent) {
                    return;
                }
                notificationMessage = "Session '" + sessionName + "': " + status;
            } else {
                notificationMessage = "Session <a href=''>'" + sessionName + "'</a>: " + status;
            }

            NotificationGroup.toolWindowGroup("Android Session Restarted", executor.getToolWindowId(), true)
                    .createNotification("", notificationMessage, type, new NotificationListener() {
                        @Override
                        public void hyperlinkUpdate(@NotNull Notification notification,
                                @NotNull HyperlinkEvent event) {
                            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                                final RunContentManager contentManager = ExecutionManager.getInstance(project)
                                        .getContentManager();

                                for (RunContentDescriptor d : contentManager.getAllDescriptors()) {
                                    if (d.equals(descriptor)) {
                                        final Content content = d.getAttachedContent();
                                        content.getManager().setSelectedContent(content);
                                        toolWindow.activate(null, true, true);
                                        break;
                                    }
                                }
                            }
                        }
                    }).notify(project);
        }
    });
}