Search in sources :

Example 11 with ProjectManagerAdapter

use of com.intellij.openapi.project.ProjectManagerAdapter in project intellij by bazelbuild.

the class JUnitPluginDependencyWarning method notifyJUnitNotEnabled.

/**
 * Pop up a notification asking user to enable the JUnit plugin, and also add an error item to the
 * event log.
 */
private static void notifyJUnitNotEnabled() {
    String buildSystem = Blaze.defaultBuildSystemName();
    String message = String.format("<html>The JUnit plugin is disabled, but it's required for the %s plugin to function." + "<br>Please <a href=\"fix\">enable the JUnit plugin</a> and restart the IDE", buildSystem);
    NotificationListener listener = new NotificationListener.Adapter() {

        @Override
        protected void hyperlinkActivated(Notification notification, HyperlinkEvent e) {
            if ("fix".equals(e.getDescription())) {
                PluginUtils.installOrEnablePlugin(JUNIT_PLUGIN_ID);
            }
        }
    };
    Notification notification = new Notification(buildSystem + " Plugin Error", buildSystem + " plugin dependencies are missing", message, NotificationType.ERROR, listener);
    notification.setImportant(true);
    Application app = ApplicationManager.getApplication();
    MessageBusConnection connection = app.getMessageBus().connect(app);
    connection.subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() {

        @Override
        public void appStarting(@Nullable Project projectFromCommandLine) {
            // Adds an error item to the 'Event Log' tab.
            // Easy to ignore, but remains in event log until manually cleared.
            Transactions.submitTransactionAndWait(() -> Notifications.Bus.notify(notification));
        }

        @Override
        public void appFrameCreated(String[] commandLineArgs, Ref<Boolean> willOpenProject) {
            // Popup dialog in welcome screen.
            app.invokeLater(() -> showPopupNotification(message));
        }
    });
    if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
        connection.subscribe(ProjectManager.TOPIC, new ProjectManagerAdapter() {

            @Override
            public void projectOpened(Project project) {
                // Popup dialog on project open, for users bypassing the welcome screen.
                if (Blaze.isBlazeProject(project)) {
                    app.invokeLater(() -> showPopupNotification(message));
                }
            }
        });
    }
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkAdapter(com.intellij.ui.HyperlinkAdapter) ProjectManagerAdapter(com.intellij.openapi.project.ProjectManagerAdapter) Notification(com.intellij.notification.Notification) Project(com.intellij.openapi.project.Project) ProjectManagerAdapter(com.intellij.openapi.project.ProjectManagerAdapter) AppLifecycleListener(com.intellij.ide.AppLifecycleListener) Application(com.intellij.openapi.application.Application) NotificationListener(com.intellij.notification.NotificationListener)

Aggregations

Project (com.intellij.openapi.project.Project)11 ProjectManagerAdapter (com.intellij.openapi.project.ProjectManagerAdapter)11 ProjectManager (com.intellij.openapi.project.ProjectManager)3 AppLifecycleListener (com.intellij.ide.AppLifecycleListener)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Notification (com.intellij.notification.Notification)1 NotificationListener (com.intellij.notification.NotificationListener)1 Application (com.intellij.openapi.application.Application)1 EditorMouseEvent (com.intellij.openapi.editor.event.EditorMouseEvent)1 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)1 FileEditorManagerListener (com.intellij.openapi.fileEditor.FileEditorManagerListener)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 Pair (com.intellij.openapi.util.Pair)1 HyperlinkAdapter (com.intellij.ui.HyperlinkAdapter)1 EditorPopupHandler (com.intellij.util.EditorPopupHandler)1 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)1 MouseEvent (java.awt.event.MouseEvent)1 IOException (java.io.IOException)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1