]> source.dussan.org Git - vaadin-framework.git/commitdiff
#6097 Added support for htmlModeAllowed in notifications opened from a sub window
authorLeif Åstrand <leif@vaadin.com>
Wed, 10 Aug 2011 12:21:17 +0000 (12:21 +0000)
committerLeif Åstrand <leif@vaadin.com>
Wed, 10 Aug 2011 12:21:17 +0000 (12:21 +0000)
svn changeset:20270/svn branch:6.7

src/com/vaadin/terminal/gwt/client/ui/VNotification.java
src/com/vaadin/terminal/gwt/client/ui/VView.java
src/com/vaadin/terminal/gwt/client/ui/VWindow.java
tests/src/com/vaadin/tests/components/notification/NotificationsHtmlAllowed.html
tests/src/com/vaadin/tests/components/notification/NotificationsHtmlAllowed.java

index f0438700fddccdbc709342869793613eacf19486..c3d239310c3bd746b4dc34cc3b5f074fc022470b 100644 (file)
@@ -9,7 +9,6 @@ import java.util.Date;
 import java.util.EventObject;\r
 import java.util.Iterator;\r
 \r
-import com.google.gwt.core.client.Scheduler;\r
 import com.google.gwt.event.dom.client.KeyCodes;\r
 import com.google.gwt.user.client.DOM;\r
 import com.google.gwt.user.client.Element;\r
@@ -17,7 +16,10 @@ import com.google.gwt.user.client.Event;
 import com.google.gwt.user.client.Timer;\r
 import com.google.gwt.user.client.ui.HTML;\r
 import com.google.gwt.user.client.ui.Widget;\r
+import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
 import com.vaadin.terminal.gwt.client.BrowserInfo;\r
+import com.vaadin.terminal.gwt.client.UIDL;\r
+import com.vaadin.terminal.gwt.client.Util;\r
 \r
 public class VNotification extends VOverlay {\r
 \r
@@ -62,14 +64,15 @@ public class VNotification extends VOverlay {
     public VNotification(int delayMsec) {\r
         this();\r
         this.delayMsec = delayMsec;\r
-        if(BrowserInfo.get().isTouchDevice()) {\r
-            new Timer(){\r
+        if (BrowserInfo.get().isTouchDevice()) {\r
+            new Timer() {\r
                 @Override\r
                 public void run() {\r
-                    if(isAttached()) {\r
+                    if (isAttached()) {\r
                         fade();\r
                     }\r
-                }}.schedule(delayMsec + TOUCH_DEVICE_IDLE_DELAY );\r
+                }\r
+            }.schedule(delayMsec + TOUCH_DEVICE_IDLE_DELAY);\r
         }\r
     }\r
 \r
@@ -331,6 +334,40 @@ public class VNotification extends VOverlay {
         }\r
     }\r
 \r
+    public static void showNotification(ApplicationConnection client,\r
+            final UIDL notification) {\r
+        boolean htmlContentAllowed = notification\r
+                .hasAttribute(VView.NOTIFICATION_HTML_CONTENT_ALLOWED);\r
+        String html = "";\r
+        if (notification.hasAttribute("icon")) {\r
+            final String parsedUri = client.translateVaadinUri(notification\r
+                    .getStringAttribute("icon"));\r
+            html += "<img src=\"" + parsedUri + "\" />";\r
+        }\r
+        if (notification.hasAttribute("caption")) {\r
+            String caption = notification.getStringAttribute("caption");\r
+            if (!htmlContentAllowed) {\r
+                caption = Util.escapeHTML(caption);\r
+                caption = caption.replaceAll("\\n", "<br />");\r
+            }\r
+            html += "<h1>" + caption + "</h1>";\r
+        }\r
+        if (notification.hasAttribute("message")) {\r
+            String message = notification.getStringAttribute("message");\r
+            if (!htmlContentAllowed) {\r
+                message = Util.escapeHTML(message);\r
+                message = message.replaceAll("\\n", "<br />");\r
+            }\r
+            html += "<p>" + message + "</p>";\r
+        }\r
+\r
+        final String style = notification.hasAttribute("style") ? notification\r
+                .getStringAttribute("style") : null;\r
+        final int position = notification.getIntAttribute("position");\r
+        final int delay = notification.getIntAttribute("delay");\r
+        new VNotification(delay).show(html, position, style);\r
+    }\r
+\r
     public class HideEvent extends EventObject {\r
 \r
         public HideEvent(Object source) {\r
index eba6036deb6147263d8515b17231b7b1eebec48c..1e9a5ba5a0d67ede56143ec1c9e797c7d38d9240 100644 (file)
@@ -322,40 +322,7 @@ public class VView extends SimplePanel implements Container, ResizeHandler,
                 for (final Iterator<?> it = childUidl.getChildIterator(); it
                         .hasNext();) {
                     final UIDL notification = (UIDL) it.next();
-                    boolean htmlContentAllowed = notification
-                            .hasAttribute(NOTIFICATION_HTML_CONTENT_ALLOWED);
-                    String html = "";
-                    if (notification.hasAttribute("icon")) {
-                        final String parsedUri = client
-                                .translateVaadinUri(notification
-                                        .getStringAttribute("icon"));
-                        html += "<img src=\"" + parsedUri + "\" />";
-                    }
-                    if (notification.hasAttribute("caption")) {
-                        String caption = notification
-                                .getStringAttribute("caption");
-                        if (!htmlContentAllowed) {
-                            caption = Util.escapeHTML(caption);
-                            caption = caption.replaceAll("\\n", "<br />");
-                        }
-                        html += "<h1>" + caption + "</h1>";
-                    }
-                    if (notification.hasAttribute("message")) {
-                        String message = notification
-                                .getStringAttribute("message");
-                        if (!htmlContentAllowed) {
-                            message = Util.escapeHTML(message);
-                            message = message.replaceAll("\\n", "<br />");
-                        }
-                        html += "<p>" + message + "</p>";
-                    }
-
-                    final String style = notification.hasAttribute("style") ? notification
-                            .getStringAttribute("style") : null;
-                    final int position = notification
-                            .getIntAttribute("position");
-                    final int delay = notification.getIntAttribute("delay");
-                    new VNotification(delay).show(html, position, style);
+                    VNotification.showNotification(client, notification);
                 }
             } else {
                 // subwindows
index e2fe47cc2c270eff0320ecde44208eb691386c4d..8d5215f5286117c300f622f8a7cde2bc39e6e111 100644 (file)
@@ -431,36 +431,10 @@ public class VWindow extends VOverlay implements Container,
                     }
                     shortcutHandler.updateActionMap(childUidl);
                 } else if (childUidl.getTag().equals("notifications")) {
-                    // TODO needed? move ->
                     for (final Iterator<?> it = childUidl.getChildIterator(); it
                             .hasNext();) {
                         final UIDL notification = (UIDL) it.next();
-                        String html = "";
-                        if (notification.hasAttribute("icon")) {
-                            final String parsedUri = client
-                                    .translateVaadinUri(notification
-                                            .getStringAttribute("icon"));
-                            html += "<img src=\"" + parsedUri + "\" />";
-                        }
-                        if (notification.hasAttribute("caption")) {
-                            html += "<h1>"
-                                    + notification
-                                            .getStringAttribute("caption")
-                                    + "</h1>";
-                        }
-                        if (notification.hasAttribute("message")) {
-                            html += "<p>"
-                                    + notification
-                                            .getStringAttribute("message")
-                                    + "</p>";
-                        }
-
-                        final String style = notification.hasAttribute("style") ? notification
-                                .getStringAttribute("style") : null;
-                        final int position = notification
-                                .getIntAttribute("position");
-                        final int delay = notification.getIntAttribute("delay");
-                        new VNotification(delay).show(html, position, style);
+                        VNotification.showNotification(client, notification);
                     }
                 }
             }
index a6a40224f7ed46b69aa9292f1b3e964da1730359..b4d76edae9d14c9e2f871977ecb4d9e89b4ce145 100644 (file)
 </tr>
 <tr>
        <td>click</td>
-       <td>vaadin=runcomvaadintestscomponentsnotificationNotificationsHtmlAllowed::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentsnotificationNotificationsHtmlAllowed::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VButton[0]/domChild[0]/domChild[0]</td>
        <td></td>
 </tr>
 <tr>
        <td>screenCapture</td>
        <td></td>
-       <td>html</td>
+       <td>view-html</td>
 </tr>
 <tr>
        <td>closeNotification</td>
-       <td>//body/div[2]</td>
+       <td>//body/div[4]</td>
        <td>0,0</td>
 </tr>
 <tr>
        <td>mouseClick</td>
        <td>vaadin=runcomvaadintestscomponentsnotificationNotificationsHtmlAllowed::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]</td>
-       <td>66,2</td>
+       <td>60,0</td>
 </tr>
 <tr>
        <td>click</td>
-       <td>vaadin=runcomvaadintestscomponentsnotificationNotificationsHtmlAllowed::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentsnotificationNotificationsHtmlAllowed::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VButton[0]/domChild[0]/domChild[0]</td>
        <td></td>
 </tr>
 <tr>
        <td>screenCapture</td>
-       <td><br /></td>
-       <td>plain</td>
+       <td></td>
+       <td>view-plain</td>
+</tr>
+<tr>
+       <td>closeNotification</td>
+       <td>//body/div[4]</td>
+       <td>0,0</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentsnotificationNotificationsHtmlAllowed::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]</td>
+       <td>51,7</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsnotificationNotificationsHtmlAllowed::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>window-plain</td>
+</tr>
+<tr>
+       <td>closeNotification</td>
+       <td>//body/div[4]</td>
+       <td>0,0</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentsnotificationNotificationsHtmlAllowed::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]</td>
+       <td>80,2</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsnotificationNotificationsHtmlAllowed::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>window-html</td>
 </tr>
 <tr>
        <td>closeNotification</td>
-       <td>//body/div[2]</td>
+       <td>//body/div[4]</td>
        <td>0,0</td>
 </tr>
 </tbody></table>
index 58f6c12f440f04557b4a5b08b5d1622bfe29d14f..d4f153d30176d02ca4eddef1486ea3b857441b46 100644 (file)
@@ -7,6 +7,7 @@ import com.vaadin.ui.Button.ClickListener;
 import com.vaadin.ui.CheckBox;\r
 import com.vaadin.ui.TextArea;\r
 import com.vaadin.ui.TextField;\r
+import com.vaadin.ui.Window;\r
 import com.vaadin.ui.Window.Notification;\r
 \r
 public class NotificationsHtmlAllowed extends TestBase implements ClickListener {\r
@@ -14,19 +15,32 @@ public class NotificationsHtmlAllowed extends TestBase implements ClickListener
     private TextArea messageField;\r
     private CheckBox htmlAllowedBox;\r
     private TextField captionField;\r
+    private Window subwindow;\r
+    private CheckBox showInSubwindow;\r
 \r
     @Override\r
     protected void setup() {\r
         captionField = new TextField("Caption", "Hello <u>world</u>");\r
         addComponent(captionField);\r
+\r
         messageField = new TextArea("Message",\r
                 "Hello <i>world</i>\nWith a newline <br/>And a html line break");\r
         messageField.setRows(10);\r
         addComponent(messageField);\r
+\r
         htmlAllowedBox = new CheckBox("Html content allowed", true);\r
         addComponent(htmlAllowedBox);\r
+\r
+        showInSubwindow = new CheckBox("Show in subwindow", false);\r
+        addComponent(showInSubwindow);\r
+\r
         Button showNotification = new Button("Show notification", this);\r
         addComponent(showNotification);\r
+\r
+        subwindow = new Window("Sub window");\r
+        subwindow.setPositionX(400);\r
+        subwindow.setPositionY(0);\r
+        getMainWindow().addWindow(subwindow);\r
     }\r
 \r
     @Override\r
@@ -40,11 +54,22 @@ public class NotificationsHtmlAllowed extends TestBase implements ClickListener
     }\r
 \r
     public void buttonClick(ClickEvent event) {\r
+        Notification n = makeNotification();\r
+        Window window;\r
+        if (showInSubwindow.booleanValue()) {\r
+            window = subwindow;\r
+        } else {\r
+            window = event.getButton().getWindow();\r
+        }\r
+        window.showNotification(n);\r
+\r
+    }\r
+\r
+    private Notification makeNotification() {\r
         Notification n = new Notification((String) captionField.getValue(),\r
                 (String) messageField.getValue(),\r
                 Notification.TYPE_HUMANIZED_MESSAGE,\r
                 htmlAllowedBox.booleanValue());\r
-        event.getButton().getWindow().showNotification(n);\r
-\r
+        return n;\r
     }\r
 }\r