com.vaadin.flow.component.contextmenu.

Class ContextMenuBase<C extends ContextMenuBase<C>>

    • Constructor Detail

      • ContextMenuBase

        public ContextMenuBase()

        Creates an empty context menu.

    • Method Detail

      • setTarget

        public void setTarget(Component target)

        Sets the target component for this context menu.

        By default, the context menu can be opened with a right click or a long touch on the target component.

        Parameters:

        target - the target component for this context menu, can be null to remove the target

      • getTarget

        public Component getTarget()

        Gets the target component of this context menu, or null if it doesn't have a target.

        Returns:

        the target component of this context menu

        See Also:

        setTarget(Component)

      • setOpenOnClick

        public void setOpenOnClick(boolean openOnClick)

        Determines the way for opening the context menu.

        By default, the context menu can be opened with a right click or a long touch on the target component.

        Parameters:

        openOnClick - if true, the context menu can be opened with left click only. Otherwise the context menu follows the default behavior.

      • isOpenOnClick

        public boolean isOpenOnClick()

        Gets whether the context menu can be opened via left click.

        By default, this will return false and context menu can be opened with a right click or a long touch on the target component.

        Returns:

        true if the context menu can be opened with left click only. Otherwise the context menu follows the default behavior.

      • add

        public void add(Component... components)

        Adds the given components into the context menu overlay.

        For the common use case of having a list of high-lightable items inside the overlay, you can use the #addItem(Component, ComponentEventListener) convenience methods instead.

        The added elements in the DOM will not be children of the <vaadin-context-menu> element, but will be inserted into an overlay that is attached into the <body>.

        Specified by:

        add in interface HasComponents

        Parameters:

        components - the components to add

        See Also:

        #addItem(String, ComponentEventListener), #addItem(Component, ComponentEventListener)

      • remove

        public void remove(Component... components)

        Description copied from interface: HasComponents

        Removes the given child components from this component.

        Specified by:

        remove in interface HasComponents

        Parameters:

        components - the components to remove

      • removeAll

        public void removeAll()

        Removes all contents from this component, this includes child components, text content as well as child elements that have been added directly to this component using the Element API. it also removes the children that were added only at the client-side. This also removes all the items added with addItem(String) and its overload methods.

        Specified by:

        removeAll in interface HasComponents

      • addComponentAtIndex

        public void addComponentAtIndex(int index,
                                        Component component)

        Adds the given component into this context menu at the given index.

        The added elements in the DOM will not be children of the <vaadin-context-menu> element, but will be inserted into an overlay that is attached into the <body>.

        Specified by:

        addComponentAtIndex in interface HasComponents

        Parameters:

        index - the index, where the component will be added.

        component - the component to add

      • getItems

        public List<MenuItem> getItems()

        Gets the items added to this component (the children of this component that are instances of MenuItem).

        Returns:

        the MenuItem components in this context menu

        See Also:

        #addItem(String, ComponentEventListener)

      • isOpened

        public boolean isOpened()

        Gets the open state from the context menu.

        Returns:

        the opened property from the context menu

      • addItem

        protected MenuItem addItem(String text)

        Creates and adds a new item component to this context menu with the given text content.

        Parameters:

        text - the text content for the created menu item

        Returns:

        the created menu item

      • addItem

        protected MenuItem addItem(Component component)

        Creates and adds a new item component to this context menu with the given component inside.

        Parameters:

        component - the component to add to the created menu item

        Returns:

        the created menu item