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
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
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
}\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
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
}
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);
}
}
}
</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>
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
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
}\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