Class Notification
- All Implemented Interfaces:
AttachNotifier
,DetachNotifier
,HasComponents
,HasElement
,HasEnabled
,HasStyle
,HasTheme
,HasThemeVariant<NotificationVariant>
,Serializable
- Author:
- Vaadin Ltd
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
opened-changed
event is sent when the notification opened state changes.static enum
Enumeration of all available positions for notification component -
Constructor Summary
ConstructorDescriptionDefault constructor.Notification
(Component... components) Creates a notification with given components inside.Notification
(String text) Creates a Notification with the given String rendered as its HTML text, that does not close automatically.Notification
(String text, int duration) Creates a Notification with given String rendered as its HTML text and given Integer rendered as its duration.Notification
(String text, int duration, Notification.Position position) Creates a Notification with given text String, duration and position -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(Collection<Component> components) Adds the given components into this notification.addAttachListener
(ComponentEventListener<AttachEvent> listener) Adds a attach listener to this component.void
addComponentAtIndex
(int index, Component component) Adds the given component into this notification at the given index.addDetachListener
(ComponentEventListener<DetachEvent> listener) Adds a detach listener to this component.Adds a listener foropened-changed
events fired by the webcomponent.void
close()
Closes the notification.Gets the set of CSS class names used for this element.int
The duration in milliseconds to show the notification.Description copied from corresponding location in WebComponent:getStyle()
Gets the style instance for managing inline styles for the element of this component.boolean
isOpened()
True if the notification is currently displayed.protected void
onAttach
(AttachEvent attachEvent) Called when the component is attached to a UI.protected void
onDetach
(DetachEvent detachEvent) Called when the component is detached from a UI.void
open()
Opens the notification.void
setClassName
(String className) Sets the CSS class names of the notification overlay element.void
setDuration
(int duration) The duration in milliseconds to show the notification.void
setOpened
(boolean opened) Opens or closes the notification.void
setPosition
(Notification.Position position) Set position of the notification.void
Set the text of the notification with given Stringstatic Notification
Shows a notification in the current page with given text.static Notification
show
(String text, int duration, Notification.Position position) Shows a notification in the current page with given text, duration and position.Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.vaadin.flow.component.HasComponents
add, add, addComponentAsFirst, remove, remove, removeAll
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, hasClassName, removeClassName, removeClassNames, setClassName
Methods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
Methods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant
addThemeVariants, removeThemeVariants
-
Constructor Details
-
Notification
public Notification()Default constructor. Create an empty notification with component support and non-auto-closingNote: To mix text and child components in notification that also supports child components, use the
Text
component for the textual parts. -
Notification
Creates a Notification with the given String rendered as its HTML text, that does not close automatically.- Parameters:
text
- the text of the Notification
-
Notification
Creates a Notification with given String rendered as its HTML text and given Integer rendered as its duration.Set to
0
or a negative number to disable the notification auto-closing.- Parameters:
text
- the text of the Notificationduration
- the duration in milliseconds to show the notification
-
Notification
Creates a Notification with given text String, duration and positionSet to
0
or a negative number to disable the notification auto-closing.- Parameters:
text
- the text of the notificationduration
- the duration in milliseconds to show the notificationposition
- the position of the notification. Valid enumerate values are TOP_STRETCH, TOP_START, TOP_CENTER, TOP_END, MIDDLE, BOTTOM_START, BOTTOM_CENTER, BOTTOM_END, BOTTOM_STRETCH
-
Notification
Creates a notification with given components inside.Note: To mix text and child components in a component that also supports child components, use the
Text
component for the textual parts.- Parameters:
components
- the components inside the notification- See Also:
-
-
Method Details
-
show
Shows a notification in the current page with given text, duration and position.- Parameters:
text
- the text of the Notificationduration
- the duration in milliseconds to show the notificationposition
- the position of the notification. Valid enumerate values are TOP_STRETCH, TOP_START, TOP_CENTER, TOP_END, MIDDLE, BOTTOM_START, BOTTOM_CENTER, BOTTOM_END, BOTTOM_STRETCH- Returns:
- the notification
-
show
Shows a notification in the current page with given text.This is the convenience method for
show(String, int, Position)
which uses default web-component values for duration (which is 5000 ms) and position (Position.BOTTOM_START).- Parameters:
text
- the text of the Notification- Returns:
- the notification
-
setText
Set the text of the notification with given StringNOTE: When mixing this method with
Notification()
andNotification(Component...)
. Method will remove all the components from the notification.- Parameters:
text
- the text of the Notification
-
setPosition
Set position of the notification.- Parameters:
position
- the position of the notification. Valid enumerate values areTOP_STRETCH, TOP_START, TOP_CENTER, TOP_END, MIDDLE, BOTTOM_START, BOTTOM_CENTER, BOTTOM_END, BOTTOM_STRETCH
, notnull
-
getPosition
Description copied from corresponding location in WebComponent:
Alignment of the notification in the viewport Valid values are
top-stretch|top-start|top-center|top-end|middle|bottom-start|bottom-center|bottom-end|bottom-stretch
This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
The default position value is Position.BOTTOM_START.
- Returns:
- the
Notification.Position
property from the webcomponent
-
open
public void open()Opens the notification. -
close
public void close()Closes the notification.Note: This method also removes the notification component from the DOM after closing it, unless you have added the component manually.
-
add
Adds the given components into this notification.The elements in the DOM will not be children of the
<vaadin-notification>
element, but will be inserted into an overlay that is attached into the<body>
.NOTE: When mixing this method with
Notification(String)
,Notification(String, int)
andNotification(String, int, Position)
method will remove the text content.- Specified by:
add
in interfaceHasComponents
- Parameters:
components
- the components to add
-
addComponentAtIndex
Adds the given component into this notification at the given index.The element in the DOM will not be child of the
<vaadin-notification>
element, but will be inserted into an overlay that is attached into the<body>
.NOTE: When mixing this method with
Notification(String)
,Notification(String, int)
andNotification(String, int, Position)
method will remove the text content.- Specified by:
addComponentAtIndex
in interfaceHasComponents
- Parameters:
index
- the index, where the component will be added.component
- the component to add
-
setOpened
public void setOpened(boolean opened) Opens or closes the notification.Note: You don't need to add the component anywhere before opening it. Since
<vaadin-notification>
's location in the DOM doesn't really matter, opening a notification will automatically add it to the<body>
if it's not yet attached anywhere.- Parameters:
opened
-true
to open the notification,false
to close it
-
isOpened
True if the notification is currently displayed.This property is synchronized automatically from client side when an
opened-changed
event happens.- Returns:
- the
opened
property from the webcomponent
-
addOpenedChangeListener
public Registration addOpenedChangeListener(ComponentEventListener<Notification.OpenedChangeEvent> listener) Adds a listener foropened-changed
events fired by the webcomponent.- Parameters:
listener
- the listener- Returns:
- a
Registration
for removing the event listener
-
setDuration
public void setDuration(int duration) The duration in milliseconds to show the notification. Set to0
or a negative number to disable the notification auto-closing.- Parameters:
duration
- the value to set
-
getDuration
public int getDuration()The duration in milliseconds to show the notification. Set to
0
or a negative number to disable the notification auto-closing.This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
- Returns:
- the
duration
property from the webcomponent
-
addAttachListener
Adds a attach listener to this component.Note: To listen for opening the notification, you should use
addOpenedChangeListener(ComponentEventListener)
.- Specified by:
addAttachListener
in interfaceAttachNotifier
- Parameters:
listener
- the listener to add, notnull
- Returns:
- a handle that can be used for removing the listener
-
addDetachListener
Adds a detach listener to this component.Note: To listen for closing the notification, you should use
addOpenedChangeListener(ComponentEventListener)
, as the component is not necessarily removed from the DOM when closing.- Specified by:
addDetachListener
in interfaceDetachNotifier
- Parameters:
listener
- the listener to add, notnull
- Returns:
- a handle that can be used for removing the listener
-
onAttach
Description copied from class:Component
Called when the component is attached to a UI.The default implementation does nothing.
This method is invoked before the
AttachEvent
is fired for the component. -
onDetach
Description copied from class:Component
Called when the component is detached from a UI.The default implementation does nothing.
This method is invoked before the
DetachEvent
is fired for the component. -
setClassName
Sets the CSS class names of the notification overlay element. This method overwrites any previous set class names.- Specified by:
setClassName
in interfaceHasStyle
- Parameters:
className
- a space-separated string of class names to set, ornull
to remove all class names
-
getClassNames
Description copied from interface:HasStyle
Gets the set of CSS class names used for this element. The returned set can be modified to add or remove class names. The contents of the set is also reflected in the value of theclass
attribute.Despite the name implying a list being returned, the return type is actually a
Set
since the in-browser return value behaves like aSet
in Java.- Specified by:
getClassNames
in interfaceHasStyle
- Returns:
- a list of class names, never
null
- See Also:
-
getStyle
Description copied from interface:HasStyle
Gets the style instance for managing inline styles for the element of this component.- Specified by:
getStyle
in interfaceHasStyle
- Returns:
- the style object for the element, not
null
- Throws:
UnsupportedOperationException
- Notification does not support adding styles to card element
-