Reputation: 1145
Is it possible to somehow get the currently shown Notification from a given window in Vaadin? Looking at the Window API, all I can see is a couple of showWindow()
methods.
So, does anyone know if there exist some functionality for getting the currently shown Notification (if there is any Notification present, that is)?
Upvotes: 2
Views: 1253
Reputation: 501
By reflection :
private boolean isNotified(String notif) throws SecurityException, NoSuchFieldException,
IllegalArgumentException, IllegalAccessException {
Page current = Page.getCurrent();
Field f = current.getClass().getDeclaredField("notifications");
f.setAccessible(true);
List<Notification> notifications = (List<Notification>) f.get(current);
boolean found = false;
if (notifications != null) {
for (Notification notification : notifications) {
if (notification.getCaption() == notif) {
found=true;
}
}
}
return found;
}
Upvotes: 1
Reputation: 3155
I do not believe there is currently any way to do this.
You could override Window#showNotification(Notification) to keep track of this yourself, but as far as I can see, the client doesn't tell the server that the notification has been closed => there's no way of "resetting" this flag.
(the private method Window#addNotification keeps track of the notifications to send to the browser in a linked list, but Window#paintContent(PaintTarget) clears that list as soon as they are sent to the browser)
Upvotes: 3