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");
}
}));
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;
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 {
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.
*/
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
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();
+ }
}
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 {
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);
+
}
*/
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.
*/
// 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;
- // }
-
}
/* ********************************************************************* */
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".
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.
*