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

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

Introduction

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

Prototype

void setIcon(@NotNull Icon icon);

Source Link

Document

Sets new window icon.

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 ww  . j  ava  2  s. co 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.monitor.AndroidToolWindowFactory.java

License:Apache License

@Override
public void createToolWindowContent(@NotNull final Project project, @NotNull final ToolWindow toolWindow) {
    // In order to use the runner layout ui, the runner infrastructure needs to be initialized.
    // Otherwise it is not possible to for example drag one of the tabs out of the tool window.
    // The object that needs to be created is the content manager of the execution manager for this project.
    ExecutionManager.getInstance(project).getContentManager();

    RunnerLayoutUi layoutUi = RunnerLayoutUi.Factory.getInstance(project).create("Android", TOOL_WINDOW_ID,
            "Profiling Tools", project);

    toolWindow.setIcon(AndroidIcons.AndroidToolWindow);
    toolWindow.setAvailable(true, null);
    toolWindow.setToHideOnEmptyContent(true);
    toolWindow.setTitle(TOOL_WINDOW_ID);

    DeviceContext deviceContext = new DeviceContext();

    // TODO Remove global handlers. These handlers are global, but are set per project.
    // if there are two projects opened, things go very wrong.
    ClientData.setMethodProfilingHandler(new OpenVmTraceHandler(project));

    Content logcatContent = createLogcatContent(layoutUi, project, deviceContext);
    final AndroidLogcatView logcatView = logcatContent.getUserData(AndroidLogcatView.ANDROID_LOGCAT_VIEW_KEY);
    assert logcatView != null;
    logcatContent.setSearchComponent(logcatView.createSearchComponent());
    layoutUi.addContent(logcatContent, 0, PlaceInGrid.center, false);

    MonitorContentFactory.createMonitorContent(project, deviceContext, layoutUi);

    layoutUi.getOptions().setLeftToolbar(getToolbarActions(project, deviceContext), ActionPlaces.UNKNOWN);
    layoutUi.addListener(new ContentManagerAdapter() {
        @Override/*from w  w  w.java 2 s  .  c  o m*/
        public void selectionChanged(ContentManagerEvent event) {
            Content selectedContent = event.getContent();
            BaseMonitorView view = selectedContent.getUserData(BaseMonitorView.MONITOR_VIEW_KEY);
            if (view != null && event.getOperation() == ContentManagerEvent.ContentOperation.add) {
                UsageTracker.getInstance()
                        .log(AndroidStudioEvent.newBuilder()
                                .setCategory(AndroidStudioEvent.EventCategory.PROFILING)
                                .setKind(AndroidStudioEvent.EventKind.MONITOR_RUNNING)
                                .setMonitorType(view.getMonitorType()));

            }
        }
    }, project);

    final JBLoadingPanel loadingPanel = new JBLoadingPanel(new BorderLayout(), project);

    DevicePanel devicePanel = new DevicePanel(project, deviceContext);
    JPanel panel = devicePanel.getComponent();
    panel.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));
    loadingPanel.add(panel, BorderLayout.NORTH);
    loadingPanel.add(layoutUi.getComponent(), BorderLayout.CENTER);

    final ContentManager contentManager = toolWindow.getContentManager();
    Content c = contentManager.getFactory().createContent(loadingPanel, "", true);

    // Store references to the logcat & device panel views, so that these views can be retrieved directly from
    // the DDMS tool window. (e.g. to clear logcat before a launch, select a particular device, etc)
    c.putUserData(AndroidLogcatView.ANDROID_LOGCAT_VIEW_KEY, logcatView);
    c.putUserData(DEVICES_PANEL_KEY, devicePanel);

    contentManager.addContent(c);

    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
            logcatView.activate();
            final ToolWindow window = ToolWindowManager.getInstance(project).getToolWindow(TOOL_WINDOW_ID);
            if (window != null && window.isVisible()) {
                ConsoleView console = logcatView.getLogConsole().getConsole();
                if (console != null) {
                    checkFacetAndSdk(project, console);
                }
            }
        }
    }, project.getDisposed());

    final File adb = AndroidSdkUtils.getAdb(project);
    if (adb == null) {
        return;
    }

    loadingPanel.setLoadingText("Initializing ADB");
    loadingPanel.startLoading();

    ListenableFuture<AndroidDebugBridge> future = AdbService.getInstance().getDebugBridge(adb);
    Futures.addCallback(future, new FutureCallback<AndroidDebugBridge>() {
        @Override
        public void onSuccess(@Nullable AndroidDebugBridge bridge) {
            Logger.getInstance(AndroidToolWindowFactory.class).info("Successfully obtained debug bridge");
            loadingPanel.stopLoading();
        }

        @Override
        public void onFailure(@NotNull Throwable t) {
            loadingPanel.stopLoading();

            // If we cannot connect to ADB in a reasonable amount of time (10 seconds timeout in AdbService), then something is seriously
            // wrong. The only identified reason so far is that some machines have incompatible versions of adb that were already running.
            // e.g. Genymotion, some HTC flashing software, Ubuntu's adb package may all conflict with the version of adb in the SDK.
            Logger.getInstance(AndroidToolWindowFactory.class).info("Unable to obtain debug bridge", t);
            String msg;
            if (t.getMessage() != null) {
                msg = t.getMessage();
            } else {
                msg = String.format("Unable to establish a connection to adb.\n\n"
                        + "Check the Event Log for possible issues.\n"
                        + "This can happen if you have an incompatible version of adb running already.\n"
                        + "Try re-opening %1$s after killing any existing adb daemons.\n\n"
                        + "If this happens repeatedly, please file a bug at http://b.android.com including the following:\n"
                        + "  1. Output of the command: '%2$s devices'\n"
                        + "  2. Your idea.log file (Help | Show Log in Explorer)\n",
                        ApplicationNamesInfo.getInstance().getProductName(), adb.getAbsolutePath());
            }
            Messages.showErrorDialog(msg, "ADB Connection Error");
        }
    }, EdtExecutor.INSTANCE);
}

From source file:com.android.tools.idea.startup.AndroidStudioInitializer.java

License:Apache License

private static void setUpExperimentalFeatures() {
    if (System.getProperty(ProfilerState.ENABLE_EXPERIMENTAL_PROFILING) != null) {
        ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerAdapter() {
            @Override/* w ww  . j  a  v a  2  s  .co  m*/
            public void projectOpened(final Project project) {
                StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> {
                    ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
                    ToolWindow toolWindow = toolWindowManager.registerToolWindow(
                            AndroidMonitorToolWindowFactory.ID, false, ToolWindowAnchor.BOTTOM, project, true);
                    toolWindow.setIcon(AndroidIcons.AndroidToolWindow);
                    new AndroidMonitorToolWindowFactory().createToolWindowContent(project, toolWindow);
                    toolWindow.show(null);
                });
            }
        });
    }
}

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

License:Apache License

private void initialize() {
    if (!_isInitialized) {
        _isInitialized = true;/*from w ww  .  j  ava 2s .c o m*/
        _isDisposed = false;
        ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(_project);
        ToolWindow toolWindow = toolWindowManager.registerToolWindow(COMMIT_LOGS_TOOLWINDOW_ID, true,
                ToolWindowAnchor.BOTTOM);
        toolWindow.setIcon(COMMIT_LOGS_SMALL_ICON);
        _contentManager = toolWindow.getContentManager();
        toolWindow.installWatcher(_contentManager);
        //      _contentManager = PeerFactory.getInstance().getContentFactory().createContentManager(true, _project);
        _contentManager.addContentManagerListener(new ContentManagerAdapter() {
            @Override
            public void contentRemoved(ContentManagerEvent event) {
                JComponent component = event.getContent().getComponent();
                JComponent removedComponent = (component instanceof CommitLogWindowComponent)
                        ? ((CommitLogWindowComponent) component).getComponent()
                        : component;
                //                    if (removedComponent == myErrorsView) {
                //                        myErrorsView.dispose();
                //                        myErrorsView = null;
                //                    } else
                for (Iterator iterator = _commitLogs.iterator(); iterator.hasNext();) {
                    Editor editor = (Editor) iterator.next();
                    if (removedComponent == editor.getComponent()) {
                        EditorFactory.getInstance().releaseEditor(editor);
                        iterator.remove();
                    }
                }
            }
        });
        //      final JComponent component = _contentManager.getComponent();
    }
}

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;//  ww  w  . j  a  v  a2 s  . c  o  m
    }
    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.echologic.xfiles.XFiles.java

License:Open Source License

public void projectOpened() {
    ToolWindowManager manager = ToolWindowManager.getInstance(project);
    ToolWindow window = manager.registerToolWindow(TOOL_WINDOW_ID, new XFilesToolWindow(project),
            ToolWindowAnchor.LEFT);//  ww w.j a  v a2  s . c  om
    window.setTitle(project.getName());
    window.setIcon(XFilesIcons.XFILES_ICON);
}

From source file:com.facebook.buck.intellij.ideabuck.ui.BuckToolWindowFactory.java

License:Apache License

@Override
public void createToolWindowContent(final Project project, ToolWindow toolWindow) {
    toolWindow.setAvailable(true, null);
    toolWindow.setToHideOnEmptyContent(true);
    toolWindow.setIcon(BuckIcons.BUCK_TOOL_WINDOW_ICON);

    RunnerLayoutUi runnerLayoutUi = BuckUIManager.getInstance(project).getLayoutUi(project);

    BuckSettingsProvider.State state = BuckSettingsProvider.getInstance().getState();

    // Debug Console
    if (state.showDebug) {
        Content consoleContent = createConsoleContent(runnerLayoutUi, project);
        consoleContent.setCloseable(false);
        consoleContent.setPinnable(false);
        runnerLayoutUi.addContent(consoleContent, 0, PlaceInGrid.center, false);
    }/*from w w w .j av a 2s.  c o m*/
    // Build Tree Events
    Content treeViewContent = runnerLayoutUi.createContent(BUILD_OUTPUT_PANEL, createBuildInfoPanel(project),
            "Build", null, null);
    treeViewContent.setCloseable(false);
    treeViewContent.setPinnable(false);
    runnerLayoutUi.addContent(treeViewContent, 0, PlaceInGrid.center, false);

    runnerLayoutUi.getOptions().setLeftToolbar(getLeftToolbarActions(project), ActionPlaces.UNKNOWN);

    runnerLayoutUi.updateActionsNow();

    final ContentManager contentManager = toolWindow.getContentManager();
    Content content = contentManager.getFactory().createContent(runnerLayoutUi.getComponent(), "", true);
    contentManager.addContent(content);

    updateBuckToolWindowTitle(project);
}

From source file:com.google.idea.blaze.clwb.problemsview.BlazeProblemsViewConsole.java

License:Open Source License

private void updateIcon() {
    UIUtil.invokeLaterIfNeeded(() -> {
        if (!myProject.isDisposed()) {
            final ToolWindow tw = ToolWindowManager.getInstance(myProject)
                    .getToolWindow(BLAZE_PROBLEMS_TOOLWINDOW_ID);
            if (tw != null) {
                final boolean active = myPanel.getErrorViewStructure().hasMessages(ALL_MESSAGE_KINDS);
                tw.setIcon(active ? myActiveIcon : myPassiveIcon);
                if (active) {
                    tw.show(null);/*from w  ww.  j  a v  a 2s . c  o m*/
                }
            }
        }
    });
}

From source file:com.google.jstestdriver.idea.JSTestDriverToolWindow.java

License:Apache License

private void initToolWindow() {
    ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);

    ToolWindow myToolWindow = toolWindowManager.registerToolWindow(TOOL_WINDOW_ID, false,
            ToolWindowAnchor.BOTTOM);//from  w  w  w.j av a 2s .  com

    ContentFactory contentFactory = SERVICE.getInstance();
    Content content = contentFactory.createContent(new ToolPanel(), "", false);
    myToolWindow.getContentManager().addContent(content);
    myToolWindow.setIcon(PluginResources.getSmallIcon());
}

From source file:com.hp.alm.ali.idea.content.AliContentFactory.java

License:Apache License

private static ToolWindow getOrCreateDetailToolWindow(Project project) {
    ToolWindow toolWindow = getDetailToolWindow(project);
    if (toolWindow == null) {
        ToolWindowManager toolWindowManager = project.getComponent(ToolWindowManager.class);
        toolWindow = toolWindowManager.registerToolWindow(TOOL_WINDOW_DETAIL, true, ToolWindowAnchor.RIGHT);
        toolWindow.setToHideOnEmptyContent(true);
        toolWindow.setIcon(IconLoader.getIcon("/ali_icon_13x13.png"));
        toolWindow.getContentManager().addContentManagerListener(project.getComponent(EntityEditManager.class));
    }/*  w w  w  . ja v  a 2 s .  c  o  m*/
    return toolWindow;
}