Class GridContextMenu<T>

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.contextmenu.ContextMenuBase<GridContextMenu<T>,GridMenuItem<T>,GridSubMenu<T>>
com.vaadin.flow.component.grid.contextmenu.GridContextMenu<T>
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasStyle, Serializable

public class GridContextMenu<T> extends com.vaadin.flow.component.contextmenu.ContextMenuBase<GridContextMenu<T>,GridMenuItem<T>,GridSubMenu<T>>
Server-side component for <vaadin-context-menu> to be used with Grid.
Since:
3.0
Author:
Vaadin Ltd.
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    The context of a context-click on a Grid, passed to the dynamic content provider.
    static class 
    Event that is fired when a GridMenuItem is clicked inside a GridContextMenu.
    static class 
     

    Nested classes/interfaces inherited from class com.vaadin.flow.component.contextmenu.ContextMenuBase

    com.vaadin.flow.component.contextmenu.ContextMenuBase.OpenedChangeEvent<TComponent extends com.vaadin.flow.component.contextmenu.ContextMenuBase<TComponent,?,?>>
  • Field Summary

    Fields inherited from class com.vaadin.flow.component.contextmenu.ContextMenuBase

    EVENT_DETAIL
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty context menu to be used with a Grid.
    Creates an empty context menu with the given target component.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.vaadin.flow.shared.Registration
    addGridContextMenuOpenedListener(com.vaadin.flow.component.ComponentEventListener<GridContextMenu.GridContextMenuOpenedEvent<T>> listener)
    Adds a listener for the opened-changed events fired by the web component.
    addItem(com.vaadin.flow.component.Component component, com.vaadin.flow.component.ComponentEventListener<GridContextMenu.GridContextMenuItemClickEvent<T>> clickListener)
     
    addItem(String text, com.vaadin.flow.component.ComponentEventListener<GridContextMenu.GridContextMenuItemClickEvent<T>> clickListener)
     
    protected com.vaadin.flow.component.contextmenu.MenuManager<GridContextMenu<T>,GridMenuItem<T>,GridSubMenu<T>>
    createMenuManager(com.vaadin.flow.function.SerializableRunnable contentReset)
     
    static <T> List<GridContextMenu<T>>
    Gets the grid context menus that have the given grid as their target, in the order their target was set.
    com.vaadin.flow.function.SerializablePredicate<T>
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use getDynamicContentProvider() together with setDynamicContentProvider(SerializablePredicate), which also receives the clicked column.
    com.vaadin.flow.function.SerializablePredicate<GridContextMenu.DynamicContentContext<T>>
    Gets the callback function that is executed before the context menu is opened to dynamically provide its contents.
    protected boolean
    onBeforeOpenMenu(tools.jackson.databind.node.ObjectNode eventDetail)
    void
    setDynamicContentHandler(com.vaadin.flow.function.SerializablePredicate<T> dynamicContentHandler)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use setDynamicContentProvider(SerializablePredicate) instead, which also receives the clicked column.
    void
    setDynamicContentProvider(com.vaadin.flow.function.SerializablePredicate<GridContextMenu.DynamicContentContext<T>> dynamicContentProvider)
    Sets a callback that is executed before the context menu is opened to dynamically provide its contents.
    void
    setTarget(com.vaadin.flow.component.Component target)

    Methods inherited from class com.vaadin.flow.component.contextmenu.ContextMenuBase

    addComponent, addComponent, addComponentAsFirst, addComponentAtIndex, addItem, addItem, addItem, addItem, addOpenedChangeListener, addSeparator, close, getChildren, getContextMenus, getItems, getMenuManager, getTarget, isOpened, isOpenOnClick, remove, removeAll, setOpenOnClick

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, bindVisible, findAncestor, findAncestor, fireEvent, from, get, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, getUIOrThrow, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, setVisible, whenAttached

    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.AttachNotifier

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, bindClassName, bindClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
  • Constructor Details

    • GridContextMenu

      public GridContextMenu()
      Creates an empty context menu to be used with a Grid.
    • GridContextMenu

      public GridContextMenu(Grid<T> target)
      Creates an empty context menu with the given target component.
      Parameters:
      target - the target component for this context menu
      See Also:
  • Method Details

    • getContextMenus

      public static <T> List<GridContextMenu<T>> getContextMenus(Grid<T> grid)
      Gets the grid context menus that have the given grid as their target, in the order their target was set. Plain ContextMenu instances targeting the grid are not included.
      Type Parameters:
      T - the grid bean type
      Parameters:
      grid - the target grid
      Returns:
      an unmodifiable snapshot of the grid context menus targeting the grid, empty if there are none
      Since:
      25.4
      See Also:
    • setTarget

      public void setTarget(com.vaadin.flow.component.Component target)
      Overrides:
      setTarget in class com.vaadin.flow.component.contextmenu.ContextMenuBase<GridContextMenu<T>,GridMenuItem<T>,GridSubMenu<T>>
      Throws:
      IllegalArgumentException - if the given target is not an instance of Grid
    • addItem

      public GridMenuItem<T> addItem(String text, com.vaadin.flow.component.ComponentEventListener<GridContextMenu.GridContextMenuItemClickEvent<T>> clickListener)
    • addItem

      public GridMenuItem<T> addItem(com.vaadin.flow.component.Component component, com.vaadin.flow.component.ComponentEventListener<GridContextMenu.GridContextMenuItemClickEvent<T>> clickListener)
    • createMenuManager

      protected com.vaadin.flow.component.contextmenu.MenuManager<GridContextMenu<T>,GridMenuItem<T>,GridSubMenu<T>> createMenuManager(com.vaadin.flow.function.SerializableRunnable contentReset)
      Specified by:
      createMenuManager in class com.vaadin.flow.component.contextmenu.ContextMenuBase<GridContextMenu<T>,GridMenuItem<T>,GridSubMenu<T>>
    • addGridContextMenuOpenedListener

      public com.vaadin.flow.shared.Registration addGridContextMenuOpenedListener(com.vaadin.flow.component.ComponentEventListener<GridContextMenu.GridContextMenuOpenedEvent<T>> listener)
      Adds a listener for the opened-changed events fired by the web component.
      Parameters:
      listener - the listener to add
      Returns:
      a Registration for removing the event listener
      Since:
      4.0
    • getDynamicContentHandler

      @Deprecated(since="25.4", forRemoval=true) public com.vaadin.flow.function.SerializablePredicate<T> getDynamicContentHandler()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getDynamicContentProvider() together with setDynamicContentProvider(SerializablePredicate), which also receives the clicked column.
      Gets the callback function that is executed before the context menu is opened.

      The dynamic context handler allows for customizing the contents of the context menu before it is open.

      Returns:
      the callback function that is executed before opening the context menu, or null if not specified or if a dynamic content provider was set with setDynamicContentProvider(SerializablePredicate).
      Since:
      4.1
    • setDynamicContentHandler

      @Deprecated(since="25.4", forRemoval=true) public void setDynamicContentHandler(com.vaadin.flow.function.SerializablePredicate<T> dynamicContentHandler)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use setDynamicContentProvider(SerializablePredicate) instead, which also receives the clicked column.
      Sets a callback that is executed before the context menu is opened.

      This callback receives the clicked item (if any) as an input parameter and further can dynamically modify the contents of the context menu. This is useful in situations where the context menu items cannot be known in advance and depend on the specific context (i.e. clicked row) and thus can be configured dynamically. The boolean return value of this callback specifies if the context menu will be opened.

      Replaces any provider set with setDynamicContentProvider(SerializablePredicate).

      Parameters:
      dynamicContentHandler - the callback function that will be executed before opening the context menu.
      Since:
      4.1
    • getDynamicContentProvider

      public com.vaadin.flow.function.SerializablePredicate<GridContextMenu.DynamicContentContext<T>> getDynamicContentProvider()
      Gets the callback function that is executed before the context menu is opened to dynamically provide its contents.
      Returns:
      the callback function that is executed before opening the context menu, or null if not specified or if a handler was set with setDynamicContentHandler(SerializablePredicate).
      Since:
      25.4
      See Also:
    • setDynamicContentProvider

      public void setDynamicContentProvider(com.vaadin.flow.function.SerializablePredicate<GridContextMenu.DynamicContentContext<T>> dynamicContentProvider)
      Sets a callback that is executed before the context menu is opened to dynamically provide its contents.

      The callback receives a GridContextMenu.DynamicContentContext with the clicked item and column. This is useful when the context menu items depend on what was clicked, for example:

       contextMenu.setDynamicContentProvider(context -> {
           contextMenu.removeAll();
           Person person = context.item();
           if (context.column() == nameColumn) {
               contextMenu.addItem("Call", e -> call(person));
           } else if (context.column() == addressColumn) {
               contextMenu.addItem("Show on map", e -> showOnMap(person));
           }
           return true;
       });
       

      The boolean return value of this callback specifies if the context menu will be opened.

      Replaces any handler set with setDynamicContentHandler(SerializablePredicate).

      Parameters:
      dynamicContentProvider - the callback function that will be executed before opening the context menu, or null to remove it
      Since:
      25.4
    • onBeforeOpenMenu

      protected boolean onBeforeOpenMenu(tools.jackson.databind.node.ObjectNode eventDetail)
      Overrides:
      onBeforeOpenMenu in class com.vaadin.flow.component.contextmenu.ContextMenuBase<GridContextMenu<T>,GridMenuItem<T>,GridSubMenu<T>>
      Since:
      25.0