]> source.dussan.org Git - vaadin-framework.git/commitdiff
Restored support for Notifications in root
authorLeif Åstrand <leif@vaadin.com>
Wed, 2 Nov 2011 12:03:49 +0000 (14:03 +0200)
committerLeif Åstrand <leif@vaadin.com>
Wed, 2 Nov 2011 12:03:49 +0000 (14:03 +0200)
Also removed the deprecated set/getMessage method from Notification

src/com/vaadin/RootTestApplication.java
src/com/vaadin/ui/DefaultRoot.java
src/com/vaadin/ui/Root.java
src/com/vaadin/ui/Window.java

index b9707ce6fc433dc627abf4c59110494fbc0c4057..08958d8edc8ea19d7ec4483becde695ba4b4722e 100644 (file)
@@ -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");
                 }
             }));
 
index a04d1baf08f9cf93c9f124e220e09f9f60dc030a..8eb4a260501a0df3010446a9361fb90d58c667af 100644 (file)
@@ -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<Notification> 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<Notification> 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<Notification>();
+        }
+        notifications.add(notification);
+        requestRepaint();
+    }
 }
index 232a28ec5f3f8aa971fe51bc5ec618cdcce6dfc1..332220f88d30a86d881a891997c69e3e561b50c7 100644 (file)
@@ -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);
+
 }
index d785a66f2538de645ab5f890d180975c48a4b4cc..7366f90874b788fba9c78d0d4581c25b84c6bc0b 100644 (file)
@@ -136,14 +136,6 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier {
      */
     private int positionX = -1;
 
-    // /**
-    // * <b>Application window only</b>. 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<Notification> notifications;
-
     /**
      * <b>Sub window only</b>. 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<Notification> 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<Notification>();
-    // }
-    // 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.
          *