Search in sources :

Example 11 with NotificationListener

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

the class ExecutionUtil method handleExecutionError.

public static void handleExecutionError(@NotNull final Project project, @NotNull final String toolWindowId, @NotNull String taskName, @NotNull ExecutionException e) {
    if (e instanceof RunCanceledByUserException) {
        return;
    }
    LOG.debug(e);
    String description = e.getMessage();
    if (StringUtil.isEmptyOrSpaces(description)) {
        LOG.warn("Execution error without description", e);
        description = "Unknown error";
    }
    HyperlinkListener listener = null;
    if ((description.contains("87") || description.contains("111") || description.contains("206")) && e instanceof ProcessNotCreatedException && !PropertiesComponent.getInstance(project).isTrueValue("dynamic.classpath")) {
        final String commandLineString = ((ProcessNotCreatedException) e).getCommandLine().getCommandLineString();
        if (commandLineString.length() > 1024 * 32) {
            description = "Command line is too long. In order to reduce its length classpath file can be used.<br>" + "Would you like to enable classpath file mode for all run configurations of your project?<br>" + "<a href=\"\">Enable</a>";
            listener = new HyperlinkListener() {

                @Override
                public void hyperlinkUpdate(HyperlinkEvent event) {
                    PropertiesComponent.getInstance(project).setValue("dynamic.classpath", "true");
                }
            };
        }
    }
    final String title = ExecutionBundle.message("error.running.configuration.message", taskName);
    final String fullMessage = title + ":<br>" + description;
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        LOG.error(fullMessage, e);
    }
    if (listener == null) {
        listener = ExceptionUtil.findCause(e, HyperlinkListener.class);
    }
    final HyperlinkListener finalListener = listener;
    final String finalDescription = description;
    UIUtil.invokeLaterIfNeeded(() -> {
        if (project.isDisposed()) {
            return;
        }
        ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
        if (toolWindowManager.canShowNotification(toolWindowId)) {
            //noinspection SSBasedInspection
            toolWindowManager.notifyByBalloon(toolWindowId, MessageType.ERROR, fullMessage, null, finalListener);
        } else {
            Messages.showErrorDialog(project, UIUtil.toHtml(fullMessage), "");
        }
        NotificationListener notificationListener = finalListener == null ? null : (notification, event) -> {
            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                finalListener.hyperlinkUpdate(event);
            }
        };
        ourNotificationGroup.createNotification(title, finalDescription, NotificationType.ERROR, notificationListener).notify(project);
    });
}
Also used : ProcessNotCreatedException(com.intellij.execution.process.ProcessNotCreatedException) HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener) ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) NotificationListener(com.intellij.notification.NotificationListener)

Example 12 with NotificationListener

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

the class PluginManager method reportPluginError.

public static void reportPluginError() {
    if (myPluginError != null) {
        String title = IdeBundle.message("title.plugin.error");
        Notifications.Bus.notify(new Notification(title, title, myPluginError, NotificationType.ERROR, new NotificationListener() {

            @SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod")
            @Override
            public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
                notification.expire();
                String description = event.getDescription();
                if (EDIT.equals(description)) {
                    PluginManagerConfigurable configurable = new PluginManagerConfigurable(PluginManagerUISettings.getInstance());
                    IdeFrame ideFrame = WindowManagerEx.getInstanceEx().findFrameFor(null);
                    ShowSettingsUtil.getInstance().editConfigurable((JFrame) ideFrame, configurable);
                    return;
                }
                List<String> disabledPlugins = getDisabledPlugins();
                if (myPlugins2Disable != null && DISABLE.equals(description)) {
                    for (String pluginId : myPlugins2Disable) {
                        if (!disabledPlugins.contains(pluginId)) {
                            disabledPlugins.add(pluginId);
                        }
                    }
                } else if (myPlugins2Enable != null && ENABLE.equals(description)) {
                    disabledPlugins.removeAll(myPlugins2Enable);
                    PluginManagerMain.notifyPluginsUpdated(null);
                }
                try {
                    saveDisabledPlugins(disabledPlugins, false);
                } catch (IOException ignore) {
                }
                myPlugins2Enable = null;
                myPlugins2Disable = null;
            }
        }));
        myPluginError = null;
    }
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull) IdeFrame(com.intellij.openapi.wm.IdeFrame) Notification(com.intellij.notification.Notification) NotificationListener(com.intellij.notification.NotificationListener)

Example 13 with NotificationListener

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

the class VcsRootProblemNotifier method rescanAndNotifyIfNeeded.

public void rescanAndNotifyIfNeeded() {
    Collection<VcsRootError> errors = scan();
    if (errors.isEmpty()) {
        synchronized (NOTIFICATION_LOCK) {
            expireNotification();
        }
        return;
    }
    LOG.debug("Following errors detected: " + errors);
    Collection<VcsRootError> importantUnregisteredRoots = getImportantUnregisteredMappings(errors);
    Collection<VcsRootError> invalidRoots = getInvalidRoots(errors);
    if (importantUnregisteredRoots.size() == 1) {
        VcsRootError singleUnregRoot = notNull(getFirstItem(importantUnregisteredRoots));
        String mappingPath = singleUnregRoot.getMapping();
        VirtualFile projectDir = guessProjectDir(myProject);
        Collection<VcsRootError> allUnregisteredRoots = filter(errors, it -> it.getType() == UNREGISTERED_ROOT);
        if (!myVcsManager.hasAnyMappings() && allUnregisteredRoots.size() == 1 && !myReportedUnregisteredRoots.contains(mappingPath) && FileUtil.isAncestor(projectDir.getPath(), mappingPath, false) && Registry.is("vcs.auto.add.single.root")) {
            VcsDirectoryMapping mapping = new VcsDirectoryMapping(mappingPath, singleUnregRoot.getVcsKey().getName());
            myVcsManager.setDirectoryMappings(singletonList(mapping));
            LOG.info("Added " + mapping.getVcs() + " root " + mapping + " as the only auto-detected root.");
            return;
        }
    }
    List<String> unregRootPaths = ContainerUtil.map(importantUnregisteredRoots, VcsRootError::getMapping);
    if (invalidRoots.isEmpty() && (importantUnregisteredRoots.isEmpty() || myReportedUnregisteredRoots.containsAll(unregRootPaths))) {
        return;
    }
    myReportedUnregisteredRoots.addAll(unregRootPaths);
    String title = makeTitle(importantUnregisteredRoots, invalidRoots);
    String description = makeDescription(importantUnregisteredRoots, invalidRoots);
    synchronized (NOTIFICATION_LOCK) {
        expireNotification();
        NotificationListener listener = new MyNotificationListener(myProject, mySettings, myVcsManager, importantUnregisteredRoots);
        VcsNotifier notifier = VcsNotifier.getInstance(myProject);
        myNotification = invalidRoots.isEmpty() ? notifier.notifyMinorInfo(title, description, listener) : notifier.notifyError(title, description, listener);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NotificationListener(com.intellij.notification.NotificationListener)

Example 14 with NotificationListener

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

the class VcsBalloonProblemNotifier method run.

public void run() {
    final Notification notification;
    if (myNotificationListener != null && myNotificationListener.length > 0) {
        final StringBuilder sb = new StringBuilder(myMessage);
        for (NamedRunnable runnable : myNotificationListener) {
            final String name = runnable.toString();
            sb.append("<br/><a href=\"").append(name).append("\">").append(name).append("</a>");
        }
        NotificationListener listener = (currentNotification, event) -> {
            if (HyperlinkEvent.EventType.ACTIVATED.equals(event.getEventType())) {
                if (myNotificationListener.length == 1) {
                    myNotificationListener[0].run();
                } else {
                    final String description = event.getDescription();
                    if (description != null) {
                        for (NamedRunnable runnable : myNotificationListener) {
                            if (description.equals(runnable.toString())) {
                                runnable.run();
                                break;
                            }
                        }
                    }
                }
                currentNotification.expire();
            }
        };
        notification = NOTIFICATION_GROUP.createNotification("", sb.toString(), myMessageType.toNotificationType(), listener);
    } else {
        notification = NOTIFICATION_GROUP.createNotification(myMessage, myMessageType);
    }
    notification.notify(myProject.isDefault() ? null : myProject);
}
Also used : Notification(com.intellij.notification.Notification) Nullable(org.jetbrains.annotations.Nullable) Application(com.intellij.openapi.application.Application) MessageType(com.intellij.openapi.ui.MessageType) HyperlinkEvent(javax.swing.event.HyperlinkEvent) NotificationGroup(com.intellij.notification.NotificationGroup) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Project(com.intellij.openapi.project.Project) ChangesViewContentManager(com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager) NamedRunnable(com.intellij.openapi.util.NamedRunnable) NotNull(org.jetbrains.annotations.NotNull) NotificationListener(com.intellij.notification.NotificationListener) NamedRunnable(com.intellij.openapi.util.NamedRunnable) Notification(com.intellij.notification.Notification) NotificationListener(com.intellij.notification.NotificationListener)

Example 15 with NotificationListener

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

the class GitBranchUiHandlerImpl method showUnmergedFilesNotification.

@Override
public void showUnmergedFilesNotification(@NotNull final String operationName, @NotNull final Collection<GitRepository> repositories) {
    String title = unmergedFilesErrorTitle(operationName);
    String description = unmergedFilesErrorNotificationDescription(operationName);
    VcsNotifier.getInstance(myProject).notifyError(title, description, new NotificationListener() {

        @Override
        public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED && event.getDescription().equals("resolve")) {
                GitConflictResolver.Params params = new GitConflictResolver.Params().setMergeDescription(String.format("The following files have unresolved conflicts. You need to resolve them before %s.", operationName)).setErrorNotificationTitle("Unresolved files remain.");
                new GitConflictResolver(myProject, myGit, GitUtil.getRootsFromRepositories(repositories), params).merge();
            }
        }
    });
}
Also used : GitConflictResolver(git4idea.merge.GitConflictResolver) HyperlinkEvent(javax.swing.event.HyperlinkEvent) 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