com.vaadin.flow.component.notification.
Class Notification
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.notification.GeneratedVaadinNotification<Notification>
-
- com.vaadin.flow.component.notification.Notification
-
All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasComponents, HasElement, HasEnabled, HasTheme, Serializable
@HtmlImport(value="flow-component-renderer.html") @JsModule(value="./flow-component-renderer.js") public class Notification extends GeneratedVaadinNotification<Notification> implements HasComponents, HasTheme
Server-side component for the
vaadin-notification
element.Author:
Vaadin Ltd
See Also:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static class
Notification.Position
Enumeration of all available positions for notification component
-
Nested classes/interfaces inherited from class com.vaadin.flow.component.notification.GeneratedVaadinNotification
GeneratedVaadinNotification.OpenedChangeEvent<R extends GeneratedVaadinNotification<R>>
-
-
Constructor Summary
Constructors Constructor and Description Notification()
Default 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
All Methods Modifier and Type Method and Description void
add(Component... components)
Adds the given components into this notification.
Registration
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.
Registration
addDetachListener(ComponentEventListener<DetachEvent> listener)
Adds a detach listener to this component.
Registration
addOpenedChangeListener(ComponentEventListener<GeneratedVaadinNotification.OpenedChangeEvent<Notification>> listener)
Adds a listener for
opened-changed
events fired by the webcomponent.void
addThemeVariants(NotificationVariant... variants)
Adds theme variants to the component.
void
close()
Closes the notification.
Stream<Component>
getChildren()
Gets the child components of this component.
int
getDuration()
Description copied from corresponding location in WebComponent:
Notification.Position
getPosition()
Description copied from corresponding location in WebComponent:
boolean
isOpened()
Description copied from corresponding location in WebComponent:
void
open()
Opens the notification.
void
remove(Component... components)
Remove the given components from this notification.
void
removeAll()
Remove all the components from this notification.
void
removeThemeVariants(NotificationVariant... variants)
Removes theme variants from the component.
void
setDuration(int duration)
Description copied from corresponding location in WebComponent:
void
setOpened(boolean opened)
Opens or closes the notification.
void
setPosition(Notification.Position position)
Set position of the notification.
void
setText(String text)
Set the text of the notification with given String
static Notification
show(String text)
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.notification.GeneratedVaadinNotification
getDurationDouble, getPositionString, isOpenedBoolean, render, setDuration, setPosition
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getUI, hasListener, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, 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, addComponentAsFirst
-
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
-
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
-
Methods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
-
-
-
-
Constructor Detail
-
Notification
public Notification()
Default constructor. Create an empty notification with component support and non-auto-closing
Note: To mix text and child components in notification that also supports child components, use the
Text
component for the textual parts.
-
Notification
public Notification(String text)
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
public Notification(String text, int duration)
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
public Notification(String text, int duration, Notification.Position position)
Creates a Notification with given text String, duration and position
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 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
public Notification(Component... components)
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 notificationSee Also:
-
-
Method Detail
-
show
public static Notification show(String text, int duration, Notification.Position position)
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_STRETCHReturns:
the notification
-
show
public static Notification show(String text)
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 NotificationReturns:
the notification
-
setText
public void setText(String text)
Set the text of the notification with given String
NOTE: 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
public void setPosition(Notification.Position position)
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
public Notification.Position 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.
Overrides:
open
in classGeneratedVaadinNotification<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.
Overrides:
close
in classGeneratedVaadinNotification<Notification>
-
add
public void add(Component... components)
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
-
remove
public void remove(Component... components)
Remove the given components from this notification.
Specified by:
remove
in interfaceHasComponents
Parameters:
components
- the components to remove
-
addComponentAtIndex
public void addComponentAtIndex(int index, Component component)
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
-
removeAll
public void removeAll()
Remove all the components from this notification.
Specified by:
removeAll
in interfaceHasComponents
-
getChildren
public Stream<Component> getChildren()
Description copied from class:
Component
Gets the child components of this component.
The default implementation finds child components by traversing each child
Element
tree.If the component is injected to a PolymerTemplate using the
@Id
annotation the getChildren method will only return children added from the server side and will not return any children declared in the template file.Overrides:
getChildren
in classComponent
Returns:
the child components of this component
See Also:
-
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.Overrides:
setOpened
in classGeneratedVaadinNotification<Notification>
Parameters:
opened
-true
to open the notification,false
to close it
-
isOpened
public boolean isOpened()
Description copied from corresponding location in WebComponent:
True if the notification is currently displayed.
This property is synchronized automatically from client side when a 'opened-changed' event happens.
Returns:
the
opened
property from the webcomponent
-
addOpenedChangeListener
public Registration addOpenedChangeListener(ComponentEventListener<GeneratedVaadinNotification.OpenedChangeEvent<Notification>> listener)
Description copied from class:
GeneratedVaadinNotification
Adds a listener for
opened-changed
events fired by the webcomponent.Overrides:
addOpenedChangeListener
in classGeneratedVaadinNotification<Notification>
Parameters:
listener
- the listenerReturns:
a
Registration
for removing the event listener
-
setDuration
public void setDuration(int duration)
Description copied from corresponding location in WebComponent:
The duration in milliseconds to show the notification. Set to
0
or a negative number to disable the notification auto-closing.Parameters:
duration
- the value to set
-
getDuration
public int getDuration()
Description copied from corresponding location in WebComponent:
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
public Registration addAttachListener(ComponentEventListener<AttachEvent> listener)
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
public Registration addDetachListener(ComponentEventListener<DetachEvent> listener)
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
-
addThemeVariants
public void addThemeVariants(NotificationVariant... variants)
Adds theme variants to the component.
Parameters:
variants
- theme variants to add
-
removeThemeVariants
public void removeThemeVariants(NotificationVariant... variants)
Removes theme variants from the component.
Parameters:
variants
- theme variants to remove
-
-