C
- the context-menu typeI
- the menu-item typeS
- the sub menu type@JsModule(value="./flow-component-renderer.js") @JsModule(value="./contextMenuConnector-es6.js") @JavaScript(value="frontend://contextMenuConnector.js") public abstract class ContextMenuBase<C extends ContextMenuBase<C,I,S>,I extends MenuItemBase<C,I,S>,S extends SubMenuBase<C,I,S>> extends GeneratedVaadinContextMenu<C> implements HasComponents
<vaadin-context-menu>
. Classes extending this should provide API for
adding items and handling events related to them. For basic example, see
ContextMenu
.GeneratedVaadinContextMenu.OpenedChangeEvent<R extends GeneratedVaadinContextMenu<R>>
Modifier and Type | Field and Description |
---|---|
static String |
EVENT_DETAIL |
Constructor and Description |
---|
ContextMenuBase()
Creates an empty context menu.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Component... components)
Adds the given components into the context menu overlay.
|
void |
addComponentAtIndex(int index,
Component component)
Adds the given component into this context menu at the given index.
|
I |
addItem(Component component)
Adds a new item component with the given component to the context menu
overlay.
|
I |
addItem(String text)
Adds a new item component with the given text content to the context menu
overlay.
|
Registration |
addOpenedChangeListener(ComponentEventListener<GeneratedVaadinContextMenu.OpenedChangeEvent<C>> listener)
Adds a listener for the
opened-changed events fired by the web
component. |
void |
close()
Closes this context menu if it is currently open.
|
protected abstract MenuManager<C,I,S> |
createMenuManager(SerializableRunnable contentReset)
Creates a menu manager instance which contains logic to control the menu
content.
|
Stream<Component> |
getChildren()
Gets the child components of this component.
|
List<I> |
getItems()
Gets the items added to this component (the children of this component
that are instances of
MenuItem ). |
protected MenuManager<C,I,S> |
getMenuManager()
Gets the menu manager.
|
Component |
getTarget()
Gets the target component of this context menu, or
null if it
doesn't have a target. |
boolean |
isOpened()
Gets the open state from the context menu.
|
boolean |
isOpenOnClick()
Gets whether the context menu can be opened via left click.
|
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. |
void |
remove(Component... components)
Removes the given child components from this component.
|
void |
removeAll()
Removes all of the child components.
|
void |
setOpenOnClick(boolean openOnClick)
Determines the way for opening the context menu.
|
void |
setTarget(Component target)
Sets the target component for this context menu.
|
getCloseOnString, getListenOnJsonObject, getOpenOnString, getSelectorString, isOpenedBoolean, open, setCloseOn, setListenOn, setOpenOn, setSelector
addListener, fireEvent, from, get, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, 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 static final String EVENT_DETAIL
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.
target
- the target component for this context menu, can be
null
to remove the targetpublic Component getTarget()
null
if it
doesn't have a target.setTarget(Component)
public void setOpenOnClick(boolean openOnClick)
By default, the context menu can be opened with a right click or a long touch on the target component.
openOnClick
- if true
, the context menu can be opened with left
click only. Otherwise the context menu follows the default
behavior.public boolean isOpenOnClick()
By default, this will return false
and context menu can be opened
with a right click or a long touch on the target component.
true
if the context menu can be opened with left click
only. Otherwise the context menu follows the default behavior.public void close()
close
in class GeneratedVaadinContextMenu<C extends ContextMenuBase<C,I,S>>
public I addItem(String text)
This is a convenience method for the use case where you have a list of
highlightable MenuItem
s inside the overlay. If you want to
configure the contents of the overlay without wrapping them inside
MenuItem
s, or if you just want to add some non-highlightable
components between the items, use the add(Component...)
method.
text
- the text content for the created menu itemadd(Component...)
public I addItem(Component component)
This is a convenience method for the use case where you have a list of
highlightable MenuItem
s inside the overlay. If you want to
configure the contents of the overlay without wrapping them inside
MenuItem
s, or if you just want to add some non-highlightable
components between the items, use the add(Component...)
method.
component
- the component to add to the created menu itemadd(Component...)
public void add(Component... components)
For the common use case of having a list of high-lightable items inside
the overlay, you can use the addItem(String)
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>
.
add
in interface HasComponents
components
- the components to addHasMenuItems.addItem(String, ComponentEventListener)
,
HasMenuItems.addItem(Component, ComponentEventListener)
public void remove(Component... components)
HasComponents
remove
in interface HasComponents
components
- the components to removepublic void removeAll()
addItem(String)
and its overload methods.removeAll
in interface HasComponents
public void addComponentAtIndex(int index, Component component)
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>
.
addComponentAtIndex
in interface HasComponents
index
- the index, where the component will be addedcomponent
- the component to addadd(Component...)
public Stream<Component> getChildren()
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.getChildren
in class Component
Id
public List<I> getItems()
MenuItem
). This doesn't include the
components added to the sub menus of this context menu.MenuItem
components in this context menuaddItem(String)
public boolean isOpened()
opened
property from the context menupublic Registration addOpenedChangeListener(ComponentEventListener<GeneratedVaadinContextMenu.OpenedChangeEvent<C>> listener)
opened-changed
events fired by the web
component.addOpenedChangeListener
in class GeneratedVaadinContextMenu<C extends ContextMenuBase<C,I,S>>
listener
- the listener to addprotected MenuManager<C,I,S> getMenuManager()
protected abstract MenuManager<C,I,S> createMenuManager(SerializableRunnable contentReset)
contentReset
- callback to reset the menu contentprotected boolean onBeforeOpenMenu(elemental.json.JsonObject eventDetail)
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.
eventDetail
- the client side event details provided by the target
component.true
if the context menu should be opened, false
otherwise.Copyright © 2025. All rights reserved.