summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorArtur <artur@vaadin.com>2018-01-09 13:11:02 +0200
committerTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2018-01-09 13:11:02 +0200
commit59a2dafdcb1333b278484bdd65b3ca3cc7bb87f8 (patch)
tree9222a32b504433b787bafca805637d21e5f3bddf /client
parent531320c5051b7f72c9d96c7826b5cd4f9dcaae67 (diff)
downloadvaadin-framework-59a2dafdcb1333b278484bdd65b3ca3cc7bb87f8.tar.gz
vaadin-framework-59a2dafdcb1333b278484bdd65b3ca3cc7bb87f8.zip
Add Notification.close() to hide a notification from the server (#10483)
Also fixes the problem that notifications were never removed on the server side Fixes #2114, fixes #10481
Diffstat (limited to 'client')
-rw-r--r--client/src/main/java/com/vaadin/client/ui/notification/NotificationConnector.java32
1 files changed, 23 insertions, 9 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/notification/NotificationConnector.java b/client/src/main/java/com/vaadin/client/ui/notification/NotificationConnector.java
index 038d70dbf3..a0c49af8a3 100644
--- a/client/src/main/java/com/vaadin/client/ui/notification/NotificationConnector.java
+++ b/client/src/main/java/com/vaadin/client/ui/notification/NotificationConnector.java
@@ -36,6 +36,8 @@ import com.vaadin.ui.Notification;
@Connect(value = Notification.class)
public class NotificationConnector extends AbstractExtensionConnector {
+ private VNotification notification;
+
@Override
public NotificationState getState() {
return (NotificationState) super.getState();
@@ -44,21 +46,33 @@ public class NotificationConnector extends AbstractExtensionConnector {
@Override
protected void extend(ServerConnector target) {
NotificationState state = getState();
- VNotification n = VNotification.showNotification(
- target.getConnection(),
- state.caption, state.description,
- state.htmlContentAllowed, getResourceUrl("icon"),
- state.styleName, state.position, state.delay);
+ notification = VNotification.showNotification(target.getConnection(),
+ state.caption, state.description, state.htmlContentAllowed,
+ getResourceUrl("icon"), state.styleName, state.position,
+ state.delay);
- n.addCloseHandler(new CloseHandler<PopupPanel>() {
+ notification.addCloseHandler(new CloseHandler<PopupPanel>() {
@Override
public void onClose(CloseEvent<PopupPanel> event) {
- NotificationServerRpc rpc =
- getRpcProxy(NotificationServerRpc.class);
- rpc.closed();
+ if (getParent() == null) {
+ // Unregistered already
+ return;
+ }
+ NotificationServerRpc rpc = getRpcProxy(
+ NotificationServerRpc.class);
+ rpc.closed();
+ notification = null;
}
});
}
+ @Override
+ public void onUnregister() {
+ super.onUnregister();
+ if (notification != null) {
+ notification.hide();
+ notification = null;
+ }
+ }
}