public class Notification extends AbstractExtension
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.
Modifier and Type | Class and Description |
---|---|
static class |
Notification.CloseEvent
Event fired when a notification is closed.
|
static interface |
Notification.CloseListener
An interface used for listening to Notification close events.
|
static class |
Notification.Type |
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
Modifier and Type | Field and Description |
---|---|
static int |
DELAY_FOREVER |
static int |
DELAY_NONE |
static Position |
POSITION_BOTTOM_LEFT
Deprecated.
|
static Position |
POSITION_BOTTOM_RIGHT
Deprecated.
|
static Position |
POSITION_CENTERED
Deprecated.
|
static Position |
POSITION_CENTERED_BOTTOM
Deprecated.
|
static Position |
POSITION_CENTERED_TOP
Deprecated.
|
static Position |
POSITION_TOP_LEFT
Deprecated.
|
static Position |
POSITION_TOP_RIGHT
Deprecated.
|
static Notification.Type |
TYPE_ERROR_MESSAGE
Deprecated.
|
static Notification.Type |
TYPE_HUMANIZED_MESSAGE
Deprecated.
|
static Notification.Type |
TYPE_TRAY_NOTIFICATION
Deprecated.
|
static Notification.Type |
TYPE_WARNING_MESSAGE
Deprecated.
|
Constructor and Description |
---|
Notification(String caption)
Creates a "humanized" notification message.
|
Notification(String caption,
Notification.Type 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,
Notification.Type type)
Creates a notification message of the specified type, with a bigger
caption and smaller description.
|
Notification(String caption,
String description,
Notification.Type type,
boolean htmlContentAllowed)
Creates a notification message of the specified type, with a bigger
caption and smaller description.
|
Modifier and Type | Method and Description |
---|---|
Registration |
addCloseListener(Notification.CloseListener listener)
Adds a CloseListener to the Notification.
|
void |
close()
Closes (hides) the notification.
|
protected void |
close(boolean userOriginated)
Closes (hides) the notification.
|
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.
|
Position |
getPosition()
Gets the position of the notification message.
|
protected NotificationState |
getState()
Returns the shared state for this connector.
|
protected NotificationState |
getState(boolean markAsDirty)
Returns the shared state for this connector.
|
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(Position 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 Notification |
show(String caption)
Shows a notification message on the middle of the current page.
|
static Notification |
show(String caption,
Notification.Type type)
Shows a notification message the current page.
|
static Notification |
show(String caption,
String description,
Notification.Type type)
Shows a notification message the current page.
|
extend, getParent, getSupportedParentType, remove, setParent
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addListener, addListener, addListener, addMethodInvocationToQueue, attach, beforeClientResponse, createState, detach, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isConnectorEnabled, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
addAttachListener, addDetachListener, attach, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, getUI, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
getConnectorId
@Deprecated public static final Notification.Type TYPE_HUMANIZED_MESSAGE
@Deprecated public static final Notification.Type TYPE_WARNING_MESSAGE
@Deprecated public static final Notification.Type TYPE_ERROR_MESSAGE
@Deprecated public static final Notification.Type TYPE_TRAY_NOTIFICATION
@Deprecated public static final Position POSITION_CENTERED
@Deprecated public static final Position POSITION_CENTERED_TOP
@Deprecated public static final Position POSITION_CENTERED_BOTTOM
@Deprecated public static final Position POSITION_TOP_LEFT
@Deprecated public static final Position POSITION_TOP_RIGHT
@Deprecated public static final Position POSITION_BOTTOM_LEFT
@Deprecated public static final Position POSITION_BOTTOM_RIGHT
public static final int DELAY_FOREVER
public static final int DELAY_NONE
public Notification(String caption)
caption
- The message to showpublic Notification(String caption, Notification.Type type)
caption
- The message to showtype
- The type of messagepublic Notification(String caption, String description)
caption
- The message captiondescription
- The message descriptionpublic Notification(String caption, String description, Notification.Type type)
caption
- The message captiondescription
- The message descriptiontype
- The type of messagepublic Notification(String caption, String description, Notification.Type type, boolean htmlContentAllowed)
caption
- The message captiondescription
- The message descriptiontype
- The type of messagehtmlContentAllowed
- Whether html in the caption and description should be
displayed as html or as plain textpublic String getCaption()
public void setCaption(String caption)
caption
- The message captionpublic String getDescription()
public void setDescription(String description)
description
- The message descriptionpublic Position getPosition()
public void setPosition(Position position)
position
- The desired notification position, not null
public Resource getIcon()
public void setIcon(Resource icon)
icon
- The desired message iconpublic int getDelayMsec()
public void setDelayMsec(int delayMsec)
delayMsec
- the desired delay in milliseconds, -1 to
require the user to click the messagepublic void setStyleName(String styleName)
styleName
- The desired style namepublic String getStyleName()
public void setHtmlContentAllowed(boolean htmlContentAllowed)
htmlContentAllowed
- true if the texts are used as html, false if used as plain
textpublic boolean isHtmlContentAllowed()
true
if the texts are used as HTML, false
if used
as plain textsetHtmlContentAllowed(boolean)
public void show(Page page)
page
- The page on which the notification should be shownpublic void close()
If the notification is not shown, does nothing.
protected void close(boolean userOriginated)
If the notification is not shown, does nothing.
userOriginated
- true
if the notification was closed because the
user clicked on it, false
if the notification was
closed from the serverprotected NotificationState getState()
AbstractClientConnector
As a side effect, marks the connector dirty so any changes done to the
state will be sent to the client. Use getState(false)
to avoid
marking the connector as dirty.
getState
in class AbstractClientConnector
protected NotificationState getState(boolean markAsDirty)
AbstractClientConnector
getState
in class AbstractClientConnector
markAsDirty
- true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()
public static Notification show(String caption)
caption
- The messageNotification(String)
,
show(Page)
public static Notification show(String caption, Notification.Type type)
Notification
, for instance
Notification.Type.WARNING_MESSAGE
.
The caption is rendered as plain text with HTML automatically escaped.caption
- The messagetype
- The message typeNotification(String, int)
,
show(Page)
public static Notification show(String caption, String description, Notification.Type type)
Notification
, for instance
Notification.TYPE_WARNING_MESSAGE.
The caption is rendered as plain text with HTML automatically escaped.caption
- The messagedescription
- The message descriptiontype
- The message typeNotification(String, Type)
,
show(Page)
public Registration addCloseListener(Notification.CloseListener listener)
listener
- the CloseListener to add, not null
Copyright © 2022 Vaadin Ltd. All rights reserved.