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:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.HasComponents,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasEnabled,com.vaadin.flow.component.HasStyle,com.vaadin.flow.component.HasTheme,Serializable
@JsModule("./flow-component-renderer.js") @JsModule("./notificationConnector.js") public class Notification extends GeneratedVaadinNotification<Notification> implements com.vaadin.flow.component.HasComponents, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.HasStyleNotifications are used to provide feedback to the user. They communicate information about activities, processes, and events in the application.- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classNotification.PositionEnumeration 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 Description Notification()Default constructor.Notification(com.vaadin.flow.component.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 Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(com.vaadin.flow.component.Component... components)Adds the given components into this notification.com.vaadin.flow.shared.RegistrationaddAttachListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.AttachEvent> listener)voidaddComponentAtIndex(int index, com.vaadin.flow.component.Component component)Adds the given component into this notification at the given index.com.vaadin.flow.shared.RegistrationaddDetachListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.DetachEvent> listener)com.vaadin.flow.shared.RegistrationaddOpenedChangeListener(com.vaadin.flow.component.ComponentEventListener<GeneratedVaadinNotification.OpenedChangeEvent<Notification>> listener)Adds a listener foropened-changedevents fired by the webcomponent.voidaddThemeVariants(NotificationVariant... variants)Adds theme variants to the component.voidclose()Closes the notification.Stream<com.vaadin.flow.component.Component>getChildren()intgetDuration()Description copied from corresponding location in WebComponent:Notification.PositiongetPosition()Description copied from corresponding location in WebComponent:com.vaadin.flow.dom.StylegetStyle()booleanisOpened()Description copied from corresponding location in WebComponent:protected voidonAttach(com.vaadin.flow.component.AttachEvent attachEvent)voidopen()Opens the notification.voidremove(com.vaadin.flow.component.Component... components)Remove the given components from this notification.voidremoveAll()Remove all the components from this notification.voidremoveThemeVariants(NotificationVariant... variants)Removes theme variants from the component.voidsetDuration(int duration)Description copied from corresponding location in WebComponent:voidsetOpened(boolean opened)Opens or closes the notification.voidsetPosition(Notification.Position position)Set position of the notification.voidsetText(String text)Set the text of the notification with given Stringstatic Notificationshow(String text)Shows a notification in the current page with given text.static Notificationshow(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, setDuration, setPosition
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, scrollIntoView, set, setElement, setId, setVisible
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Constructor Detail
-
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
Textcomponent 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
0or 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 positionSet to
0or 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(com.vaadin.flow.component.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
Textcomponent for the textual parts.- Parameters:
components- the components inside the notification- See Also:
add(Component...)
-
-
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_STRETCH- Returns:
- 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 Notification- Returns:
- the notification
-
setText
public void setText(String text)
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
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-stretchThis 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.Positionproperty from the webcomponent
-
open
public void open()
Opens the notification.- Overrides:
openin 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:
closein classGeneratedVaadinNotification<Notification>
-
add
public void add(com.vaadin.flow.component.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:
addin interfacecom.vaadin.flow.component.HasComponents- Parameters:
components- the components to add
-
remove
public void remove(com.vaadin.flow.component.Component... components)
Remove the given components from this notification.- Specified by:
removein interfacecom.vaadin.flow.component.HasComponents- Parameters:
components- the components to remove
-
addComponentAtIndex
public void addComponentAtIndex(int index, com.vaadin.flow.component.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:
addComponentAtIndexin interfacecom.vaadin.flow.component.HasComponents- 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:
removeAllin interfacecom.vaadin.flow.component.HasComponents
-
getChildren
public Stream<com.vaadin.flow.component.Component> getChildren()
- Overrides:
getChildrenin classcom.vaadin.flow.component.Component
-
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:
setOpenedin classGeneratedVaadinNotification<Notification>- Parameters:
opened-trueto open the notification,falseto 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
openedproperty from the webcomponent
-
addOpenedChangeListener
public com.vaadin.flow.shared.Registration addOpenedChangeListener(com.vaadin.flow.component.ComponentEventListener<GeneratedVaadinNotification.OpenedChangeEvent<Notification>> listener)
Description copied from class:GeneratedVaadinNotificationAdds a listener foropened-changedevents fired by the webcomponent.- Overrides:
addOpenedChangeListenerin classGeneratedVaadinNotification<Notification>- Parameters:
listener- the listener- Returns:
- a
Registrationfor 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
0or 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
0or 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
durationproperty from the webcomponent
-
addAttachListener
public com.vaadin.flow.shared.Registration addAttachListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.AttachEvent> listener)
Note: To listen for opening the notification, you should use
addOpenedChangeListener(ComponentEventListener).- Specified by:
addAttachListenerin interfacecom.vaadin.flow.component.AttachNotifier
-
addDetachListener
public com.vaadin.flow.shared.Registration addDetachListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.DetachEvent> listener)
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:
addDetachListenerin interfacecom.vaadin.flow.component.DetachNotifier
-
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
-
onAttach
protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
- Overrides:
onAttachin classcom.vaadin.flow.component.Component
-
getStyle
public com.vaadin.flow.dom.Style getStyle()
- Specified by:
getStylein interfacecom.vaadin.flow.component.HasStyle- Throws:
UnsupportedOperationException- Notification does not support adding styles to card element
-
-