com.vaadin.flow.component.contextmenu.
Class ContextMenuBase<C extends ContextMenuBase<C>>
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.contextmenu.GeneratedVaadinContextMenu<C>
-
- com.vaadin.flow.component.contextmenu.ContextMenuBase<C>
-
All Implemented Interfaces:
AttachNotifier, ClickNotifier<C>, DetachNotifier, HasComponents, HasElement, HasEnabled, HasStyle, Serializable
Direct Known Subclasses:
@HtmlImport(value="flow-component-renderer.html") @HtmlImport(value="frontend://bower_components/vaadin-list-box/src/vaadin-list-box.html") @JavaScript(value="frontend://contextMenuConnector.js") public class ContextMenuBase<C extends ContextMenuBase<C>> extends GeneratedVaadinContextMenu<C> implements HasComponents
Base functionality for server-side components based on
<vaadin-context-menu>
. Classes extending this should provide API for adding items and handling events related to them. For basic example, seeContextMenu
.Author:
Vaadin Ltd.
See Also:
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.vaadin.flow.component.contextmenu.GeneratedVaadinContextMenu
GeneratedVaadinContextMenu.OpenedChangeEvent<R extends GeneratedVaadinContextMenu<R>>
-
-
Constructor Summary
Constructors Constructor and Description ContextMenuBase()
Creates an empty context menu.
-
Method Summary
All Methods 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.
protected MenuItem
addItem(Component component)
Creates and adds a new item component to this context menu with the given component inside.
protected MenuItem
addItem(String text)
Creates and adds a new item component to this context menu with the given text content.
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.
Stream<Component>
getChildren()
Gets the child components of this component.
List<MenuItem>
getItems()
Gets the items added to this component (the children of this component that are instances of
MenuItem
).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.
void
remove(Component... components)
Removes the given child components from this component.
void
removeAll()
Removes all contents from this component, this includes child components, text content as well as child elements that have been added directly to this component using the
Element
API.void
setOpenOnClick(boolean openOnClick)
Determines the way for opening the context menu.
void
setTarget(Component target)
Sets the target component for this context menu.
-
Methods inherited from class com.vaadin.flow.component.contextmenu.GeneratedVaadinContextMenu
getCloseOnString, getListenOnJsonObject, getOpenOnString, getSelectorString, isOpenedBoolean, open, setCloseOn, setListenOn, setOpenOn, setSelector
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getUI, hasListener, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, 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.HasComponents
addComponentAsFirst
-
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
-
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
-
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Methods inherited from interface com.vaadin.flow.component.ClickNotifier
addClickListener
-
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
-
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
-
-
-
-
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.
Parameters:
target
- the target component for this context menu, can benull
to remove the target
-
getTarget
public Component getTarget()
Gets the target component of this context menu, or
null
if 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
false
and context menu can be opened with a right click or a long touch on the target component.Returns:
true
if 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.
Overrides:
close
in classGeneratedVaadinContextMenu<C extends ContextMenuBase<C>>
-
add
public void add(Component... components)
Adds the given components into the context menu overlay.
For the common use case of having a list of high-lightable items inside the overlay, you can use the
#addItem(Component, ComponentEventListener)
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>
.Specified by:
add
in interfaceHasComponents
Parameters:
components
- the components to addSee Also:
#addItem(String, ComponentEventListener)
,#addItem(Component, ComponentEventListener)
-
remove
public void remove(Component... components)
Description copied from interface:
HasComponents
Removes the given child components from this component.
Specified by:
remove
in interfaceHasComponents
Parameters:
components
- the components to remove
-
removeAll
public void removeAll()
Removes all contents from this component, this includes child components, text content as well as child elements that have been added directly to this component using the
Element
API. it also removes the children that were added only at the client-side. This also removes all the items added withaddItem(String)
and its overload methods.Specified by:
removeAll
in interfaceHasComponents
-
addComponentAtIndex
public void addComponentAtIndex(int index, Component component)
Adds the given component into this context menu at the given index.
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>
.Specified by:
addComponentAtIndex
in interfaceHasComponents
Parameters:
index
- the index, where the component will be added.component
- the component to add
-
getChildren
public Stream<Component> getChildren()
Gets the child components of this component. This includes components added with
add(Component...)
and theMenuItem
components created withaddItem(String)
and its overload methods.Overrides:
getChildren
in classComponent
Returns:
the child components of this component
See Also:
-
getItems
public List<MenuItem> getItems()
Gets the items added to this component (the children of this component that are instances of
MenuItem
).Returns:
the
MenuItem
components in this context menuSee Also:
#addItem(String, ComponentEventListener)
-
isOpened
public boolean isOpened()
Gets the open state from the context menu.
Returns:
the
opened
property from the context menu
-
addItem
protected MenuItem addItem(String text)
Creates and adds a new item component to this context menu with the given text content.
Parameters:
text
- the text content for the created menu itemReturns:
the created menu item
-
addItem
protected MenuItem addItem(Component component)
Creates and adds a new item component to this context menu with the given component inside.
Parameters:
component
- the component to add to the created menu itemReturns:
the created menu item
-
addOpenedChangeListener
public Registration addOpenedChangeListener(ComponentEventListener<GeneratedVaadinContextMenu.OpenedChangeEvent<C>> listener)
Adds a listener for the
opened-changed
events fired by the web component.Overrides:
addOpenedChangeListener
in classGeneratedVaadinContextMenu<C extends ContextMenuBase<C>>
Parameters:
listener
- the listener to addReturns:
a Registration for removing the event listener
-
-