From b565c34753ceef7d2b6539b0d3f274ee8cab826e Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 7 Jun 2011 16:48:53 +0200 Subject: [PATCH] logEvent replaced with explicit notifications with different groupIds --- .../intellij/compiler/impl/CompileDriver.java | 12 ++++-- .../intellij/notification/Notification.java | 5 +++ .../intellij/notification/Notifications.java | 4 -- .../notification/NotificationGroup.java | 42 +++++++++++++++++++ .../execution/testframework/TestsUIUtil.java | 7 ++-- .../update/AbstractCommonUpdateAction.java | 19 ++++----- 6 files changed, 67 insertions(+), 22 deletions(-) create mode 100644 platform/platform-impl/src/com/intellij/notification/NotificationGroup.java diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java index a448e00f44d1..8d18828a4d5b 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java @@ -29,7 +29,8 @@ import com.intellij.compiler.make.DependencyCache; import com.intellij.compiler.progress.CompilerTask; import com.intellij.diagnostic.IdeErrorsDialog; import com.intellij.diagnostic.PluginException; -import com.intellij.notification.Notifications; +import com.intellij.notification.NotificationDisplayType; +import com.intellij.notification.NotificationGroup; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.Result; @@ -70,7 +71,10 @@ import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.newvfs.ManagingFS; import com.intellij.openapi.vfs.newvfs.RefreshQueue; import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS; -import com.intellij.openapi.wm.*; +import com.intellij.openapi.wm.StatusBar; +import com.intellij.openapi.wm.ToolWindowId; +import com.intellij.openapi.wm.ToolWindowManager; +import com.intellij.openapi.wm.WindowManager; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.PsiDocumentManager; import com.intellij.util.*; @@ -88,6 +92,8 @@ import java.io.*; import java.util.*; public class CompileDriver { + private static final NotificationGroup NOTIFICATION_GROUP = new NotificationGroup("Compiler", NotificationDisplayType.NONE, true); + private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.impl.CompileDriver"); // to be used in tests only for debug output public static volatile boolean ourDebugMode = false; @@ -551,7 +557,7 @@ public class CompileDriver { if (_status == ExitStatus.UP_TO_DATE) { logMessage = "Compilation: all files are up to date"; } - Notifications.Bus.logEvent(logMessage, messageType.toNotificationType(), myProject); + NOTIFICATION_GROUP.createNotification(logMessage, messageType.toNotificationType()).notify(myProject); } if (_status != ExitStatus.UP_TO_DATE && compileContext.getMessageCount(null) > 0) { compileContext.addMessage(CompilerMessageCategory.INFORMATION, statusMessage, null, -1, -1); diff --git a/platform/platform-api/src/com/intellij/notification/Notification.java b/platform/platform-api/src/com/intellij/notification/Notification.java index 2882c12c6838..8b5cc4483b2a 100644 --- a/platform/platform-api/src/com/intellij/notification/Notification.java +++ b/platform/platform-api/src/com/intellij/notification/Notification.java @@ -16,6 +16,7 @@ package com.intellij.notification; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.Balloon; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -109,4 +110,8 @@ public class Notification { public Balloon getBalloon() { return myBalloonRef == null ? null : myBalloonRef.get(); } + + public void notify(@Nullable Project project) { + Notifications.Bus.notify(this, project); + } } diff --git a/platform/platform-api/src/com/intellij/notification/Notifications.java b/platform/platform-api/src/com/intellij/notification/Notifications.java index 311fa14c9544..a1e3d2d60221 100644 --- a/platform/platform-api/src/com/intellij/notification/Notifications.java +++ b/platform/platform-api/src/com/intellij/notification/Notifications.java @@ -70,10 +70,6 @@ public interface Notifications { notify(notification, null); } - public static void logEvent(@NotNull String text, NotificationType type, @Nullable final Project project) { - notify(new Notification(LOG_ONLY_GROUP_ID, "", text, type), project); - } - public static void notify(@NotNull final Notification notification, @Nullable final Project project) { invoke(project, new Processor() { @Override diff --git a/platform/platform-impl/src/com/intellij/notification/NotificationGroup.java b/platform/platform-impl/src/com/intellij/notification/NotificationGroup.java new file mode 100644 index 000000000000..7e783257fdf0 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/notification/NotificationGroup.java @@ -0,0 +1,42 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.notification; + +import com.intellij.notification.impl.NotificationSettings; +import com.intellij.notification.impl.NotificationsConfiguration; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author peter + */ +public class NotificationGroup { + private final String myDisplayId; + + public NotificationGroup(String displayId, NotificationDisplayType defaultDisplayType, boolean logByDefault) { + myDisplayId = displayId; + + NotificationsConfiguration.getNotificationsConfiguration().registerDefaultSettings(new NotificationSettings(displayId, defaultDisplayType, logByDefault)); + } + + public Notification createNotification(@NotNull final String content, @NotNull final NotificationType type) { + return createNotification("", content, type, null); + } + + public Notification createNotification(@NotNull final String title, @NotNull final String content, @NotNull final NotificationType type, @Nullable NotificationListener listener) { + return new Notification(myDisplayId, title, content, type, listener); + } +} diff --git a/platform/testRunner/src/com/intellij/execution/testframework/TestsUIUtil.java b/platform/testRunner/src/com/intellij/execution/testframework/TestsUIUtil.java index 07196b8e6342..c95d058e4b4e 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/TestsUIUtil.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/TestsUIUtil.java @@ -18,7 +18,8 @@ package com.intellij.execution.testframework; import com.intellij.execution.ExecutionBundle; import com.intellij.execution.Location; import com.intellij.execution.configurations.RuntimeConfiguration; -import com.intellij.notification.Notifications; +import com.intellij.notification.NotificationDisplayType; +import com.intellij.notification.NotificationGroup; import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.Application; @@ -31,7 +32,6 @@ import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.wm.ToolWindowId; import com.intellij.openapi.wm.ToolWindowManager; -import com.intellij.openapi.wm.impl.ToolWindowManagerImpl; import com.intellij.pom.Navigatable; import com.intellij.psi.PsiElement; import com.intellij.ui.SystemNotifications; @@ -45,6 +45,7 @@ import java.awt.image.BufferedImage; import java.util.List; public class TestsUIUtil { + private static final NotificationGroup NOTIFICATION_GROUP = new NotificationGroup("Test Runner", NotificationDisplayType.NONE, true); @NonNls private static final String ICONS_ROOT = "/runConfigurations/"; public static final Color PASSED_COLOR = new Color(0, 128, 0); @@ -125,7 +126,7 @@ public class TestsUIUtil { if (!Comparing.strEqual(toolWindowManager.getActiveToolWindowId(), testRunDebugId)) { toolWindowManager.notifyByBalloon(testRunDebugId, type, balloonText, null, null); } else { - Notifications.Bus.logEvent(balloonText, type.toNotificationType(), project); + NOTIFICATION_GROUP.createNotification(balloonText, type.toNotificationType()).notify(project); } SystemNotifications.getInstance().notify("TestRunner", title, text); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/AbstractCommonUpdateAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/AbstractCommonUpdateAction.java index f4f41279fab0..fab2abc2af6b 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/AbstractCommonUpdateAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/AbstractCommonUpdateAction.java @@ -19,8 +19,9 @@ import com.intellij.history.Label; import com.intellij.history.LocalHistory; import com.intellij.history.LocalHistoryAction; import com.intellij.ide.errorTreeView.HotfixData; +import com.intellij.notification.NotificationDisplayType; +import com.intellij.notification.NotificationGroup; import com.intellij.notification.NotificationType; -import com.intellij.notification.Notifications; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.application.ApplicationManager; @@ -61,6 +62,7 @@ import java.io.File; import java.util.*; public abstract class AbstractCommonUpdateAction extends AbstractVcsAction { + private static final NotificationGroup NOTIFICATION_GROUP = new NotificationGroup("VCS Update", NotificationDisplayType.NONE, true); private final boolean myAlwaysVisible; private final static Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.update.AbstractCommonUpdateAction"); @@ -195,14 +197,6 @@ public abstract class AbstractCommonUpdateAction extends AbstractVcsAction { return result; } - private static boolean containsParent(FilePath[] array, FilePath file) { - for (FilePath virtualFile : array) { - if (virtualFile == file) continue; - if (VfsUtil.isAncestor(virtualFile.getIOFile(), file.getIOFile(), false)) return true; - } - return false; - } - @NotNull private FilePath[] filterRoots(FilePath[] roots, VcsContext vcsContext) { final ArrayList result = new ArrayList(); @@ -350,7 +344,7 @@ public abstract class AbstractCommonUpdateAction extends AbstractVcsAction { public void run(@NotNull final ProgressIndicator indicator) { suspendIfNeeded(); try { - runImpl(indicator); + runImpl(); } catch (Throwable t) { releaseIfNeeded(); if (t instanceof Error) { @@ -362,7 +356,7 @@ public abstract class AbstractCommonUpdateAction extends AbstractVcsAction { } } - private void runImpl(@NotNull final ProgressIndicator indicator) { + private void runImpl() { ProjectManagerEx.getInstanceEx().blockReloadingProjectOnExternalChanges(); myProjectLevelVcsManager.startBackgroundVcsOperation(); @@ -462,7 +456,8 @@ public abstract class AbstractCommonUpdateAction extends AbstractVcsAction { if (text.length() > 0) { log += ": " + text.toString(); } - Notifications.Bus.logEvent(log, NotificationType.INFORMATION, myProject); + NOTIFICATION_GROUP.createNotification(log, NotificationType.INFORMATION).notify(myProject); + return new NotificationInfo("VCS Update", title, log, true); }