Search in sources :

Example 31 with NotificationListener

use of com.intellij.notification.NotificationListener in project intellij-community by JetBrains.

the class HgVcs method checkVersion.

/**
   * Checks Hg version and updates the myVersion variable.
   * In the case of nullable or unsupported version reports the problem.
   */
public void checkVersion() {
    final String executable = getGlobalSettings().getHgExecutable();
    VcsNotifier vcsNotifier = VcsNotifier.getInstance(myProject);
    final String SETTINGS_LINK = "settings";
    final String UPDATE_LINK = "update";
    NotificationListener linkAdapter = new NotificationListener.Adapter() {

        @Override
        protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
            if (SETTINGS_LINK.equals(e.getDescription())) {
                ShowSettingsUtil.getInstance().showSettingsDialog(myProject, getConfigurable().getDisplayName());
            } else if (UPDATE_LINK.equals(e.getDescription())) {
                BrowserUtil.browse("http://mercurial.selenic.com");
            }
        }
    };
    try {
        myVersion = HgVersion.identifyVersion(executable);
        //if version is not supported, but have valid hg executable
        if (!myVersion.isSupported()) {
            LOG.info("Unsupported Hg version: " + myVersion);
            String message = String.format("The <a href='" + SETTINGS_LINK + "'>configured</a> version of Hg is not supported: %s.<br/> " + "The minimal supported version is %s. Please <a href='" + UPDATE_LINK + "'>update</a>.", myVersion, HgVersion.MIN);
            vcsNotifier.notifyError("Unsupported Hg version", message, linkAdapter);
        } else if (myVersion.hasUnsupportedExtensions()) {
            String unsupportedExtensionsAsString = myVersion.getUnsupportedExtensions().toString();
            LOG.warn("Unsupported Hg extensions: " + unsupportedExtensionsAsString);
            String message = String.format("Some hg extensions %s are not found or not supported by your hg version and will be ignored.\n" + "Please, update your hgrc or Mercurial.ini file", unsupportedExtensionsAsString);
            vcsNotifier.notifyWarning("Unsupported Hg version", message);
        }
    } catch (Exception e) {
        if (getExecutableValidator().checkExecutableAndNotifyIfNeeded()) {
            //sometimes not hg application has version command, but we couldn't parse an answer as valid hg,
            // so parse(output) throw ParseException, but hg and git executable seems to be valid in this case
            final String reason = (e.getCause() != null ? e.getCause() : e).getMessage();
            String message = HgVcsMessages.message("hg4idea.unable.to.run.hg", executable);
            vcsNotifier.notifyError(message, reason + "<br/> Please check your hg executable path in <a href='" + SETTINGS_LINK + "'> settings </a>", linkAdapter);
        }
    }
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) NotNull(org.jetbrains.annotations.NotNull) Notification(com.intellij.notification.Notification) NotificationListener(com.intellij.notification.NotificationListener)

Example 32 with NotificationListener

use of com.intellij.notification.NotificationListener in project intellij-community by JetBrains.

the class StudyProjectComponent method projectOpened.

@Override
public void projectOpened() {
    Course course = StudyTaskManager.getInstance(myProject).getCourse();
    // Check if user has javafx lib in his JDK. Now bundled JDK doesn't have this lib inside.
    if (StudyUtils.hasJavaFx()) {
        Platform.setImplicitExit(false);
    }
    if (course != null && !course.isAdaptive() && !course.isUpToDate()) {
        final Notification notification = new Notification("Update.course", "Course Updates", "Course is ready to <a href=\"update\">update</a>", NotificationType.INFORMATION, new NotificationListener() {

            @Override
            public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
                FileEditorManagerEx.getInstanceEx(myProject).closeAllFiles();
                ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
                    ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
                    return execCancelable(() -> {
                        updateCourse();
                        return true;
                    });
                }, "Updating Course", true, myProject);
                EduUtils.synchronize();
                course.setUpdated();
            }
        });
        notification.notify(myProject);
    }
    StudyUtils.registerStudyToolWindow(course, myProject);
    StartupManager.getInstance(myProject).runWhenProjectIsInitialized(() -> ApplicationManager.getApplication().invokeLater((DumbAwareRunnable) () -> ApplicationManager.getApplication().runWriteAction((DumbAwareRunnable) () -> {
        Course course1 = StudyTaskManager.getInstance(myProject).getCourse();
        if (course1 != null) {
            UISettings instance = UISettings.getInstance();
            instance.setHideToolStripes(false);
            instance.fireUISettingsChanged();
            registerShortcuts();
            EduUsagesCollector.projectTypeOpened(course1.isAdaptive() ? EduNames.ADAPTIVE : EduNames.STUDY);
        }
    })));
    myBusConnection = ApplicationManager.getApplication().getMessageBus().connect();
    myBusConnection.subscribe(EditorColorsManager.TOPIC, new EditorColorsListener() {

        @Override
        public void globalSchemeChange(EditorColorsScheme scheme) {
            final StudyToolWindow toolWindow = StudyUtils.getStudyToolWindow(myProject);
            if (toolWindow != null) {
                toolWindow.updateFonts(myProject);
            }
        }
    });
}
Also used : EditorColorsListener(com.intellij.openapi.editor.colors.EditorColorsListener) HyperlinkEvent(javax.swing.event.HyperlinkEvent) UISettings(com.intellij.ide.ui.UISettings) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) StudyToolWindow(com.jetbrains.edu.learning.ui.StudyToolWindow) StudyProjectGenerator.flushCourse(com.jetbrains.edu.learning.courseGeneration.StudyProjectGenerator.flushCourse) Notification(com.intellij.notification.Notification) DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable) NotificationListener(com.intellij.notification.NotificationListener)

Example 33 with NotificationListener

use of com.intellij.notification.NotificationListener in project intellij-community by JetBrains.

the class PythonSdkType method notifyRemoteSdkSkeletonsFail.

public static void notifyRemoteSdkSkeletonsFail(final InvalidSdkException e, @Nullable final Runnable restartAction) {
    NotificationListener notificationListener;
    String notificationMessage;
    if (e.getCause() instanceof VagrantNotStartedException) {
        notificationListener = new NotificationListener() {

            @Override
            public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
                final PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();
                if (manager != null) {
                    try {
                        VagrantNotStartedException cause = (VagrantNotStartedException) e.getCause();
                        manager.runVagrant(cause.getVagrantFolder(), cause.getMachineName());
                    } catch (ExecutionException e1) {
                        throw new RuntimeException(e1);
                    }
                }
                if (restartAction != null) {
                    restartAction.run();
                }
            }
        };
        notificationMessage = e.getMessage() + "\n<a href=\"#\">Launch vagrant and refresh skeletons</a>";
    } else if (ExceptionUtil.causedBy(e, ExceptionFix.class)) {
        //noinspection ThrowableResultOfMethodCallIgnored
        final ExceptionFix fix = ExceptionUtil.findCause(e, ExceptionFix.class);
        notificationListener = new NotificationListener() {

            @Override
            public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
                fix.apply();
                if (restartAction != null) {
                    restartAction.run();
                }
            }
        };
        notificationMessage = fix.getNotificationMessage(e.getMessage());
    } else {
        notificationListener = null;
        notificationMessage = e.getMessage();
    }
    Notifications.Bus.notify(new Notification(SKELETONS_TOPIC, "Couldn't refresh skeletons for remote interpreter", notificationMessage, NotificationType.WARNING, notificationListener));
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) ExecutionException(com.intellij.execution.ExecutionException) PythonRemoteInterpreterManager(com.jetbrains.python.remote.PythonRemoteInterpreterManager) NotNull(org.jetbrains.annotations.NotNull) Notification(com.intellij.notification.Notification) NotificationListener(com.intellij.notification.NotificationListener)

Example 34 with NotificationListener

use of com.intellij.notification.NotificationListener in project android by JetBrains.

the class InstantRunNotificationTask method showNotification.

public static void showNotification(@NotNull Project project, @Nullable InstantRunContext context, @NotNull String notificationText) {
    if (!InstantRunSettings.isShowNotificationsEnabled()) {
        return;
    }
    @Language("HTML") String message = String.format("<html>%1$s<br>(<a href=\"mute\">Don't show again</a>)</html>", notificationText);
    NotificationListener l = (notification, event) -> {
        if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
            String description = event.getDescription();
            if (description != null && description.startsWith("http")) {
                BrowserUtil.browse(description, project);
            } else if ("mute".equals(description)) {
                InstantRunSettings.setShowStatusNotifications(false);
            } else if ("configure".equals(description)) {
                InstantRunConfigurable configurable = new InstantRunConfigurable();
                ShowSettingsUtil.getInstance().editConfigurable(project, configurable);
            } else if ("restart".equals(description)) {
                assert context != null : "Notifications that include a restart activity option need to have a valid instant run context";
                RestartActivityAction.restartActivity(project, context);
            } else if ("learnmore".equals(description)) {
                BrowserUtil.browse("http://developer.android.com/r/studio-ui/instant-run.html", project);
            } else if ("updategradle".equals(description)) {
                InstantRunConfigurable.updateProjectToInstantRunTools(project, null);
            }
        }
    };
    InstantRunManager.NOTIFICATION_GROUP.createNotification("", message, NotificationType.INFORMATION, l).notify(project);
}
Also used : AndroidBundle(org.jetbrains.android.util.AndroidBundle) LaunchStatus(com.android.tools.idea.run.util.LaunchStatus) ShowSettingsUtil(com.intellij.openapi.options.ShowSettingsUtil) HyperlinkEvent(javax.swing.event.HyperlinkEvent) IDevice(com.android.ddmlib.IDevice) Language(org.intellij.lang.annotations.Language) HashSet(com.intellij.util.containers.HashSet) Set(java.util.Set) BrowserUtil(com.intellij.ide.BrowserUtil) com.android.tools.idea.fd(com.android.tools.idea.fd) ConsolePrinter(com.android.tools.idea.run.ConsolePrinter) NotificationListener(com.intellij.notification.NotificationListener) NotificationType(com.intellij.notification.NotificationType) Nullable(org.jetbrains.annotations.Nullable) GuardedBy(com.android.annotations.concurrency.GuardedBy) RestartActivityAction(com.android.tools.idea.fd.actions.RestartActivityAction) Project(com.intellij.openapi.project.Project) NotNull(org.jetbrains.annotations.NotNull) Language(org.intellij.lang.annotations.Language) NotificationListener(com.intellij.notification.NotificationListener)

Example 35 with NotificationListener

use of com.intellij.notification.NotificationListener in project intellij-plugins by JetBrains.

the class ValidateFlashConfigurationsPrecompileTask method suggestParallelCompilationIfNeeded.

private void suggestParallelCompilationIfNeeded(final Project project, final Collection<Pair<Module, FlexBuildConfiguration>> modulesAndBCsToCompile) {
    if (myParallelCompilationSuggested)
        return;
    if (CompilerWorkspaceConfiguration.getInstance(project).PARALLEL_COMPILATION)
        return;
    if (modulesAndBCsToCompile.size() < 2)
        return;
    if (!independentBCsExist(modulesAndBCsToCompile))
        return;
    final NotificationListener listener = new NotificationListener() {

        public void hyperlinkUpdate(@NotNull final Notification notification, @NotNull final HyperlinkEvent event) {
            notification.expire();
            if ("enable".equals(event.getDescription())) {
                CompilerWorkspaceConfiguration.getInstance(project).PARALLEL_COMPILATION = true;
                final NotificationListener listener1 = new NotificationListener() {

                    public void hyperlinkUpdate(@NotNull final Notification notification, @NotNull final HyperlinkEvent event) {
                        notification.expire();
                        ShowSettingsUtil.getInstance().showSettingsDialog(project, CompilerBundle.message("compiler.configurable.display.name"));
                    }
                };
                new Notification(FLASH_COMPILER_GROUP_ID, FlexBundle.message("parallel.compilation.enabled"), FlexBundle.message("see.settings.compiler"), NotificationType.INFORMATION, listener1).notify(project);
            } else if ("open".equals(event.getDescription())) {
                ShowSettingsUtil.getInstance().showSettingsDialog(project, CompilerBundle.message("compiler.configurable.display.name"));
            }
        }
    };
    new Notification(FLASH_COMPILER_GROUP_ID, FlexBundle.message("parallel.compilation.hint.title"), FlexBundle.message("parallel.compilation.hint"), NotificationType.INFORMATION, listener).notify(project);
    myParallelCompilationSuggested = true;
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) NotNull(org.jetbrains.annotations.NotNull) Notification(com.intellij.notification.Notification) NotificationListener(com.intellij.notification.NotificationListener)

Aggregations

NotificationListener (com.intellij.notification.NotificationListener)36 HyperlinkEvent (javax.swing.event.HyperlinkEvent)28 Notification (com.intellij.notification.Notification)26 NotNull (org.jetbrains.annotations.NotNull)23 Project (com.intellij.openapi.project.Project)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 GuardedBy (com.android.annotations.concurrency.GuardedBy)2 IDevice (com.android.ddmlib.IDevice)2 com.android.tools.idea.fd (com.android.tools.idea.fd)2 RestartActivityAction (com.android.tools.idea.fd.actions.RestartActivityAction)2 ConsolePrinter (com.android.tools.idea.run.ConsolePrinter)2 LaunchStatus (com.android.tools.idea.run.util.LaunchStatus)2 BrowserUtil (com.intellij.ide.BrowserUtil)2 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)2 NotificationType (com.intellij.notification.NotificationType)2 ShowSettingsUtil (com.intellij.openapi.options.ShowSettingsUtil)2 MultiMap (com.intellij.util.containers.MultiMap)2 File (java.io.File)2 Set (java.util.Set)2 Nullable (org.jetbrains.annotations.Nullable)2