From: Marc Englund Date: Thu, 6 Mar 2008 14:23:19 +0000 (+0000) Subject: Documented Notification ( #1359 ) and implemented icon support that was i the API... X-Git-Tag: 6.7.0.beta1~4975 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e48421992d8ea11ca3a46e97e1aecb1aaf2d9d4a;p=vaadin-framework.git Documented Notification ( #1359 ) and implemented icon support that was i the API but not working. svn changeset:3989/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IView.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IView.java index 46dd36a254..dd4bd2b08e 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IView.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IView.java @@ -119,6 +119,12 @@ public class IView extends SimplePanel implements Paintable, .hasNext();) { final UIDL notification = (UIDL) it.next(); String html = ""; + if (notification.hasAttribute("icon")) { + final String parsedUri = client + .translateToolkitUri(notification + .getStringAttribute("icon")); + html += ""; + } if (notification.hasAttribute("caption")) { html += "

" + notification.getStringAttribute("caption") diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java index bb280172c6..ca296a073a 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java @@ -241,11 +241,14 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { setCaption(uidl.getStringAttribute("caption")); } - UIDL childUidl = uidl.getChildUIDL(0); - if ("open".equals(childUidl.getTag())) { + boolean showingUrl = false; + int childIndex = 0; + UIDL childUidl = uidl.getChildUIDL(childIndex++); + while ("open".equals(childUidl.getTag())) { + // TODO multipe opens with the same target will in practice just + // open the last one - should we fix that somehow? final String parsedUri = client.translateToolkitUri(childUidl .getStringAttribute("src")); - // TODO this should be a while-loop for multiple opens if (!childUidl.hasAttribute("name")) { final Frame frame = new Frame(); DOM.setStyleAttribute(frame.getElement(), "width", "100%"); @@ -253,26 +256,30 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { DOM.setStyleAttribute(frame.getElement(), "border", "0px"); frame.setUrl(parsedUri); contentPanel.setWidget(frame); + showingUrl = true; } else { final String target = childUidl.getStringAttribute("name"); Window.open(parsedUri, target, ""); } - } else { - final Paintable lo = client.getPaintable(childUidl); - if (layout != null) { - if (layout != lo) { - // remove old - client.unregisterPaintable(layout); - contentPanel.remove((Widget) layout); - // add new + childUidl = uidl.getChildUIDL(childIndex++); + } + + final Paintable lo = client.getPaintable(childUidl); + if (layout != null) { + if (layout != lo) { + // remove old + client.unregisterPaintable(layout); + contentPanel.remove((Widget) layout); + // add new + if (!showingUrl) { contentPanel.setWidget((Widget) lo); - layout = lo; } - } else { - contentPanel.setWidget((Widget) lo); + layout = lo; } - lo.updateFromUIDL(childUidl, client); + } else if (!showingUrl) { + contentPanel.setWidget((Widget) lo); } + lo.updateFromUIDL(childUidl, client); // we may have actions and notifications if (uidl.getChildCount() > 1) { @@ -290,6 +297,12 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { .hasNext();) { final UIDL notification = (UIDL) it.next(); String html = ""; + if (notification.hasAttribute("icon")) { + final String parsedUri = client + .translateToolkitUri(notification + .getStringAttribute("icon")); + html += ""; + } if (notification.hasAttribute("caption")) { html += "

" + notification diff --git a/src/com/itmill/toolkit/ui/Window.java b/src/com/itmill/toolkit/ui/Window.java index 416270f194..51dbde11ab 100644 --- a/src/com/itmill/toolkit/ui/Window.java +++ b/src/com/itmill/toolkit/ui/Window.java @@ -505,6 +505,9 @@ public class Window extends Panel implements URIHandler, ParameterHandler { if (n.getMessage() != null) { target.addAttribute("message", n.getMessage()); } + if (n.getIcon() != null) { + target.addAttribute("icon", n.getIcon()); + } target.addAttribute("position", n.getPosition()); target.addAttribute("delay", n.getDelayMsec()); if (n.getStyleName() != null) { @@ -1081,22 +1084,87 @@ public class Window extends Panel implements URIHandler, ParameterHandler { this.scrollLeft = scrollLeft; } + /** + * Shows a notification message on the middle of the window. The message + * automatically disappears ("humanized message"). + * + * @see #showNotification(com.itmill.toolkit.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. + * + * @see #showNotification(com.itmill.toolkit.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)); } - public void showNotification(String caption, String message) { - addNotification(new Notification(caption, message)); + /** + * Shows a notification consisting of a bigger caption and a smaller + * description on the middle of the window. The message automatically + * disappears ("humanized message"). + * + * @see #showNotification(com.itmill.toolkit.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)); } - public void showNotification(String caption, String message, int type) { - addNotification(new Notification(caption, message, 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. + * + * @see #showNotification(com.itmill.toolkit.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 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); } @@ -1109,7 +1177,43 @@ public class Window extends Panel implements URIHandler, ParameterHandler { requestRepaint(); } - public class Notification { + /** + * A notification message, used to display temporary messages to the user - + * for example "Document saved", or "Save failed". + *

+ * The notification message tries to be as unobtrusive as possible, while + * still drawing needed attention. There are several basic types of messages + * that can be used in different situations: + *

+ *

+ *

+ * In addition to the basic pre-configured types, a Notification can also be + * configured to show up in a custom position, for a specified time (or + * until clicked), and with a custom stylename. An icon can also be added. + *

+ * + */ + public static class Notification { public static final int TYPE_HUMANIZED_MESSAGE = 1; public static final int TYPE_WARNING_MESSAGE = 2; public static final int TYPE_ERROR_MESSAGE = 3;