From 04722c351b2b8619884fbedbcdc4d6a50c4e1d55 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Wed, 2 Nov 2011 14:03:49 +0200 Subject: [PATCH] Restored support for Notifications in root Also removed the deprecated set/getMessage method from Notification --- src/com/vaadin/RootTestApplication.java | 6 +- src/com/vaadin/ui/DefaultRoot.java | 173 +++++++++++++++++++++ src/com/vaadin/ui/Root.java | 15 ++ src/com/vaadin/ui/Window.java | 194 ------------------------ 4 files changed, 189 insertions(+), 199 deletions(-) diff --git a/src/com/vaadin/RootTestApplication.java b/src/com/vaadin/RootTestApplication.java index b9707ce6fc..08958d8edc 100644 --- a/src/com/vaadin/RootTestApplication.java +++ b/src/com/vaadin/RootTestApplication.java @@ -3,17 +3,13 @@ package com.vaadin; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.DefaultRoot; -import com.vaadin.ui.Label; import com.vaadin.ui.Root; -import com.vaadin.ui.Window; public class RootTestApplication extends Application { private final Root root = new DefaultRoot(new Button("Roots, bloody roots", new Button.ClickListener() { public void buttonClick(ClickEvent event) { - Window subWindow = new Window("Sub window"); - subWindow.addComponent(new Label("More roots")); - root.addWindow(subWindow); + root.showNotification("Testing"); } })); diff --git a/src/com/vaadin/ui/DefaultRoot.java b/src/com/vaadin/ui/DefaultRoot.java index a04d1baf08..8eb4a26050 100644 --- a/src/com/vaadin/ui/DefaultRoot.java +++ b/src/com/vaadin/ui/DefaultRoot.java @@ -4,6 +4,8 @@ import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; import com.vaadin.Application; import com.vaadin.terminal.PaintException; @@ -11,6 +13,7 @@ import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Terminal; import com.vaadin.terminal.gwt.client.ui.VView; import com.vaadin.ui.Window.CloseListener; +import com.vaadin.ui.Window.Notification; @ClientWidget(VView.class) public class DefaultRoot extends AbstractComponentContainer implements Root { @@ -18,6 +21,12 @@ public class DefaultRoot extends AbstractComponentContainer implements Root { private Terminal terminal; private Application application; + /** + * A list of notifications that are waiting to be sent to the client. + * Cleared (set to null) when the notifications have been sent. + */ + private List notifications; + /** * List of windows in this root. */ @@ -52,6 +61,37 @@ public class DefaultRoot extends AbstractComponentContainer implements Root { w.paint(target); } + // Paint notifications + if (notifications != null) { + target.startTag("notifications"); + for (final Iterator it = notifications.iterator(); it + .hasNext();) { + final Notification n = it.next(); + target.startTag("notification"); + if (n.getCaption() != null) { + target.addAttribute("caption", n.getCaption()); + } + if (n.getDescription() != null) { + target.addAttribute("message", n.getDescription()); + } + if (n.getIcon() != null) { + target.addAttribute("icon", n.getIcon()); + } + if (!n.isHtmlContentAllowed()) { + target.addAttribute( + VView.NOTIFICATION_HTML_CONTENT_NOT_ALLOWED, true); + } + target.addAttribute("position", n.getPosition()); + target.addAttribute("delay", n.getDelayMsec()); + if (n.getStyleName() != null) { + target.addAttribute("style", n.getStyleName()); + } + target.endTag("notification"); + } + target.endTag("notifications"); + notifications = null; + } + if (pendingFocus != null) { // ensure focused component is still attached to this main window if (pendingFocus.getRoot() == this @@ -195,4 +235,137 @@ public class DefaultRoot extends AbstractComponentContainer implements Root { pendingFocus = focusable; requestRepaint(); } + + /** + * Shows a notification message on the middle of the window. The message + * automatically disappears ("humanized message"). + * + * Care should be taken to to avoid XSS vulnerabilities as the caption is + * rendered as html. + * + * @see #showNotification(com.vaadin.ui.Window.Notification) + * @see Notification + * + * @param caption + * The message + */ + public void showNotification(String caption) { + addNotification(new Notification(caption)); + } + + /** + * Shows a notification message the window. The position and behavior of the + * message depends on the type, which is one of the basic types defined in + * {@link Notification}, for instance Notification.TYPE_WARNING_MESSAGE. + * + * Care should be taken to to avoid XSS vulnerabilities as the caption is + * rendered as html. + * + * @see #showNotification(com.vaadin.ui.Window.Notification) + * @see Notification + * + * @param caption + * The message + * @param type + * The message type + */ + public void showNotification(String caption, int type) { + addNotification(new Notification(caption, type)); + } + + /** + * Shows a notification consisting of a bigger caption and a smaller + * description on the middle of the window. The message automatically + * disappears ("humanized message"). + * + * Care should be taken to to avoid XSS vulnerabilities as the caption and + * description are rendered as html. + * + * @see #showNotification(com.vaadin.ui.Window.Notification) + * @see Notification + * + * @param caption + * The caption of the message + * @param description + * The message description + * + */ + public void showNotification(String caption, String description) { + addNotification(new Notification(caption, description)); + } + + /** + * Shows a notification consisting of a bigger caption and a smaller + * description. The position and behavior of the message depends on the + * type, which is one of the basic types defined in {@link Notification}, + * for instance Notification.TYPE_WARNING_MESSAGE. + * + * Care should be taken to to avoid XSS vulnerabilities as the caption and + * description are rendered as html. + * + * @see #showNotification(com.vaadin.ui.Window.Notification) + * @see Notification + * + * @param caption + * The caption of the message + * @param description + * The message description + * @param type + * The message type + */ + public void showNotification(String caption, String description, int type) { + addNotification(new Notification(caption, description, type)); + } + + /** + * Shows a notification consisting of a bigger caption and a smaller + * description. The position and behavior of the message depends on the + * type, which is one of the basic types defined in {@link Notification}, + * for instance Notification.TYPE_WARNING_MESSAGE. + * + * Care should be taken to avoid XSS vulnerabilities if html content is + * allowed. + * + * @see #showNotification(com.vaadin.ui.Window.Notification) + * @see Notification + * + * @param caption + * The message caption + * @param description + * The message description + * @param type + * The type of message + * @param htmlContentAllowed + * Whether html in the caption and description should be + * displayed as html or as plain text + */ + public void showNotification(String caption, String description, int type, + boolean htmlContentAllowed) { + addNotification(new Notification(caption, description, type, + htmlContentAllowed)); + } + + /** + * Shows a notification message. + * + * @see Notification + * @see #showNotification(String) + * @see #showNotification(String, int) + * @see #showNotification(String, String) + * @see #showNotification(String, String, int) + * + * @param notification + * The notification message to show + */ + public void showNotification(Notification notification) { + addNotification(notification); + } + + private void addNotification(Notification notification) { + if (notifications == null) { + notifications = new LinkedList(); + } + notifications.add(notification); + requestRepaint(); + } } diff --git a/src/com/vaadin/ui/Root.java b/src/com/vaadin/ui/Root.java index 232a28ec5f..332220f88d 100644 --- a/src/com/vaadin/ui/Root.java +++ b/src/com/vaadin/ui/Root.java @@ -4,6 +4,7 @@ import java.util.Collection; import com.vaadin.Application; import com.vaadin.terminal.Terminal; +import com.vaadin.ui.Window.Notification; public interface Root extends Component, com.vaadin.ui.Component.Focusable { @@ -35,4 +36,18 @@ public interface Root extends Component, com.vaadin.ui.Component.Focusable { public void setFocusedComponent(Focusable focusable); + public void showNotification(Notification notification); + + public void showNotification(String caption, String description, + int type, boolean htmlContentAllowed); + + public void showNotification(String caption, String description, + int type); + + public void showNotification(String caption, String description); + + public void showNotification(String caption, int type); + + public void showNotification(String caption); + } diff --git a/src/com/vaadin/ui/Window.java b/src/com/vaadin/ui/Window.java index d785a66f25..7366f90874 100644 --- a/src/com/vaadin/ui/Window.java +++ b/src/com/vaadin/ui/Window.java @@ -136,14 +136,6 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier { */ private int positionX = -1; - // /** - // * Application window only. A list of notifications that are - // waiting - // * to be sent to the client. Cleared (set to null) when the notifications - // * have been sent. - // */ - // private LinkedList notifications; - /** * Sub window only. Modality flag for sub window. */ @@ -497,38 +489,6 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier { // Window closing target.addVariable(this, "close", false); - - // // Paint notifications - // if (notifications != null) { - // target.startTag("notifications"); - // for (final Iterator it = notifications.iterator(); it - // .hasNext();) { - // final Notification n = it.next(); - // target.startTag("notification"); - // if (n.getCaption() != null) { - // target.addAttribute("caption", n.getCaption()); - // } - // if (n.getMessage() != null) { - // target.addAttribute("message", n.getMessage()); - // } - // if (n.getIcon() != null) { - // target.addAttribute("icon", n.getIcon()); - // } - // if (!n.isHtmlContentAllowed()) { - // target.addAttribute( - // VView.NOTIFICATION_HTML_CONTENT_NOT_ALLOWED, true); - // } - // target.addAttribute("position", n.getPosition()); - // target.addAttribute("delay", n.getDelayMsec()); - // if (n.getStyleName() != null) { - // target.addAttribute("style", n.getStyleName()); - // } - // target.endTag("notification"); - // } - // target.endTag("notifications"); - // notifications = null; - // } - } /* ********************************************************************* */ @@ -1313,142 +1273,6 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier { requestRepaint(); } - // /** - // * Shows a notification message on the middle of the window. The message - // * automatically disappears ("humanized message"). - // * - // * Care should be taken to to avoid XSS vulnerabilities as the caption is - // * rendered as html. - // * - // * @see #showNotification(com.vaadin.ui.Window.Notification) - // * @see Notification - // * - // * @param caption - // * The message - // */ - // public void showNotification(String caption) { - // addNotification(new Notification(caption)); - // } - - // /** - // * Shows a notification message the window. The position and behavior of - // the - // * message depends on the type, which is one of the basic types defined in - // * {@link Notification}, for instance Notification.TYPE_WARNING_MESSAGE. - // * - // * Care should be taken to to avoid XSS vulnerabilities as the caption is - // * rendered as html. - // * - // * @see #showNotification(com.vaadin.ui.Window.Notification) - // * @see Notification - // * - // * @param caption - // * The message - // * @param type - // * The message type - // */ - // public void showNotification(String caption, int type) { - // addNotification(new Notification(caption, type)); - // } - - // /** - // * Shows a notification consisting of a bigger caption and a smaller - // * description on the middle of the window. The message automatically - // * disappears ("humanized message"). - // * - // * Care should be taken to to avoid XSS vulnerabilities as the caption and - // * description are rendered as html. - // * - // * @see #showNotification(com.vaadin.ui.Window.Notification) - // * @see Notification - // * - // * @param caption - // * The caption of the message - // * @param description - // * The message description - // * - // */ - // public void showNotification(String caption, String description) { - // addNotification(new Notification(caption, description)); - // } - - // /** - // * Shows a notification consisting of a bigger caption and a smaller - // * description. The position and behavior of the message depends on the - // * type, which is one of the basic types defined in {@link Notification}, - // * for instance Notification.TYPE_WARNING_MESSAGE. - // * - // * Care should be taken to to avoid XSS vulnerabilities as the caption and - // * description are rendered as html. - // * - // * @see #showNotification(com.vaadin.ui.Window.Notification) - // * @see Notification - // * - // * @param caption - // * The caption of the message - // * @param description - // * The message description - // * @param type - // * The message type - // */ - // public void showNotification(String caption, String description, int - // type) { - // addNotification(new Notification(caption, description, type)); - // } - - // /** - // * Shows a notification consisting of a bigger caption and a smaller - // * description. The position and behavior of the message depends on the - // * type, which is one of the basic types defined in {@link Notification}, - // * for instance Notification.TYPE_WARNING_MESSAGE. - // * - // * Care should be taken to avoid XSS vulnerabilities if html content is - // * allowed. - // * - // * @see #showNotification(com.vaadin.ui.Window.Notification) - // * @see Notification - // * - // * @param caption - // * The message caption - // * @param description - // * The message description - // * @param type - // * The type of message - // * @param htmlContentAllowed - // * Whether html in the caption and description should be - // * displayed as html or as plain text - // */ - // public void showNotification(String caption, String description, int - // type, - // boolean htmlContentAllowed) { - // addNotification(new Notification(caption, description, type, - // htmlContentAllowed)); - // } - - // /** - // * Shows a notification message. - // * - // * @see Notification - // * @see #showNotification(String) - // * @see #showNotification(String, int) - // * @see #showNotification(String, String) - // * @see #showNotification(String, String, int) - // * - // * @param notification - // * The notification message to show - // */ - // public void showNotification(Notification notification) { - // addNotification(notification); - // } - // - // private void addNotification(Notification notification) { - // if (notifications == null) { - // notifications = new LinkedList(); - // } - // notifications.add(notification); - // requestRepaint(); - // } - /** * A notification message, used to display temporary messages to the user - * for example "Document saved", or "Save failed". @@ -1643,24 +1467,6 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier { this.caption = caption; } - /** - * @deprecated Use {@link #getDescription()} instead. - * @return - */ - @Deprecated - public String getMessage() { - return description; - } - - /** - * @deprecated Use {@link #setDescription(String)} instead. - * @param description - */ - @Deprecated - public void setMessage(String description) { - this.description = description; - } - /** * Gets the description part of the notification message. * -- 2.39.5