aboutsummaryrefslogtreecommitdiffstats
path: root/server
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 /server
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 'server')
-rw-r--r--server/src/main/java/com/vaadin/ui/Notification.java52
1 files changed, 49 insertions, 3 deletions
diff --git a/server/src/main/java/com/vaadin/ui/Notification.java b/server/src/main/java/com/vaadin/ui/Notification.java
index 24327a8cc4..9a3bc8198a 100644
--- a/server/src/main/java/com/vaadin/ui/Notification.java
+++ b/server/src/main/java/com/vaadin/ui/Notification.java
@@ -20,6 +20,7 @@ import java.io.Serializable;
import java.lang.reflect.Method;
import com.vaadin.event.ConnectorEvent;
+import com.vaadin.event.HasUserOriginated;
import com.vaadin.server.AbstractExtension;
import com.vaadin.server.Page;
import com.vaadin.server.Resource;
@@ -125,8 +126,9 @@ public class Notification extends AbstractExtension {
*
* @since 8.2
*/
- private NotificationServerRpc rpc = () -> fireEvent(
- new CloseEvent(Notification.this));
+ private NotificationServerRpc rpc = () -> {
+ close(true);
+ };
/**
* Creates a "humanized" notification message.
@@ -391,6 +393,37 @@ public class Notification extends AbstractExtension {
extend(page.getUI());
}
+ /**
+ * Closes (hides) the notification.
+ * <p>
+ * If the notification is not shown, does nothing.
+ *
+ * @since
+ */
+ public void close() {
+ close(false);
+ }
+
+ /**
+ * Closes (hides) the notification.
+ * <p>
+ * If the notification is not shown, does nothing.
+ *
+ * @param userOriginated
+ * <code>true</code> if the notification was closed because the
+ * user clicked on it, <code>false</code> if the notification was
+ * closed from the server
+ * @since
+ */
+ protected void close(boolean userOriginated) {
+ if (!isAttached()) {
+ return;
+ }
+
+ remove();
+ fireEvent(new CloseEvent(this, userOriginated));
+ }
+
@Override
protected NotificationState getState() {
return (NotificationState) super.getState();
@@ -498,13 +531,21 @@ public class Notification extends AbstractExtension {
*
* @since 8.2
*/
- public static class CloseEvent extends ConnectorEvent {
+ public static class CloseEvent extends ConnectorEvent
+ implements HasUserOriginated {
+
+ private boolean userOriginated;
/**
* @param source
*/
public CloseEvent(Notification source) {
+ this(source, true);
+ }
+
+ public CloseEvent(Notification source, boolean userOriginated) {
super(source);
+ this.userOriginated = userOriginated;
}
/**
@@ -515,6 +556,11 @@ public class Notification extends AbstractExtension {
public Notification getNotification() {
return (Notification) getSource();
}
+
+ @Override
+ public boolean isUserOriginated() {
+ return userOriginated;
+ }
}
/**