Example usage for com.intellij.openapi.wm StatusBar getWidget

List of usage examples for com.intellij.openapi.wm StatusBar getWidget

Introduction

In this page you can find the example usage for com.intellij.openapi.wm StatusBar getWidget.

Prototype

@Nullable
    StatusBarWidget getWidget(@NonNls String id);

Source Link

Usage

From source file:com.microsoft.alm.plugin.idea.common.statusBar.StatusBarManager.java

License:Open Source License

private static void updateWidgets(final StatusBar statusBar, final Project project, final boolean allowPrompt) {
    // Update the build widget
    BuildWidget buildWidget = (BuildWidget) statusBar.getWidget(BuildWidget.getID());
    if (buildWidget == null) {
        buildWidget = new BuildWidget();
        statusBar.addWidget(buildWidget, project);
    }//from  w ww  . j  ava2s. co  m
    // Attempt to get the current repository context (if none, then the status stays as it was)
    final RepositoryContext repositoryContext = VcsHelper.getRepositoryContext(project);
    if (repositoryContext != null) {
        final BuildWidget widget = buildWidget;

        // Create the operation and start the background work to get the latest build information
        final BuildStatusLookupOperation op = OperationFactory
                .createBuildStatusLookupOperation(repositoryContext, allowPrompt);
        op.addListener(new Operation.Listener() {
            @Override
            public void notifyLookupStarted() {
                /* do nothing */ }

            @Override
            public void notifyLookupCompleted() {
                /* do nothing */ }

            @Override
            public void notifyLookupResults(final Operation.Results results) {
                updateBuildWidget(project, statusBar, widget,
                        (BuildStatusLookupOperation.BuildStatusResults) results);
            }
        });
        op.doWorkAsync(null);

    } else {
        // The repository hasn't been opened yet, we should get an event when it is opened
    }
}

From source file:com.microsoft.alm.plugin.idea.common.statusBar.StatusBarManager.java

License:Open Source License

private static void removeWidgets(final Project project) {
    final StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
    if (statusBar != null) {
        // Remove build widget
        if (statusBar.getWidget(BuildWidget.getID()) != null) {
            statusBar.removeWidget(BuildWidget.getID());
        }/*  w  w w  .ja  v  a  2s. c  o m*/
    }
}

From source file:com.microsoft.alm.plugin.idea.statusBar.StatusBarManager.java

License:Open Source License

private static void updateWidgets(final StatusBar statusBar, final Project project, final boolean allowPrompt) {
    // Update the build widget
    BuildWidget buildWidget = (BuildWidget) statusBar.getWidget(BuildWidget.getID());
    if (buildWidget == null) {
        buildWidget = new BuildWidget();
        statusBar.addWidget(buildWidget, project);
    }//from w  w  w .j a v  a 2 s . co  m
    // Attempt to get the current repo and branch (if none, then the status stays as it was)
    final GitRepository repository = GitBranchUtil.getCurrentRepository(project);
    if (repository != null) {
        final String repoUrl = TfGitHelper.getTfGitRemoteUrl(repository);
        if (!StringUtil.isNullOrEmpty(repoUrl)) {
            // It's a tf git url so continue
            final BuildWidget widget = buildWidget;
            // TODO: Fix this HACK. There doesn't seem to be a clear way to get the full name of the current branch
            final String branch = "refs/heads/" + GitBranchUtil.getDisplayableBranchText(repository);

            // Create the operation and start the background work to get the latest build information
            final BuildStatusLookupOperation op = new BuildStatusLookupOperation(repoUrl, branch, allowPrompt);
            op.addListener(new Operation.Listener() {
                @Override
                public void notifyLookupStarted() {
                    /* do nothing */ }

                @Override
                public void notifyLookupCompleted() {
                    /* do nothing */ }

                @Override
                public void notifyLookupResults(final Operation.Results results) {
                    updateBuildWidget(project, statusBar, widget,
                            (BuildStatusLookupOperation.BuildStatusResults) results);
                }
            });
            op.doWorkAsync(null);
        }
    } else {
        // The repository hasn't been opened yet, so try again quickly
        timer.setInitialDelay(MIN_TIMER_DELAY);
        timer.restart();
    }
}

From source file:limitedwip.IdeNotifications.java

License:Apache License

private void updateStatusBar() {
    StatusBar statusBar = statusBarFor(project);
    if (statusBar == null)
        return;/*from w  w  w . jav a2  s.c om*/

    boolean hasAutoRevertWidget = statusBar.getWidget(autoRevertWidget.ID()) != null;
    if (hasAutoRevertWidget && settings.autoRevertEnabled) {
        statusBar.updateWidget(autoRevertWidget.ID());

    } else if (hasAutoRevertWidget) {
        statusBar.removeWidget(autoRevertWidget.ID());

    } else if (settings.autoRevertEnabled) {
        autoRevertWidget.showStoppedText();
        statusBar.addWidget(autoRevertWidget, "before Position");
        statusBar.updateWidget(autoRevertWidget.ID());
    }

    boolean hasWatchdogWidget = statusBar.getWidget(watchdogWidget.ID()) != null;
    boolean shouldShowWatchdog = settings.watchdogEnabled && settings.showRemainingChangesInToolbar;
    if (hasWatchdogWidget && shouldShowWatchdog) {
        statusBar.updateWidget(watchdogWidget.ID());

    } else if (hasWatchdogWidget) {
        statusBar.removeWidget(watchdogWidget.ID());

    } else if (shouldShowWatchdog) {
        watchdogWidget.showInitialText(settings.maxLinesInChange);
        statusBar.addWidget(watchdogWidget, "before Position");
        statusBar.updateWidget(watchdogWidget.ID());
    }
}

From source file:org.app4j.tool.pomodoro.PomodoroComponent.java

License:Apache License

@Override
public void initComponent() {
    final Settings settings = ServiceManager.getService(Settings.class);
    final LogStorage storage = ServiceManager.getService(LogStorage.class);

    Logger logger = new Logger(storage);
    status = new PomodoroStatus(settings);
    report = new PomodoroReport(logger);

    pomodoro = new Pomodoro(settings, logger, status, report);
    pomodoro.activate();//  w  ww.jav  a 2s  . c  o m

    messageBusConnection = ApplicationManagerEx.getApplicationEx().getMessageBus().connect();
    messageBusConnection.subscribe(ApplicationActivationListener.TOPIC, new ApplicationActivationListener() {
        @Override
        public void applicationActivated(IdeFrame ideFrame) {
        }

        @Override
        public void applicationDeactivated(IdeFrame ideFrame) {
        }
    });

    ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerAdapter() {
        @Override
        public void projectOpened(Project project) {
            StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
            if (statusBar != null && statusBar.getWidget(PomodoroStatus.ID) == null) {
                statusBar.addWidget(status);
            }

            ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);

            if (toolWindowManager.getToolWindow(PomodoroReport.ID) == null) {
                ToolWindow toolWindow = toolWindowManager.registerToolWindow(PomodoroReport.ID, false,
                        ToolWindowAnchor.BOTTOM);
                toolWindow.setIcon(Pomodoro.ICON_RUNNING);
                ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
                Content content = contentFactory.createContent(report.xChartPanel, "", false);
                toolWindow.getContentManager().addContent(content);
            }

        }

        @Override
        public void projectClosed(Project project) {
            StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
            if (statusBar != null && statusBar.getWidget(PomodoroStatus.ID) != null) {
                statusBar.removeWidget(PomodoroStatus.ID);
            }

            ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
            if (toolWindowManager.getToolWindow(PomodoroReport.ID) != null) {
                toolWindowManager.unregisterToolWindow(PomodoroReport.ID);
            }
        }
    });

    controlThread = new TickThread(pomodoro);
    controlThread.start();
}

From source file:org.twodividedbyzero.idea.findbugs.gui.toolwindow.view.ToolWindowPanel.java

License:Open Source License

@Override
public void analysisFinished(@NotNull final BugCollection bugCollection,
        @Nullable final FindBugsProject findBugsProject, @Nullable final Throwable error) {
    _bugTreePanel.setBugCollection(bugCollection);
    final ProjectStats stats = bugCollection.getProjectStats();
    _bugTreePanel.updateRootNode(stats);
    _bugTreePanel.getBugTree().validate();
    final int numAnalysedClasses = stats != null ? stats.getNumClasses() : 0;

    final StringBuilder message = new StringBuilder().append("Found ")
            .append(_bugTreePanel.getGroupModel().getBugCount()).append(" bugs in ").append(numAnalysedClasses)
            .append(numAnalysedClasses > 1 ? " classes" : " class");

    _bugsProject = findBugsProject;/*from w  w w  .j  a  v a 2s. c  o m*/

    final NotificationType notificationType;
    if (numAnalysedClasses == 0) {
        notificationType = NotificationType.WARNING;
        message.append("&nbsp; (no class files found <a href='").append(A_HREF_MORE_ANCHOR)
                .append("'>more...</a>)<br/>");
    } else {
        notificationType = NotificationType.INFORMATION;
        message.append("&nbsp;<a href='").append(A_HREF_MORE_ANCHOR).append("'>more...</a><br/>");
    }
    message.append("<font size='10px'>using ").append(VersionManager.getFullVersion())
            .append(" with Findbugs version ").append(FindBugsUtil.getFindBugsFullVersion())
            .append("</font><br/><br/>");

    if (error != null) {
        final boolean findBugsError = FindBugsUtil.isFindBugsError(error);
        final String impl;
        if (findBugsError) {
            impl = "FindBugs";
        } else {
            impl = "FindBugs-IDEA Plugin";
        }
        String errorText = "An " + impl + " error occurred.";

        final StatusBar statusBar = WindowManager.getInstance().getIdeFrame(_project).getStatusBar();
        final StatusBarWidget widget = statusBar.getWidget(IdeMessagePanel.FATAL_ERROR);
        IdeMessagePanel ideMessagePanel = null; // openFatals like ErrorNotifier
        if (widget instanceof IdeMessagePanel) {
            ideMessagePanel = (IdeMessagePanel) widget;
            errorText = "<a href='" + A_HREF_ERROR_ANCHOR + "'>" + errorText + "</a>";
        }

        message.append(String.format("%s The results of the analysis might be incomplete.", errorText));
        LOGGER.error(error);
        // use balloon because error should never disabled
        BalloonTipFactory.showToolWindowErrorNotifier(_project, message.toString(),
                new BalloonErrorListenerImpl(ToolWindowPanel.this, _bugsProject, ideMessagePanel));
    } else {
        message.append("<a href='").append(A_HREF_DISABLE_ANCHOR).append("'>Disable notification")
                .append("</a>");
        FindBugsPluginImpl.NOTIFICATION_GROUP_ANALYSIS_FINISHED
                .createNotification(VersionManager.getName() + ": Analysis Finished", message.toString(),
                        notificationType, new NotificationListenerImpl(ToolWindowPanel.this, _bugsProject))
                .setImportant(false).notify(_project);
    }

    EditorFactory.getInstance().refreshAllEditors();
    DaemonCodeAnalyzer.getInstance(_project).restart();
}