From c58e19e9495d66fe7f5da50ff364e6a4f95cc753 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 11 Apr 2016 10:12:10 +0200 Subject: [PATCH] remove invokeLater around notifications, as they have no threading requirements --- .../actions/InterruptThreadAction.java | 12 +----- .../ide/actions/CreateDesktopEntryAction.java | 21 +++------- .../actions/CreateLauncherScriptAction.java | 11 ++---- .../impl/UpdateCheckerComponent.java | 35 +++++++---------- .../importWizard/EclipseImportBuilder.java | 38 ++++++++----------- .../service/project/GradleNotification.java | 8 +--- .../maven/project/MavenProjectsManager.java | 7 +--- .../utils/MavenAttachSourcesProvider.java | 16 +++----- 8 files changed, 47 insertions(+), 101 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/InterruptThreadAction.java b/java/debugger/impl/src/com/intellij/debugger/actions/InterruptThreadAction.java index 2d5c2de1896d..ed3775891f06 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/InterruptThreadAction.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/InterruptThreadAction.java @@ -29,7 +29,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.MessageType; import com.intellij.xdebugger.impl.XDebugSessionImpl; -import javax.swing.*; import java.util.ArrayList; import java.util.List; @@ -72,15 +71,8 @@ public class InterruptThreadAction extends DebuggerAction{ } if (unsupported) { final Project project = debugProcess.getProject(); - //noinspection SSBasedInspection - SwingUtilities.invokeLater(new Runnable() { - public void run() { - if (!project.isDisposed()) { - XDebugSessionImpl.NOTIFICATION_GROUP - .createNotification("Thread operation 'interrupt' is not supported by VM", MessageType.INFO).notify(project); - } - } - }); + XDebugSessionImpl.NOTIFICATION_GROUP + .createNotification("Thread operation 'interrupt' is not supported by VM", MessageType.INFO).notify(project); } } }); diff --git a/platform/platform-impl/src/com/intellij/ide/actions/CreateDesktopEntryAction.java b/platform/platform-impl/src/com/intellij/ide/actions/CreateDesktopEntryAction.java index 44e8ba93d74d..ef9068dcbad7 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/CreateDesktopEntryAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/CreateDesktopEntryAction.java @@ -82,13 +82,9 @@ public class CreateDesktopEntryAction extends DumbAwareAction { createDesktopEntry(globalEntry); final String message = ApplicationBundle.message("desktop.entry.success", ApplicationNamesInfo.getInstance().getProductName()); - ApplicationManager.getApplication().invokeLater(new Runnable() { - public void run() { - Notifications.Bus.notify( - new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "Desktop Entry Created", message, NotificationType.INFORMATION), - getProject()); - } - }, ModalityState.NON_MODAL); + Notifications.Bus.notify( + new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "Desktop Entry Created", message, NotificationType.INFORMATION), + getProject()); } catch (Exception e) { reportFailure(e, getProject()); @@ -116,14 +112,9 @@ public class CreateDesktopEntryAction extends DumbAwareAction { public static void reportFailure(@NotNull Exception e, @Nullable final Project project) { LOG.warn(e); final String message = ExceptionUtil.getNonEmptyMessage(e, "Internal error"); - ApplicationManager.getApplication().invokeLater(new Runnable() { - @Override - public void run() { - Notifications.Bus.notify( - new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "Desktop Entry Creation Failed", message, NotificationType.ERROR), - project); - } - }, ModalityState.NON_MODAL); + Notifications.Bus.notify( + new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "Desktop Entry Creation Failed", message, NotificationType.ERROR), + project); } private static void check() throws ExecutionException, InterruptedException { diff --git a/platform/platform-impl/src/com/intellij/ide/actions/CreateLauncherScriptAction.java b/platform/platform-impl/src/com/intellij/ide/actions/CreateLauncherScriptAction.java index e19b064e6f30..7b8468603155 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/CreateLauncherScriptAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/CreateLauncherScriptAction.java @@ -143,14 +143,9 @@ public class CreateLauncherScriptAction extends DumbAwareAction { public static void reportFailure(@NotNull Exception e, @Nullable final Project project) { LOG.warn(e); final String message = ExceptionUtil.getNonEmptyMessage(e, "Internal error"); - ApplicationManager.getApplication().invokeLater(new Runnable() { - @Override - public void run() { - Notifications.Bus.notify( - new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "Launcher Script Creation Failed", message, NotificationType.ERROR), - project); - } - }, ModalityState.NON_MODAL); + Notifications.Bus.notify( + new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "Launcher Script Creation Failed", message, NotificationType.ERROR), + project); } private static File createLauncherScriptFile() throws IOException, ExecutionException { diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateCheckerComponent.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateCheckerComponent.java index 21d9a28213c9..0923877efee8 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateCheckerComponent.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateCheckerComponent.java @@ -80,7 +80,7 @@ public class UpdateCheckerComponent implements ApplicationComponent { if (!ConfigImportHelper.isFirstSession()) { String title = IdeBundle.message("update.notifications.title"); String message = IdeBundle.message("update.channel.enforced", ChannelStatus.EAP); - notify(app, UpdateChecker.NOTIFICATIONS.createNotification(title, message, NotificationType.INFORMATION, null)); + UpdateChecker.NOTIFICATIONS.createNotification(title, message, NotificationType.INFORMATION, null).notify(null); } } @@ -97,18 +97,18 @@ public class UpdateCheckerComponent implements ApplicationComponent { boolean tooOld = !SystemInfo.isJavaVersionAtLeast("1.7"); String title = IdeBundle.message("update.notifications.title"); String message = IdeBundle.message(tooOld ? "update.sni.not.available.message" : "update.sni.disabled.message"); - notify(app, UpdateChecker.NOTIFICATIONS.createNotification(title, message, NotificationType.WARNING, new NotificationListener.Adapter() { - @Override - protected void hyperlinkActivated(@NotNull Notification notification1, @NotNull HyperlinkEvent e) { - notification1.expire(); - app.invokeLater(new Runnable() { - @Override - public void run() { - ShowSettingsUtil.getInstance().showSettingsDialog(null, UpdateSettingsConfigurable.class); - } - }, ModalityState.NON_MODAL); - } - })); + UpdateChecker.NOTIFICATIONS.createNotification(title, message, NotificationType.WARNING, new NotificationListener.Adapter() { + @Override + protected void hyperlinkActivated(@NotNull Notification notification1, @NotNull HyperlinkEvent e) { + notification1.expire(); + app.invokeLater(new Runnable() { + @Override + public void run() { + ShowSettingsUtil.getInstance().showSettingsDialog(null, UpdateSettingsConfigurable.class); + } + }, ModalityState.NON_MODAL); + } + }).notify(null); } } @@ -138,15 +138,6 @@ public class UpdateCheckerComponent implements ApplicationComponent { myCheckForUpdatesAlarm.addRequest(myCheckRunnable, interval); } - private static void notify(Application app, final Notification notification) { - app.invokeLater(new Runnable() { - @Override - public void run() { - notification.notify(null); - } - }, ModalityState.NON_MODAL); - } - @Override public void initComponent() { PluginsAdvertiser.ensureDeleted(); diff --git a/plugins/eclipse/src/org/jetbrains/idea/eclipse/importWizard/EclipseImportBuilder.java b/plugins/eclipse/src/org/jetbrains/idea/eclipse/importWizard/EclipseImportBuilder.java index 95ae2cde1bb0..86a9237efd37 100644 --- a/plugins/eclipse/src/org/jetbrains/idea/eclipse/importWizard/EclipseImportBuilder.java +++ b/plugins/eclipse/src/org/jetbrains/idea/eclipse/importWizard/EclipseImportBuilder.java @@ -20,7 +20,6 @@ import com.intellij.notification.NotificationType; import com.intellij.notification.Notifications; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ApplicationNamesInfo; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileChooser.FileChooser; import com.intellij.openapi.fileChooser.FileChooserDescriptor; @@ -209,28 +208,23 @@ public class EclipseImportBuilder extends ProjectImportBuilder implement return false; } - final Runnable runnable = new Runnable() { - public void run() { - if (!naturesNames.isEmpty()) { - final String title = "Unknown Natures Detected"; - final String naturesByProject; - if (oneProjectToConvert) { - naturesByProject = naturesNames.values().iterator().next(); - } - else { - naturesByProject = StringUtil.join(naturesNames.keySet(), new Function() { - @Override - public String fun(String projectPath) { - return projectPath + "(" + naturesNames.get(projectPath) + ")"; - } - }, "
"); - } - Notifications.Bus.notify(new Notification(title, title, "Imported projects contain unknown natures:
" + naturesByProject + "
" + - "Some settings may be lost after import.", NotificationType.WARNING)); - } + if (!naturesNames.isEmpty()) { + final String title = "Unknown Natures Detected"; + final String naturesByProject; + if (oneProjectToConvert) { + naturesByProject = naturesNames.values().iterator().next(); } - }; - ApplicationManager.getApplication().invokeLater(runnable, ModalityState.NON_MODAL); + else { + naturesByProject = StringUtil.join(naturesNames.keySet(), new Function() { + @Override + public String fun(String projectPath) { + return projectPath + "(" + naturesNames.get(projectPath) + ")"; + } + }, "
"); + } + Notifications.Bus.notify(new Notification(title, title, "Imported projects contain unknown natures:
" + naturesByProject + "
" + + "Some settings may be lost after import.", NotificationType.WARNING)); + } return true; } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleNotification.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleNotification.java index ce251bcd6b20..e2daddd7d1c3 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleNotification.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleNotification.java @@ -20,7 +20,6 @@ import com.intellij.notification.NotificationListener; import com.intellij.notification.NotificationType; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; -import com.intellij.ui.AppUIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -46,12 +45,7 @@ public class GradleNotification { @NotNull final String message, @NotNull final NotificationType type, @Nullable final NotificationListener listener) { - AppUIUtil.invokeLaterIfProjectAlive(myProject, new Runnable() { - @Override - public void run() { - NOTIFICATION_GROUP.createNotification(title, message, type, listener).notify(myProject); - } - }); + NOTIFICATION_GROUP.createNotification(title, message, type, listener).notify(myProject); } } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java index db929294871f..912264364299 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java @@ -252,12 +252,7 @@ public class MavenProjectsManager extends MavenSimpleProjectComponent @NotNull final NotificationGroup group, @NotNull final NotificationType type, @Nullable final NotificationListener listener) { - AppUIUtil.invokeLaterIfProjectAlive(myProject, new Runnable() { - @Override - public void run() { - group.createNotification(title, message, type, listener).notify(myProject); - } - }); + group.createNotification(title, message, type, listener).notify(myProject); } private void initMavenized() { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenAttachSourcesProvider.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenAttachSourcesProvider.java index 17c4d2beacfa..04a3a1ec8e16 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenAttachSourcesProvider.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenAttachSourcesProvider.java @@ -37,7 +37,6 @@ import org.jetbrains.idea.maven.project.MavenProject; import org.jetbrains.idea.maven.project.MavenProjectsManager; import org.jetbrains.idea.maven.project.ProjectBundle; -import javax.swing.*; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -98,16 +97,11 @@ public class MavenAttachSourcesProvider implements AttachSourcesProvider { } message.append(""); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - Notifications.Bus.notify(new Notification(MavenUtil.MAVEN_NOTIFICATION_GROUP, - "Cannot download sources", - message.toString(), - NotificationType.WARNING), - psiFile.getProject()); - } - }); + Notifications.Bus.notify(new Notification(MavenUtil.MAVEN_NOTIFICATION_GROUP, + "Cannot download sources", + message.toString(), + NotificationType.WARNING), + psiFile.getProject()); } if (downloadResult.resolvedSources.isEmpty()) {