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;
}
}
- 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
Balloon balloon = NotificationsManagerImpl.createBalloon(myNotification, true, true);
Disposer.register(project, balloon);
balloon.show(target, Balloon.Position.above);
- myNotification.hideBalloon();
- myNotification.setBalloon(balloon);
}
}
.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;
}