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);
});
}
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;
}
}
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);
}
}
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);
}
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();
}
}
});
}
Aggregations