Class Notification

    • 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​(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>
      • remove

        public void remove​(Component... components)
        Remove the given components from this notification.
        Specified by:
        remove in interface HasComponents
        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) and Notification(String, int, Position) method will remove the text content.

        Specified by:
        addComponentAtIndex in interface 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 HasComponents
      • 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 class Component
        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:
        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
      • 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: 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.

        Overrides:
        onAttach in class Component
        Parameters:
        attachEvent - the attach event
      • onDetach

        protected void onDetach​(DetachEvent detachEvent)
        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.

        Overrides:
        onDetach in class Component
        Parameters:
        detachEvent - the detach event
      • getStyle

        public Style getStyle()
        Description copied from interface: HasStyle
        Gets the style instance for managing inline styles for the element of this component.
        Specified by:
        getStyle in interface HasStyle
        Returns:
        the style object for the element, not null
        Throws:
        UnsupportedOperationException - Notification does not support adding styles to card element