Class 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.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
    • 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
      void add​(com.vaadin.flow.component.Component... components)
      Adds the given components into this notification.
      com.vaadin.flow.shared.Registration addAttachListener​(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.AttachEvent> listener)
      void addComponentAtIndex​(int index, com.vaadin.flow.component.Component component)
      Adds the given component into this notification at the given index.
      com.vaadin.flow.shared.Registration addDetachListener​(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.DetachEvent> listener)
      com.vaadin.flow.shared.Registration addOpenedChangeListener​(com.vaadin.flow.component.ComponentEventListener<Notification.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<com.vaadin.flow.component.Component> getChildren()  
      int getDuration()
      Description copied from corresponding location in WebComponent:
      Notification.Position getPosition()
      Description copied from corresponding location in WebComponent:
      com.vaadin.flow.dom.Style getStyle()  
      boolean isOpened()
      Description copied from corresponding location in WebComponent:
      protected void onAttach​(com.vaadin.flow.component.AttachEvent attachEvent)  
      protected void onDetach​(com.vaadin.flow.component.DetachEvent detachEvent)  
      void open()
      Opens the notification.
      void remove​(com.vaadin.flow.component.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.Component

        addListener, findAncestor, fireEvent, from, get, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onEnabledStateChanged, scrollIntoView, set, setElement, setId, setVisible
      • Methods inherited from interface com.vaadin.flow.component.HasComponents

        add, add, addComponentAsFirst, remove
      • 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-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 Notification
        duration - 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 notification
        duration - the duration in milliseconds to show the notification
        position - 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 Text component 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 Notification
        duration - the duration in milliseconds to show the notification
        position - 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 String

        NOTE: When mixing this method with Notification() and Notification(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 are TOP_STRETCH, TOP_START, TOP_CENTER, TOP_END, MIDDLE, BOTTOM_START, BOTTOM_CENTER, BOTTOM_END, BOTTOM_STRETCH, not null
      • 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
      • 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 class GeneratedVaadinNotification<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) and Notification(String, int, Position) method will remove the text content.

        Specified by:
        add in interface com.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:
        remove in interface com.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) and Notification(String, int, Position) method will remove the text content.

        Specified by:
        addComponentAtIndex in interface com.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:
        removeAll in interface com.vaadin.flow.component.HasComponents
      • getChildren

        public Stream<com.vaadin.flow.component.Component> getChildren()
        Overrides:
        getChildren in class com.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:
        setOpened in class GeneratedVaadinNotification<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
      • 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 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:
        addAttachListener in interface com.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:
        addDetachListener in interface com.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:
        onAttach in class com.vaadin.flow.component.Component
      • onDetach

        protected void onDetach​(com.vaadin.flow.component.DetachEvent detachEvent)
        Overrides:
        onDetach in class com.vaadin.flow.component.Component
      • getStyle

        public com.vaadin.flow.dom.Style getStyle()
        Specified by:
        getStyle in interface com.vaadin.flow.component.HasStyle
        Throws:
        UnsupportedOperationException - Notification does not support adding styles to card element