Class ContextMenuBase<C extends ContextMenuBase<C,I,S>,I extends MenuItemBase<C,I,S>,S extends SubMenuBase<C,I,S>>
- Type Parameters:
C- the context-menu typeI- the menu-item typeS- the sub menu type
- All Implemented Interfaces:
AttachNotifier,DetachNotifier,HasElement,HasStyle,Serializable
- Direct Known Subclasses:
ContextMenu,GridContextMenu
<vaadin-context-menu>. Classes extending this should provide API for
adding items and handling events related to them. For basic example, see
ContextMenu.- Author:
- Vaadin Ltd.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classContextMenuBase.OpenedChangeEvent<TComponent extends ContextMenuBase<TComponent,?, ?>> opened-changedevent is sent when the opened state changes. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddComponent(Component... components) Adds the given components to the context menu.voidaddComponent(Collection<Component> components) Adds the given components to the context menu.voidaddComponentAsFirst(Component component) Adds the given component as the first child to the context menu.voidaddComponentAtIndex(int index, Component component) Adds the given component to the context menu at the given index.Creates a new menu item with the given component content and adds it to the context menu.Creates a new menu item with the given text content and adds it to the context menu.Adds a listener for theopened-changedevents fired by the web component.voidAdds a separator between items.voidclose()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.Gets the child components of this component.getItems()Gets the items added to this component (the children of this component that are instances ofMenuItem).protected MenuManager<C, I, S> Gets the menu manager.Gets the target component of this context menu, ornullif it doesn't have a target.booleanisOpened()Gets the open state from the context menu.booleanGets whether the context menu can be opened via left click.protected booleanonBeforeOpenMenu(tools.jackson.databind.node.ObjectNode eventDetail) Decides whether to open the menu when thebeforeOpenHandler(DomEvent)is processed, sub-classes can easily override it and perform additional operations in this phase.voidRemoves the given components from the context menu.voidRemoves all the child components.voidsetOpenOnClick(boolean openOnClick) Determines the way for opening the context menu.voidSets the target component for this context menu.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, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Field Details
-
EVENT_DETAIL
- See Also:
-
-
Constructor Details
-
ContextMenuBase
public ContextMenuBase()Creates an empty context menu.
-
-
Method Details
-
setTarget
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 benullto remove the target
-
getTarget
Gets the target component of this context menu, ornullif it doesn't have a target.- Returns:
- the target component of this context menu
- See Also:
-
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- iftrue, 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
falseand context menu can be opened with a right click or a long touch on the target component.- Returns:
trueif the context menu can be opened with left click only. Otherwise the context menu follows the default behavior.
-
close
public void close()Closes this context menu if it is currently open. -
addItem
Creates a new menu item with the given text content and adds it to the context menu.- Parameters:
text- the text content for the created menu item- Returns:
- the created menu item
-
addItem
Creates a new menu item with the given component content and adds it to the context menu.- Parameters:
component- the component to add to the created menu item- Returns:
- the created menu item
-
addComponent
Adds the given components to the context menu.For the common use case of having a list of high-lightable items inside the menu, use
addItem(String)and its overload methods instead.- Parameters:
components- the components to add- See Also:
-
addComponent
Adds the given components to the context menu.For the common use case of having a list of high-lightable items inside the menu, use
addItem(String)and its overload methods instead.- Parameters:
components- the components to add- See Also:
-
remove
Removes the given components from the context menu.- Parameters:
components- the components to remove
-
removeAll
public void removeAll()Removes all the child components. This also removes all the items added withaddItem(String)and its overload methods. -
addComponentAtIndex
Adds the given component to the context menu at the given index.For the common use case of having a list of high-lightable items inside the menu, use
addItem(String)and its overload methods instead.- Parameters:
index- the index, where the component will be addedcomponent- the component to add
-
addComponentAsFirst
Adds the given component as the first child to the context menu.For the common use case of having a list of high-lightable items inside the menu, use
addItem(String)and its overload methods instead.- Parameters:
component- the component to add
-
addSeparator
public void addSeparator()Adds a separator between items. -
getChildren
Gets the child components of this component. This includes components added withaddComponent(Component...)and theMenuItemcomponents created withaddItem(String)and its overload methods. This doesn't include the components added to the sub menus of this context menu.- Overrides:
getChildrenin classComponent- Returns:
- the child components of this component
- See Also:
-
getItems
Gets the items added to this component (the children of this component that are instances ofMenuItem). This doesn't include the components added to the sub menus of this context menu.- Returns:
- the
MenuItemcomponents in this context menu - See Also:
-
isOpened
Gets the open state from the context menu.This property is synchronized automatically from client side when an
opened-changedevent happens.- Returns:
- the
openedproperty from the context menu
-
addOpenedChangeListener
public Registration addOpenedChangeListener(ComponentEventListener<ContextMenuBase.OpenedChangeEvent<C>> listener) Adds a listener for theopened-changedevents fired by the web component.- Parameters:
listener- the listener to add- Returns:
- a Registration for removing the event listener
-
getMenuManager
Gets the menu manager.- Returns:
- the menu manager
-
createMenuManager
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(tools.jackson.databind.node.ObjectNode eventDetail) Decides whether to open the menu when thebeforeOpenHandler(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:
trueif the context menu should be opened,falseotherwise.
-