public class Notify
extends java.lang.Object
modal notification
dialogs that can lower end
user productivity. Messages may be shown at a particular location, specified either with viewport-relative coordinates,
or as an edge or center location relative to the viewport or a canvas. Messages can be configured to appear and
disappear instantly, by sliding into (or out of) view, or by fading in (or out). One or more actions
can be provided when addMessage()
is called to display a message. They will be
rendered as links on which to click to execute the action.
The behavior and appearance of messages are configured
per NotifyType
, which is simply a string that identifies that message group, similar to
log category. By calling configureMessages()
with
the NotifyType
, it can be assigned a NotifySettings
configuration to control message animation, placement, and the the Label
used to
render each message, allowing styling and autofit behavior to be configured.
Messages of the same
NotifyType
may be stacked to provide a visible history, with a configurable stacking direction and maximum
stacking depth. Details on how to configure messages are provided in the documentation for NotifySettings
.
Messages for different NotifyType
s are stacked
separately and animated by independent Framework pipelines. It's up to you to configure the placement of supported
NotifyType
s in your app so that they don't overlap, as the Framework doesn't manage it. For example,
separate NotifyType
s could be assigned separate screen edges, or assigned a different NotifySettings.positionCanvas
.
To dismiss a
message manually before its scheduled duration expires, you may call dismissMessage()
with a NotifyType
(to dismiss
all such messages) or an ID previously returned by addMessage()
(to dismiss that single message).
Warnings and Errors
Each notification may be assigned a
messagePriority
in the settings passed to
addMessage()
. By default, all NotifyType
s are
configured to have priority MESSAGE
, except for "error" and
"warn" NotifyType
s, which are configured with priority ERROR
and WARN
,
respectively.
The messagePriority
determines the default styling of a message, and which message to remove if a new message is sent while the message
stack is already at its limit. We recommended applying a messagePriority
as the best approach for showing
pre-styled warnings and errors, since that allows you to interleave them with ordinary messages in a single
NotifyType
.
Alternatively, you can display pre-styled warnings and errors by calling addMessage()
with the separate NotifyType
s "warning"
and "error", respectively, but then you must take care to assign each NotifyType
used to a separate screen location
to avoid one rendering on top of the other.
Viewport Considerations
Messages are edge or corner-aligned
based on the viewport width
and viewport height
of the current page rather than screen, so you may need
to scroll to see the targeted corner or edge. Note that widgets placed offscreen below or to the right of a page may
cause the browser to report a larger viewport, and prevent messages from being visible, even if no scrollbars are
present. If you need to stage widgets offscreen for measurement or other reasons, place them above or to the left.
Modal Windows and Click Masks
Messages are always shown above all other widgets, including modal windows
and click masks
. This is because it's expected that messages are "out of band" and logically indepedent of the widget
hierarchy being shown. We apply this layering policy even for windows and widgets created by NotifyAction
s. If there may a scenario where a message can block a window created by
an action, set NotifySettings.canDismiss
to true
so that an unobstructed view of the underlying widgets can be restored.
In the linked sample, note how we take care to reuse the existing modal window, if any, if the "Launch..." link is clicked, so that repeated clicks never stack windows over each other.
com.smartgwt.client.util.isc#say
,
com.smartgwt.client.util.isc#confirm
Modifier and Type | Field and Description |
---|---|
static int |
ERROR
Highest priority.
|
static int |
MESSAGE
Third-highest priority.
|
static int |
WARN
Second-highest priority.
|
Constructor and Description |
---|
Notify() |
Modifier and Type | Method and Description |
---|---|
static MessageID |
addMessage(java.lang.String contents)
Displays a new message, subject to the
stored
configuration for the passed notifyType , overridden by any passed settings . |
static MessageID |
addMessage(java.lang.String contents,
NotifyAction... actions) |
static MessageID |
addMessage(java.lang.String contents,
NotifyAction[] actions,
java.lang.String notifyType) |
static MessageID |
addMessage(java.lang.String contents,
NotifyAction[] actions,
java.lang.String notifyType,
NotifySettings settings)
Displays a new message, subject to the
stored
configuration for the passed notifyType , overridden by any passed settings . |
static boolean |
canDismissMessage(MessageID messageID)
Can the message corresponding to the
messageID be dismissed? Returns false if the message is no longer
being shown. |
static void |
configureDefaultSettings(NotifySettings settings)
Changes the default settings that are applied when you create a new
NotifyType with
configureMessages() . |
static void |
configureMessages(java.lang.String notifyType,
NotifySettings settings)
Sets the default
NotifySettings for the specified NotifyType . |
static void |
dismissMessage(MessageID messageID)
Dismisses one or more messages currently being shown, subject to the existing settings for their
NotifyType . |
static void |
dismissMessage(java.lang.String messageID)
Dismisses one or more messages currently being shown, subject to the existing settings for their
NotifyType . |
static boolean |
messageHasActions(MessageID messageID) |
static void |
setMessageActions(MessageID messageID,
NotifyAction... actions)
Updates the actions of the message from those, if any, passed originally to
addMessage() , while preserving any existing contents . |
static void |
setMessageContents(MessageID messageID,
java.lang.String contents)
Updates the contents of the message from what was passed originally to
addMessage() , while preserving any existing actions . |
public static final int ERROR
NotifyType
: "error".public static final int WARN
NotifyType
: "warn".public static final int MESSAGE
NotifyType
s other than "error" and "warn".public static MessageID addMessage(java.lang.String contents)
stored
configuration
for the passed notifyType
, overridden by any passed settings
. Returns an opaque
MessageID
that can be passed to dismissMessage()
to clear it. Note that an empty string may be passed for contents
if
actions
have been provided, so you may have the message consist only of your specified actions.
Most
users should do all configuration up front via a call to configureMessages()
. The settings
argument in
this method is provided to allow adjustment of properties that affect only one message, such as autoFitWidth
, styleName
, or labelProperties
. Making changes to stacking
-related properties via this argument isn't supported, unless
specifically documented on the property.
contents
- message to be displayed.
See HTMLString
com.smartgwt.client.util.isc#say
,
com.smartgwt.client.util.isc#confirm
,
com.smartgwt.client.util.isc#notify
,
HTMLString
public static MessageID addMessage(java.lang.String contents, NotifyAction... actions)
addMessage(java.lang.String)
public static MessageID addMessage(java.lang.String contents, NotifyAction[] actions, java.lang.String notifyType)
addMessage(java.lang.String)
public static MessageID addMessage(java.lang.String contents, NotifyAction[] actions, java.lang.String notifyType, NotifySettings settings)
stored
configuration
for the passed notifyType
, overridden by any passed settings
. Returns an opaque
MessageID
that can be passed to dismissMessage()
to clear it. Note that an empty string may be passed for contents
if
actions
have been provided, so you may have the message consist only of your specified actions.
Most
users should do all configuration up front via a call to configureMessages()
. The settings
argument in
this method is provided to allow adjustment of properties that affect only one message, such as autoFitWidth
, styleName
, or labelProperties
. Making changes to stacking
-related properties via this argument isn't supported, unless
specifically documented on the property.
contents
- message to be displayed.
See HTMLString
actions
- actions (if any) for this messagenotifyType
- category of message; default "message".
See NotifyType
settings
- display and behavior settings for this message that override the
configured
settings for the notifyType
com.smartgwt.client.util.isc#say
,
com.smartgwt.client.util.isc#confirm
,
com.smartgwt.client.util.isc#notify
public static boolean canDismissMessage(MessageID messageID)
messageID
be dismissed? Returns false if the message is no longer
being shown. The messageID
must have been previously returned by addMessage()
.messageID
- message identifier to dismissdismissMessage(com.smartgwt.client.widgets.notify.MessageID)
public static void configureDefaultSettings(NotifySettings settings)
NotifyType
with
configureMessages()
. If you want to change the
defaults for the built-in NotifyTypes "message", "warn", and "error", with this method, it must be called before the
first call to configureMessages()
or addMessage()
. Once a NotifyType has been created, you must use
configureMessages()
to change its settings. Note that for defaults that depend on priority (and thus differ between the built-in NotifyTypes), this method only sets the defaults for the "message" NotifyType.
settings
- changes to NotifyType defaultsconfigureMessages(java.lang.String, com.smartgwt.client.widgets.notify.NotifySettings)
public static void configureMessages(java.lang.String notifyType, NotifySettings settings)
NotifySettings
for the specified NotifyType
. This may be overridden by passing settings to addMessage()
when the message is shown, but changing stacking
-related properties via addMessage()
isn't supported, By default, the NotifyType
s "message", "warn", and "error" are predefined, each with their own NotifySettings
with different styleName
s. When configuring a new (non-predefined)
NotifyType with this method, any NotifySettings
left unset will default to
those for NotifyType "message".
notifyType
- category of message; null defaults to "message".
See NotifyType
settings
- settings to store for the notifyType
configureDefaultSettings(com.smartgwt.client.widgets.notify.NotifySettings)
public static void dismissMessage(MessageID messageID)
NotifyType
. You may either pass the opaque message identifier returned from the call to
addMessage()
to dismiss a single message, or a
NotifyType
to dismiss all such messages.messageID
- message identifier or category to dismissNotifySettings.getDuration()
,
NotifyAction.getWholeMessage()
public static void dismissMessage(java.lang.String messageID)
NotifyType
. You may either pass the opaque message identifier returned from the call to
addMessage()
to dismiss a single message, or a
NotifyType
to dismiss all such messages.messageID
- message identifier or category to dismissNotifySettings.getDuration()
,
NotifyAction.getWholeMessage()
,
NotifyType
public static boolean messageHasActions(MessageID messageID)
messageID
- message identifier to checkaddMessage(java.lang.String)
,
setMessageActions(com.smartgwt.client.widgets.notify.MessageID, com.smartgwt.client.widgets.notify.NotifyAction...)
public static void setMessageActions(MessageID messageID, NotifyAction... actions)
addMessage()
, while preserving any existing contents
. See setMessageContents()
for further guidance and animation
details.
messageID
- message identifier from addMessage()
actions
- updated actions for this messagepublic static void setMessageContents(MessageID messageID, java.lang.String contents)
addMessage()
, while preserving any existing actions
. The purpose of this method is to support messages that contain timer countdowns or other data that perhaps need refreshing during display. If you find yourself replacing the entire content with something new, you should probably just add it as a new message.
Note that this method has
minimal animation support. The change in message content and corresponding resizing are instant, but the repositioning
of the message or stack (if stacked) to keep your requested alignment
is controlled by NotifySettings.repositionMethod
, allowing slide
animation. However, that setting is ignored and the repositioning is instant if you've chosen viewport alignment
to a border or corner along the
bottom or right
viewport edge, or if an animation
is already in progress, in which case the instant repositioning will happen after it completes.
messageID
- message identifier from addMessage()
contents
- updated message.
See HTMLString