Also removed the deprecated set/getMessage method from Notificationtags/7.0.0.alpha1
@@ -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"); | |||
} | |||
})); | |||
@@ -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(); | |||
} | |||
} |
@@ -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); | |||
} |
@@ -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. | |||
* |