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);

Source Link

Usage

From source file:com.android.tools.idea.assistant.OpenAssistSidePanelAction.java

License:Apache License

@Override
public final void actionPerformed(AnActionEvent event) {
    final Project thisProject = event.getProject();
    final String actionId = ActionManager.getInstance().getId(this);

    ApplicationManager.getApplication().invokeLater(() -> {

        AssistToolWindowFactory factory = new AssistToolWindowFactory(actionId);
        ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(thisProject);
        ToolWindow toolWindow = toolWindowManager.getToolWindow(TOOL_WINDOW_TITLE);

        if (toolWindow == null) {
            // NOTE: canWorkInDumbMode must be true or the window will close on gradle sync.
            toolWindow = toolWindowManager.registerToolWindow(TOOL_WINDOW_TITLE, false, ToolWindowAnchor.RIGHT,
                    thisProject, true);//from  w w  w .j a  v a  2s .  c  o m
        }
        toolWindow.setIcon(AndroidIcons.Assistant.Assist);

        factory.createToolWindowContent(thisProject, toolWindow);

        // Always active the window, in case it was previously minimized.
        toolWindow.activate(null);
    });
    onActionPerformed(event);
}

From source file:com.android.tools.idea.gradle.actions.SelectBuildVariantAction.java

License:Apache License

@Override
protected void doPerform(@NotNull AnActionEvent e, @NotNull final Project project) {
    final Module module = getSelectedAndroidModule(e);
    if (module != null) {
        ToolWindowManager manager = ToolWindowManager.getInstance(project);
        ToolWindow toolWindow = manager.getToolWindow(BuildVariantToolWindowFactory.ID);
        if (toolWindow != null) {
            toolWindow.activate(new Runnable() {
                @Override/*from   w w w  .  jav a  2s . c  o  m*/
                public void run() {
                    BuildVariantView view = BuildVariantView.getInstance(project);
                    view.findAndSelectVariantEditor(module);
                }
            });
        }
    }
}

From source file:com.anecdote.ideaplugins.commitlog.CommitLogWindow.java

License:Apache License

public void ensureVisible(Project project) {
    if (project == null) {
        return;// w  w w  . j ava  2s .  c  om
    }
    ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
    if (toolWindowManager != null) {
        ToolWindow toolWindow = toolWindowManager.getToolWindow(COMMIT_LOGS_TOOLWINDOW_ID);
        if (toolWindow != null) {
            toolWindow.activate(null);
        }
    }
}

From source file:com.ansorgit.plugins.bash.runner.repl.AbstractConsoleRunnerWithHistory.java

License:Apache License

/**
 * Launch process, setup history, actions etc.
 *
 * @throws ExecutionException/*w w w.j  a  v a  2  s. c  om*/
 */
public void initAndRun() throws ExecutionException {
    // Create Server process
    final Process process = createProcess();

    // Init console view
    myConsoleView = createConsoleView();

    myProcessHandler = createProcessHandler(process);

    ProcessTerminatedListener.attach(myProcessHandler);

    myProcessHandler.addProcessListener(new ProcessAdapter() {
        @Override
        public void processTerminated(ProcessEvent event) {
            myRunAction.getTemplatePresentation().setEnabled(false);
            myConsoleView.getConsole().setPrompt("");
            myConsoleView.getConsole().getConsoleEditor().setRendererMode(true);
            ApplicationManager.getApplication().invokeLater(new Runnable() {
                public void run() {
                    myConsoleView.getConsole().getConsoleEditor().getComponent().updateUI();
                }
            });
        }
    });

    // Attach to process
    myConsoleView.attachToProcess(myProcessHandler);

    // Runner creating
    final Executor defaultExecutor = ExecutorRegistry.getInstance()
            .getExecutorById(DefaultRunExecutor.EXECUTOR_ID);
    final DefaultActionGroup toolbarActions = new DefaultActionGroup();
    final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN,
            toolbarActions, false);

    // Runner creating
    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(actionToolbar.getComponent(), BorderLayout.WEST);
    panel.add(myConsoleView.getComponent(), BorderLayout.CENTER);

    final RunContentDescriptor myDescriptor = new RunContentDescriptor(myConsoleView, myProcessHandler, panel,
            myConsoleTitle);

    // tool bar actions
    final AnAction[] actions = fillToolBarActions(toolbarActions, defaultExecutor, myDescriptor);
    registerActionShortcuts(actions, getLanguageConsole().getConsoleEditor().getComponent());
    registerActionShortcuts(actions, panel);
    panel.updateUI();

    // Show in run toolwindow
    ExecutionManager.getInstance(myProject).getContentManager().showRunContent(defaultExecutor, myDescriptor);

    // Request focus
    final ToolWindow window = ToolWindowManager.getInstance(myProject).getToolWindow(defaultExecutor.getId());
    window.activate(new Runnable() {
        public void run() {
            IdeFocusManager.getInstance(myProject)
                    .requestFocus(getLanguageConsole().getCurrentEditor().getContentComponent(), true);
        }
    });

    // Run
    myProcessHandler.startNotify();
}

From source file:com.boxysystems.libraryfinder.view.intellij.IntelliJLibraryFinderView.java

License:Apache License

private void showResultsPanelInToolWindow() {
    ToolWindow toolWindow = ToolWindowManager.getInstance(plugin.getProject())
            .getToolWindow(Constants.PLUGIN_ID);
    toolWindow.setAvailable(true, null);
    if (toolWindow.isActive()) {
        toolWindow.show(resultsPanel);/* w w w  . j  a v  a 2 s .  c o  m*/
    } else {
        toolWindow.activate(resultsPanel);
    }
}

From source file:com.demonwav.mcdev.platform.mixin.actions.FindMixinsAction.java

License:Open Source License

@Override
public void actionPerformed(AnActionEvent e) {
    if (e.getProject() == null) {
        return;/*from  ww w  .  j  a  v a 2s  . c om*/
    }
    final Project project = e.getProject();

    final PsiFile file = e.getData(CommonDataKeys.PSI_FILE);
    if (file == null) {
        return;
    }

    final Caret caret = e.getData(CommonDataKeys.CARET);
    if (caret == null) {
        return;
    }

    final Editor editor = e.getData(CommonDataKeys.EDITOR);
    if (editor == null) {
        return;
    }

    final PsiElement element = file.findElementAt(caret.getOffset());
    final PsiClass classOfElement = McPsiUtil.getClassOfElement(element);

    if (classOfElement == null) {
        return;
    }

    // Get on the main thread
    ApplicationManager.getApplication().invokeLater(() -> {
        // Get off the main thread
        ProgressManager.getInstance().run(new Task.Backgroundable(project, "Searching for Mixins", true, null) {
            @Override
            public boolean shouldStartInBackground() {
                return false;
            }

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                final Set<PsiClass> classes = new HashSet<>();
                // Get permission
                try (final AccessToken ignored = ApplicationManager.getApplication().acquireReadActionLock()) {
                    indicator.setIndeterminate(true);

                    final AllClassesSearchExecutor executor = new AllClassesSearchExecutor();
                    executor.execute(new AllClassesSearch.SearchParameters(
                            GlobalSearchScope.projectScope(project), project), psiClass -> {
                                indicator.setText("Checking " + psiClass.getName() + "...");

                                final Map<PsiElement, PsiClass> allMixedClasses = MixinUtils
                                        .getAllMixedClasses(psiClass);

                                if (allMixedClasses.values().stream().anyMatch(c -> c.getQualifiedName() != null
                                        && c.getQualifiedName().equals(classOfElement.getQualifiedName()))) {
                                    classes.add(psiClass);
                                }
                                return true;
                            });
                }

                ApplicationManager.getApplication().invokeLater(() -> {
                    if (classes.size() == 1) {
                        McEditorUtil.gotoTargetElement(classes.iterator().next(), editor, file);
                    } else {
                        ToolWindowManager.getInstance(project).unregisterToolWindow(TOOL_WINDOW_ID);
                        final ToolWindow window = ToolWindowManager.getInstance(project)
                                .registerToolWindow(TOOL_WINDOW_ID, true, ToolWindowAnchor.BOTTOM);
                        window.setIcon(MixinAssets.MIXIN_CLASS_ICON);

                        // Sort the results so it appears nicer
                        final List<PsiClass> classesList = new ArrayList<>(classes);
                        Collections.sort(classesList, (c1, c2) -> {
                            final Pair<String, PsiClass> pair1 = McPsiUtil.getNameOfClass(c1);
                            final Pair<String, PsiClass> pair2 = McPsiUtil.getNameOfClass(c2);

                            if (pair1 == null && pair2 == null) {
                                return 0;
                            } else if (pair1 == null) {
                                return -1;
                            } else if (pair2 == null) {
                                return 1;
                            }

                            final String name1 = pair1.getSecond().getName() + pair1.getFirst();
                            final String name2 = pair2.getSecond().getName() + pair2.getFirst();

                            return name1.compareTo(name2);
                        });

                        final FindMixinsComponent component = new FindMixinsComponent(classesList);

                        final ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
                        final Content content = contentFactory.createContent(component.getPanel(), null, false);
                        window.getContentManager().addContent(content);

                        window.activate(null);
                    }
                });
            }
        });
    });
}

From source file:com.google.idea.blaze.base.console.BlazeConsoleServiceImpl.java

License:Open Source License

@Override
public void activateConsoleWindow() {
    ToolWindow toolWindow = ToolWindowManager.getInstance(project)
            .getToolWindow(BlazeConsoleToolWindowFactory.ID);
    if (toolWindow != null) {
        toolWindow.activate(null);
    }/*w ww . j a  v  a  2  s . c  o m*/
}

From source file:com.google.idea.blaze.clwb.wizard2.BlazeCProjectCreator.java

License:Open Source License

@Nullable
private Project doCreate() throws IOException {
    final ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
    final String projectFilePath = wizardContext.getProjectFileDirectory();

    try {/*from w  ww.j  a v a2s. c  o  m*/
        File projectDir = new File(projectFilePath).getParentFile();
        LOG.assertTrue(projectDir != null,
                "Cannot create project in '" + projectFilePath + "': no parent file exists");
        FileUtil.ensureExists(projectDir);
        if (wizardContext.getProjectStorageFormat() == StorageScheme.DIRECTORY_BASED) {
            final File ideaDir = new File(projectFilePath, Project.DIRECTORY_STORE_FOLDER);
            FileUtil.ensureExists(ideaDir);
        }

        String name = wizardContext.getProjectName();
        Project newProject = projectBuilder.createProject(name, projectFilePath);
        if (newProject == null) {
            return null;
        }

        if (!ApplicationManager.getApplication().isUnitTestMode()) {
            newProject.save();
        }

        if (!projectBuilder.validate(null, newProject)) {
            return null;
        }

        projectBuilder.commit(newProject, null, ModulesProvider.EMPTY_MODULES_PROVIDER);

        StartupManager.getInstance(newProject).registerPostStartupActivity(() -> {
            // ensure the dialog is shown after all startup activities are done
            //noinspection SSBasedInspection
            SwingUtilities.invokeLater(() -> {
                if (newProject.isDisposed() || ApplicationManager.getApplication().isUnitTestMode()) {
                    return;
                }
                ApplicationManager.getApplication().invokeLater(() -> {
                    if (newProject.isDisposed()) {
                        return;
                    }
                    final ToolWindow toolWindow = ToolWindowManager.getInstance(newProject)
                            .getToolWindow(ToolWindowId.PROJECT_VIEW);
                    if (toolWindow != null) {
                        toolWindow.activate(null);
                    }
                }, ModalityState.NON_MODAL);
            });
        });

        ProjectUtil.updateLastProjectLocation(projectFilePath);

        if (WindowManager.getInstance().isFullScreenSupportedInCurrentOS()) {
            IdeFocusManager instance = IdeFocusManager.findInstance();
            IdeFrame lastFocusedFrame = instance.getLastFocusedFrame();
            if (lastFocusedFrame instanceof IdeFrameEx) {
                boolean fullScreen = ((IdeFrameEx) lastFocusedFrame).isInFullScreen();
                if (fullScreen) {
                    newProject.putUserData(IdeFrameImpl.SHOULD_OPEN_IN_FULL_SCREEN, Boolean.TRUE);
                }
            }
        }

        projectManager.openProject(newProject);

        if (!ApplicationManager.getApplication().isUnitTestMode()) {
            newProject.save();
        }
        return newProject;
    } finally {
        projectBuilder.cleanup();
    }
}

From source file:com.igormaznitsa.ideamindmap.utils.SelectIn.java

License:Apache License

private static void projectFocusTo(final Project project, final VirtualFile file) {
    final ProjectView view = ProjectView.getInstance(project);

    String viewToActivate = ProjectViewPane.ID;

    if (KnowledgeViewPane.ID.equals(view.getCurrentViewId())) {
        final Module theModule = ModuleUtil.findModuleForFile(file, project);
        if (theModule == null) {
            viewToActivate = null;// w ww. ja  v  a  2s. c om
        } else {
            final VirtualFile knowledgeFolder = IdeaUtils.findKnowledgeFolderForModule(theModule, false);
            if (knowledgeFolder != null && VfsUtil.isAncestor(knowledgeFolder, file, true)) {
                viewToActivate = KnowledgeViewPane.ID;
            }
        }
    }

    if (viewToActivate != null) {
        view.changeView(viewToActivate);
    }

    final ToolWindow toolwindow = ToolWindowManager.getInstance(project)
            .getToolWindow(ToolWindowId.PROJECT_VIEW);
    if (toolwindow != null)
        toolwindow.activate(new Runnable() {
            @Override
            public void run() {
                view.select(null, file, true);
            }
        });
}

From source file:com.intellij.ide.errorTreeView.actions.TestErrorViewAction.java

License:Apache License

protected void openView(Project project, JComponent component) {
    final MessageView messageView = MessageView.SERVICE.getInstance(project);
    final Content content = ContentFactory.SERVICE.getInstance().createContent(component, getContentName(),
            true);//from w w  w  .  jav  a2s.  c om
    messageView.getContentManager().addContent(content);
    messageView.getContentManager().setSelectedContent(content);
    ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.MESSAGES_WINDOW);
    if (toolWindow != null) {
        toolWindow.activate(null);
    }
}