Class GridContextMenu<T>
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.contextmenu.GeneratedVaadinContextMenu<C>
-
- com.vaadin.flow.component.contextmenu.ContextMenuBase<GridContextMenu<T>,GridMenuItem<T>,GridSubMenu<T>>
-
- com.vaadin.flow.component.grid.contextmenu.GridContextMenu<T>
-
- All Implemented Interfaces:
AttachNotifier
,ClickNotifier<GridContextMenu<T>>
,DetachNotifier
,HasComponents
,HasElement
,HasEnabled
,HasStyle
,Serializable
public class GridContextMenu<T> extends ContextMenuBase<GridContextMenu<T>,GridMenuItem<T>,GridSubMenu<T>>
Server-side component for<vaadin-context-menu>
to be used withGrid
.- Author:
- Vaadin Ltd.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GridContextMenu.GridContextMenuItemClickEvent<T>
Event that is fired when aGridMenuItem
is clicked inside aGridContextMenu
.static class
GridContextMenu.GridContextMenuOpenedEvent<T>
-
Nested classes/interfaces inherited from class com.vaadin.flow.component.contextmenu.ContextMenuBase
ContextMenuBase.OpenedChangeEvent<C extends ContextMenuBase<C,?,?>>
-
-
Field Summary
-
Fields inherited from class com.vaadin.flow.component.contextmenu.ContextMenuBase
EVENT_DETAIL
-
-
Constructor Summary
Constructors Constructor Description GridContextMenu()
Creates an empty context menu to be used with a Grid.GridContextMenu(Grid<T> target)
Creates an empty context menu with the given target component.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Registration
addGridContextMenuOpenedListener(ComponentEventListener<GridContextMenu.GridContextMenuOpenedEvent<T>> listener)
Adds a listener for theopened-changed
events fired by the web component.GridMenuItem<T>
addItem(Component component, ComponentEventListener<GridContextMenu.GridContextMenuItemClickEvent<T>> clickListener)
GridMenuItem<T>
addItem(String text, ComponentEventListener<GridContextMenu.GridContextMenuItemClickEvent<T>> clickListener)
protected MenuManager<GridContextMenu<T>,GridMenuItem<T>,GridSubMenu<T>>
createMenuManager(SerializableRunnable contentReset)
Creates a menu manager instance which contains logic to control the menu content.SerializablePredicate<T>
getDynamicContentHandler()
Gets the callback function that is executed before the context menu is opened.protected boolean
onBeforeOpenMenu(elemental.json.JsonObject eventDetail)
Decides whether to open the menu when theContextMenuBase.beforeOpenHandler(DomEvent)
is processed, sub-classes can easily override it and perform additional operations in this phase.void
setDynamicContentHandler(SerializablePredicate<T> dynamicContentHandler)
Sets a callback that is executed before the context menu is opened.void
setTarget(Component target)
Sets the target component for this context menu.-
Methods inherited from class com.vaadin.flow.component.contextmenu.ContextMenuBase
add, addComponentAtIndex, addItem, addItem, addOpenedChangeListener, close, getChildren, getItems, getMenuManager, getTarget, isOpened, isOpenOnClick, remove, removeAll, setOpenOnClick
-
Methods inherited from class com.vaadin.flow.component.contextmenu.GeneratedVaadinContextMenu
addClickListener, addClickShortcut, getCloseOnString, getListenOnJsonObject, getOpenOnString, getSelectorString, isOpenedBoolean, open, setCloseOn, setListenOn, setOpenOn, setSelector
-
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, onAttach, onDetach, onEnabledStateChanged, scrollIntoView, set, setElement, setId, setVisible
-
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.ClickNotifier
addDoubleClickListener, addSingleClickListener
-
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
-
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, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
-
-
-
Constructor Detail
-
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:
setTarget(Component)
-
-
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.
- Overrides:
setTarget
in classContextMenuBase<GridContextMenu<T>,GridMenuItem<T>,GridSubMenu<T>>
- Parameters:
target
- the target component for this context menu, can benull
to remove the target- Throws:
IllegalArgumentException
- if the given target is not an instance ofGrid
-
addItem
public GridMenuItem<T> addItem(String text, ComponentEventListener<GridContextMenu.GridContextMenuItemClickEvent<T>> clickListener)
-
addItem
public GridMenuItem<T> addItem(Component component, ComponentEventListener<GridContextMenu.GridContextMenuItemClickEvent<T>> clickListener)
-
createMenuManager
protected MenuManager<GridContextMenu<T>,GridMenuItem<T>,GridSubMenu<T>> createMenuManager(SerializableRunnable contentReset)
Description copied from class:ContextMenuBase
Creates a menu manager instance which contains logic to control the menu content.- Specified by:
createMenuManager
in classContextMenuBase<GridContextMenu<T>,GridMenuItem<T>,GridSubMenu<T>>
- Parameters:
contentReset
- callback to reset the menu content- Returns:
- a new menu manager instance
-
addGridContextMenuOpenedListener
public Registration addGridContextMenuOpenedListener(ComponentEventListener<GridContextMenu.GridContextMenuOpenedEvent<T>> listener)
Adds a listener for theopened-changed
events fired by the web component.- Parameters:
listener
- the listener to add- Returns:
- a Registration for removing the event listener
-
getDynamicContentHandler
public SerializablePredicate<T> getDynamicContentHandler()
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.
-
setDynamicContentHandler
public void setDynamicContentHandler(SerializablePredicate<T> dynamicContentHandler)
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.
- Parameters:
dynamicContentHandler
- the callback function that will be executed before opening the context menu.
-
onBeforeOpenMenu
protected boolean onBeforeOpenMenu(elemental.json.JsonObject eventDetail)
Decides whether to open the menu when theContextMenuBase.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.
- Overrides:
onBeforeOpenMenu
in classContextMenuBase<GridContextMenu<T>,GridMenuItem<T>,GridSubMenu<T>>
- Parameters:
eventDetail
- the client side event details provided by the target component.- Returns:
true
if the context menu should be opened,false
otherwise.
-
-