IDEA-80382 Notifications: when balloon is shown in Event Log and after clicking...
authorpeter <peter@jetbrains.com>
Thu, 26 Jan 2012 17:46:46 +0000 (18:46 +0100)
committerpeter <peter@jetbrains.com>
Thu, 26 Jan 2012 17:57:35 +0000 (18:57 +0100)
platform/platform-api/src/com/intellij/notification/Notification.java
platform/platform-impl/src/com/intellij/notification/EventLog.java
platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java

index b264b20d1c3cab83f19f412bfe418af8b1358829..36ad4145c9e7188cabbee30924c5bb8794685436 100644 (file)
@@ -18,6 +18,8 @@ package com.intellij.notification;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.popup.Balloon;
+import com.intellij.openapi.ui.popup.JBPopupAdapter;
+import com.intellij.openapi.ui.popup.LightweightWindowEvent;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -111,12 +113,18 @@ public class Notification {
     }
   }
 
-  public void setBalloon(@Nullable final Balloon balloon) {
-    if (balloon != null) {
-      myBalloonRef = new WeakReference<Balloon>(balloon);
-    } else {
-      myBalloonRef = null;
-    }
+  public void setBalloon(@NotNull final Balloon balloon) {
+    hideBalloon();
+    myBalloonRef = new WeakReference<Balloon>(balloon);
+    balloon.addListener(new JBPopupAdapter() {
+      @Override
+      public void onClosed(LightweightWindowEvent event) {
+        WeakReference<Balloon> ref = myBalloonRef;
+        if (ref != null && ref.get() == balloon) {
+          myBalloonRef = null;
+        }
+      }
+    });
   }
 
   @Nullable
index 79d6ad266beaaae817a1ede871c9658be5ff18ca..2d1e660c2c6d189cf4587d5c2bf8bc4b7de7631b 100644 (file)
@@ -415,8 +415,6 @@ public class EventLog implements Notifications {
         Balloon balloon = NotificationsManagerImpl.createBalloon(myNotification, true, true);
         Disposer.register(project, balloon);
         balloon.show(target, Balloon.Position.above);
-        myNotification.hideBalloon();
-        myNotification.setBalloon(balloon);
       }
     }
 
index 6870f9459f21f767fb56aedf461decc1fd08cd10..50968d23171b62354f6bca68afd33e9807dddc28 100644 (file)
@@ -314,13 +314,6 @@ public class NotificationsManagerImpl extends NotificationsManager implements No
       .setHideOnKeyOutside(hideOnClickOutside).setHideOnFrameResize(false);
 
     final Balloon balloon = builder.createBalloon();
-    balloon.addListener(new JBPopupAdapter() {
-      @Override
-      public void onClosed(LightweightWindowEvent event) {
-        notification.setBalloon(null);
-      }
-    });
-
     notification.setBalloon(balloon);
     return balloon;
   }