Class ContextMenuBase<C extends ContextMenuBase<C,​I,​S>,​I extends MenuItemBase<C,​I,​S>,​S extends SubMenuBase<C,​I,​S>>

    • 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.
      • addItem

        public I addItem​(String text)
        Adds a new item component with the given text content to the context menu overlay.

        This is a convenience method for the use case where you have a list of highlightable MenuItems inside the overlay. If you want to configure the contents of the overlay without wrapping them inside MenuItems, or if you just want to add some non-highlightable components between the items, use the add(Component...) method.

        Parameters:
        text - the text content for the created menu item
        Returns:
        the created menu item
        See Also:
        add(Component...)
      • addItem

        public I addItem​(Component component)
        Adds a new item component with the given component to the context menu overlay.

        This is a convenience method for the use case where you have a list of highlightable MenuItems inside the overlay. If you want to configure the contents of the overlay without wrapping them inside MenuItems, or if you just want to add some non-highlightable components between the items, use the add(Component...) method.

        Parameters:
        component - the component to add to the created menu item
        Returns:
        the created menu item
        See Also:
        add(Component...)
      • 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 of the child components. 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
        See Also:
        add(Component...)
      • getChildren

        public Stream<Component> getChildren()
        Gets the child components of this component. This includes components added with add(Component...) and the MenuItem components created with addItem(String) and its overload methods. This doesn't include the components added to the sub menus of this context menu.
        Overrides:
        getChildren in class Component
        Returns:
        the child components of this component
        See Also:
        Id
      • getItems

        public List<I> getItems()
        Gets the items added to this component (the children of this component that are instances of MenuItem). This doesn't include the components added to the sub menus of this context menu.
        Returns:
        the MenuItem components in this context menu
        See Also:
        addItem(String)
      • isOpened

        public boolean isOpened()
        Gets the open state from the context menu.
        Returns:
        the opened property from the context menu
      • getMenuManager

        protected MenuManager<C,​I,​S> getMenuManager()
        Gets the menu manager.
        Returns:
        the menu manager
      • createMenuManager

        protected abstract MenuManager<C,​I,​S> createMenuManager​(SerializableRunnable contentReset)
        Creates a menu manager instance which contains logic to control the menu content.
        Parameters:
        contentReset - callback to reset the menu content
        Returns:
        a new menu manager instance
      • onBeforeOpenMenu

        protected boolean onBeforeOpenMenu​(elemental.json.JsonObject eventDetail)
        Decides whether to open the menu when the beforeOpenHandler(DomEvent) is processed, sub-classes can easily override it and perform additional operations in this phase.

        The event details are completely specified by the target component that is in charge of defining the data it sends to the server. Based on this information, this method enables for dynamically modifying the contents of the context menu. Furthermore, this method's return value specifies if the context menu will be opened.

        Parameters:
        eventDetail - the client side event details provided by the target component.
        Returns:
        true if the context menu should be opened, false otherwise.