com.vaadin.ui
Class Notification

java.lang.Object
  extended by com.vaadin.ui.Notification
All Implemented Interfaces:
Serializable

public class Notification
extends Object
implements Serializable

A notification message, used to display temporary messages to the user - for example "Document saved", or "Save failed".

The notification message can consist of several parts: caption, description and icon. It is usually used with only caption - one should be wary of filling the notification with too much information.

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.

See Also:
Serialized Form

Field Summary
static int DELAY_FOREVER
           
static int DELAY_NONE
           
static int POSITION_BOTTOM_LEFT
           
static int POSITION_BOTTOM_RIGHT
           
static int POSITION_CENTERED
           
static int POSITION_CENTERED_BOTTOM
           
static int POSITION_CENTERED_TOP
           
static int POSITION_TOP_LEFT
           
static int POSITION_TOP_RIGHT
           
static int TYPE_ERROR_MESSAGE
           
static int TYPE_HUMANIZED_MESSAGE
           
static int TYPE_TRAY_NOTIFICATION
           
static int TYPE_WARNING_MESSAGE
           
 
Constructor Summary
Notification(String caption)
          Creates a "humanized" notification message.
Notification(String caption, int type)
          Creates a notification message of the specified type.
Notification(String caption, String description)
          Creates a "humanized" notification message with a bigger caption and smaller description.
Notification(String caption, String description, int type)
          Creates a notification message of the specified type, with a bigger caption and smaller description.
Notification(String caption, String description, int type, boolean htmlContentAllowed)
          Creates a notification message of the specified type, with a bigger caption and smaller description.
 
Method Summary
 String getCaption()
          Gets the caption part of the notification message.
 int getDelayMsec()
          Gets the delay before the notification disappears.
 String getDescription()
          Gets the description part of the notification message.
 Resource getIcon()
          Gets the icon part of the notification message.
 int getPosition()
          Gets the position of the notification message.
 String getStyleName()
          Gets the style name for the notification message.
 boolean isHtmlContentAllowed()
          Checks whether caption and description are interpreted as html or plain text.
 void setCaption(String caption)
          Sets the caption part of the notification message
 void setDelayMsec(int delayMsec)
          Sets the delay before the notification disappears.
 void setDescription(String description)
          Sets the description part of the notification message.
 void setHtmlContentAllowed(boolean htmlContentAllowed)
          Sets whether html is allowed in the caption and description.
 void setIcon(Resource icon)
          Sets the icon part of the notification message.
 void setPosition(int position)
          Sets the position of the notification message.
 void setStyleName(String styleName)
          Sets the style name for the notification message.
 void show(Page page)
          Shows this notification on a Page.
static void show(String caption)
          Shows a notification message on the middle of the current page.
static void show(String caption, int type)
          Shows a notification message the current page.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_HUMANIZED_MESSAGE

public static final int TYPE_HUMANIZED_MESSAGE
See Also:
Constant Field Values

TYPE_WARNING_MESSAGE

public static final int TYPE_WARNING_MESSAGE
See Also:
Constant Field Values

TYPE_ERROR_MESSAGE

public static final int TYPE_ERROR_MESSAGE
See Also:
Constant Field Values

TYPE_TRAY_NOTIFICATION

public static final int TYPE_TRAY_NOTIFICATION
See Also:
Constant Field Values

POSITION_CENTERED

public static final int POSITION_CENTERED
See Also:
Constant Field Values

POSITION_CENTERED_TOP

public static final int POSITION_CENTERED_TOP
See Also:
Constant Field Values

POSITION_CENTERED_BOTTOM

public static final int POSITION_CENTERED_BOTTOM
See Also:
Constant Field Values

POSITION_TOP_LEFT

public static final int POSITION_TOP_LEFT
See Also:
Constant Field Values

POSITION_TOP_RIGHT

public static final int POSITION_TOP_RIGHT
See Also:
Constant Field Values

POSITION_BOTTOM_LEFT

public static final int POSITION_BOTTOM_LEFT
See Also:
Constant Field Values

POSITION_BOTTOM_RIGHT

public static final int POSITION_BOTTOM_RIGHT
See Also:
Constant Field Values

DELAY_FOREVER

public static final int DELAY_FOREVER
See Also:
Constant Field Values

DELAY_NONE

public static final int DELAY_NONE
See Also:
Constant Field Values
Constructor Detail

Notification

public Notification(String caption)
Creates a "humanized" notification message. The caption is rendered as plain text with HTML automatically escaped.

Parameters:
caption - The message to show

Notification

public Notification(String caption,
                    int type)
Creates a notification message of the specified type. The caption is rendered as plain text with HTML automatically escaped.

Parameters:
caption - The message to show
type - The type of message

Notification

public Notification(String caption,
                    String description)
Creates a "humanized" notification message with a bigger caption and smaller description. The caption and description are rendered as plain text with HTML automatically escaped.

Parameters:
caption - The message caption
description - The message description

Notification

public Notification(String caption,
                    String description,
                    int type)
Creates a notification message of the specified type, with a bigger caption and smaller description. The caption and description are rendered as plain text with HTML automatically escaped.

Parameters:
caption - The message caption
description - The message description
type - The type of message

Notification

public Notification(String caption,
                    String description,
                    int type,
                    boolean htmlContentAllowed)
Creates a notification message of the specified type, with a bigger caption and smaller description. Care should be taken to to avoid XSS vulnerabilities if html is allowed.

Parameters:
caption - The message caption
description - The message description
type - The type of message
htmlContentAllowed - Whether html in the caption and description should be displayed as html or as plain text
Method Detail

getCaption

public String getCaption()
Gets the caption part of the notification message.

Returns:
The message caption

setCaption

public void setCaption(String caption)
Sets the caption part of the notification message

Parameters:
caption - The message caption

getDescription

public String getDescription()
Gets the description part of the notification message.

Returns:
The message description.

setDescription

public void setDescription(String description)
Sets the description part of the notification message.

Parameters:
description -

getPosition

public int getPosition()
Gets the position of the notification message.

Returns:
The position

setPosition

public void setPosition(int position)
Sets the position of the notification message.

Parameters:
position - The desired notification position

getIcon

public Resource getIcon()
Gets the icon part of the notification message.

Returns:
The message icon

setIcon

public void setIcon(Resource icon)
Sets the icon part of the notification message.

Parameters:
icon - The desired message icon

getDelayMsec

public int getDelayMsec()
Gets the delay before the notification disappears.

Returns:
the delay in msec, -1 indicates the message has to be clicked.

setDelayMsec

public void setDelayMsec(int delayMsec)
Sets the delay before the notification disappears.

Parameters:
delayMsec - the desired delay in msec, -1 to require the user to click the message

setStyleName

public void setStyleName(String styleName)
Sets the style name for the notification message.

Parameters:
styleName - The desired style name.

getStyleName

public String getStyleName()
Gets the style name for the notification message.

Returns:

setHtmlContentAllowed

public void setHtmlContentAllowed(boolean htmlContentAllowed)
Sets whether html is allowed in the caption and description. If set to true, the texts are passed to the browser as html and the developer is responsible for ensuring no harmful html is used. If set to false, the texts are passed to the browser as plain text.

Parameters:
htmlContentAllowed - true if the texts are used as html, false if used as plain text

isHtmlContentAllowed

public boolean isHtmlContentAllowed()
Checks whether caption and description are interpreted as html or plain text.

Returns:
true if the texts are used as html, false if used as plain text
See Also:
setHtmlContentAllowed(boolean)

show

public void show(Page page)
Shows this notification on a Page.

Parameters:
page - The page on which the notification should be shown

show

public static void show(String caption)
Shows a notification message on the middle of the current page. The message automatically disappears ("humanized message"). The caption is rendered as plain text with HTML automatically escaped.

Parameters:
caption - The message
See Also:
Notification(String), show(Page)

show

public static void show(String caption,
                        int type)
Shows a notification message the current page. The position and behavior of the message depends on the type, which is one of the basic types defined in Notification, for instance Notification.TYPE_WARNING_MESSAGE. The caption is rendered as plain text with HTML automatically escaped.

Parameters:
caption - The message
type - The message type
See Also:
Notification(String, int), show(Page)


Copyright © 2000-2011 Vaadin Ltd. All Rights Reserved.