public class GridContextMenu<T> extends ContextMenuBase<GridContextMenu<T>,GridMenuItem<T>,GridSubMenu<T>>
<vaadin-context-menu>
to be used with
Grid
.Modifier and Type | Class and Description |
---|---|
static class |
GridContextMenu.GridContextMenuItemClickEvent<T>
Event that is fired when a
GridMenuItem is clicked inside a
GridContextMenu . |
static class |
GridContextMenu.GridContextMenuOpenedEvent<T> |
GeneratedVaadinContextMenu.OpenedChangeEvent<R extends GeneratedVaadinContextMenu<R>>
EVENT_DETAIL
Constructor and 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.
|
Modifier and Type | Method and Description |
---|---|
Registration |
addGridContextMenuOpenedListener(ComponentEventListener<GridContextMenu.GridContextMenuOpenedEvent<T>> listener)
Adds a listener for the
opened-changed events fired by the web
component. |
GridMenuItem<T> |
addItem(Component component,
ComponentEventListener<GridContextMenu.GridContextMenuItemClickEvent<T>> clickListener)
Adds a new item component with the given component and click listener to
the context menu overlay.
|
GridMenuItem<T> |
addItem(String text,
ComponentEventListener<GridContextMenu.GridContextMenuItemClickEvent<T>> clickListener)
Adds a new item component with the given text content and click listener
to the context menu overlay.
|
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 the
ContextMenuBase.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.
|
add, addComponentAtIndex, addItem, addItem, addOpenedChangeListener, close, getChildren, getItems, getMenuManager, getTarget, isOpened, isOpenOnClick, remove, removeAll, setOpenOnClick
getCloseOnString, getListenOnJsonObject, getOpenOnString, getSelectorString, isOpenedBoolean, open, setCloseOn, setListenOn, setOpenOn, setSelector
addListener, fireEvent, from, get, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getUI, hasListener, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, set, setElement, setId, setVisible
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
add, addComponentAsFirst
isEnabled, setEnabled
getElement
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
addClickListener, addClickShortcut
addAttachListener
addDetachListener
public GridContextMenu()
public GridContextMenu(Grid<T> target)
target
- the target component for this context menusetTarget(Component)
public void setTarget(Component target)
By default, the context menu can be opened with a right click or a long touch on the target component.
setTarget
in class ContextMenuBase<GridContextMenu<T>,GridMenuItem<T>,GridSubMenu<T>>
target
- the target component for this context menu, can be
null
to remove the targetIllegalArgumentException
- if the given target is not an instance of Grid
public GridMenuItem<T> addItem(String text, ComponentEventListener<GridContextMenu.GridContextMenuItemClickEvent<T>> clickListener)
This is a convenience method for the use case where you have a list of
highlightable GridMenuItem
s inside the overlay. If you want to
configure the contents of the overlay without wrapping them inside
GridMenuItem
s, or if you just want to add some non-highlightable
components between the items, use the
ContextMenuBase.add(Component...)
method.
text
- the text content for the new itemclickListener
- the handler for clicking the new item, can be null
to
not add listenerGridMenuItem
componentaddItem(Component, ComponentEventListener)
,
ContextMenuBase.add(Component...)
,
SubMenuBase.add(Component...)
public GridMenuItem<T> addItem(Component component, ComponentEventListener<GridContextMenu.GridContextMenuItemClickEvent<T>> clickListener)
This is a convenience method for the use case where you have a list of
highlightable GridMenuItem
s inside the overlay. If you want to
configure the contents of the overlay without wrapping them inside
GridMenuItem
s, or if you just want to add some non-highlightable
components between the items, use the
ContextMenuBase.add(Component...)
method.
component
- the component inside the new itemclickListener
- the handler for clicking the new item, can be null
to
not add listenerGridMenuItem
componentaddItem(String, ComponentEventListener)
,
ContextMenuBase.add(Component...)
,
SubMenuBase.add(Component...)
protected MenuManager<GridContextMenu<T>,GridMenuItem<T>,GridSubMenu<T>> createMenuManager(SerializableRunnable contentReset)
ContextMenuBase
createMenuManager
in class ContextMenuBase<GridContextMenu<T>,GridMenuItem<T>,GridSubMenu<T>>
contentReset
- callback to reset the menu contentpublic Registration addGridContextMenuOpenedListener(ComponentEventListener<GridContextMenu.GridContextMenuOpenedEvent<T>> listener)
opened-changed
events fired by the web
component.listener
- the listener to addpublic SerializablePredicate<T> getDynamicContentHandler()
The dynamic context handler allows for customizing the contents of the context menu before it is open.
null
if not specified.public void setDynamicContentHandler(SerializablePredicate<T> dynamicContentHandler)
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.
dynamicContentHandler
- the callback function that will be executed before opening the
context menu.protected boolean onBeforeOpenMenu(elemental.json.JsonObject eventDetail)
ContextMenuBase.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.
onBeforeOpenMenu
in class ContextMenuBase<GridContextMenu<T>,GridMenuItem<T>,GridSubMenu<T>>
eventDetail
- the client side event details provided by the target
component.true
if the context menu should be opened, false
otherwise.Copyright © 2020. All rights reserved.