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,HasStyle,HasTheme,Serializable
@JsModule("./flow-component-renderer.js") @JsModule("./notificationConnector.js") public class Notification extends GeneratedVaadinNotification<Notification> implements HasComponents, HasTheme, HasStyle
Notifications 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(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(Component... components)Adds the given components into this notification.RegistrationaddAttachListener(ComponentEventListener<AttachEvent> listener)Adds a attach listener to this component.voidaddComponentAtIndex(int index, Component component)Adds the given component into this notification at the given index.RegistrationaddDetachListener(ComponentEventListener<DetachEvent> listener)Adds a detach listener to this component.RegistrationaddOpenedChangeListener(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<Component>getChildren()Gets the child components of this component.intgetDuration()Description copied from corresponding location in WebComponent:Notification.PositiongetPosition()Description copied from corresponding location in WebComponent:StylegetStyle()Gets the style instance for managing inline styles for the element of this component.booleanisOpened()Description copied from corresponding location in WebComponent:protected voidonAttach(AttachEvent attachEvent)Called when the component is attached to a UI.voidopen()Opens the notification.voidremove(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
-
Methods inherited from interface com.vaadin.flow.component.HasComponents
add, addComponentAsFirst
-
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, getClassNames, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
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-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(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(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 interfaceHasComponents- Parameters:
components- the components to add
-
remove
public void remove(Component... components)
Remove the given components from this notification.- Specified by:
removein 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:
addComponentAtIndexin 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:
removeAllin interfaceHasComponents
-
getChildren
public Stream<Component> getChildren()
Description copied from class:ComponentGets the child components of this component.The default implementation finds child components by traversing each child
Elementtree.If the component is injected to a PolymerTemplate using the
@Idannotation the getChildren method will only return children added from the server side and will not return any children declared in the template file.- Overrides:
getChildrenin classComponent- Returns:
- the child components of this component
- See Also:
Id
-
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 Registration addOpenedChangeListener(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 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:
addAttachListenerin 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:
addDetachListenerin 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
-
onAttach
protected void onAttach(AttachEvent attachEvent)
Description copied from class:ComponentCalled when the component is attached to a UI.The default implementation does nothing.
This method is invoked before the
AttachEventis fired for the component.
-
getStyle
public Style getStyle()
Description copied from interface:HasStyleGets the style instance for managing inline styles for the element of this component.- Specified by:
getStylein interfaceHasStyle- Returns:
- the style object for the element, not
null - Throws:
UnsupportedOperationException- Notification does not support adding styles to card element
-
-