@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
<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>>
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.
|
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.
|
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
addComponentAsFirst
isEnabled, setEnabled
getElement
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
addClickListener
addAttachListener
addDetachListener
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>>
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(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>
.
add
in interface HasComponents
components
- the components to add#addItem(String, ComponentEventListener)
,
#addItem(Component, ComponentEventListener)
public void remove(Component... components)
HasComponents
remove
in interface HasComponents
components
- the components to removepublic void removeAll()
Element
API. it also removes the
children that were added only at the client-side. This also removes all the items added with
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 added.component
- the component to addpublic Stream<Component> getChildren()
add(Component...)
and the MenuItem
components
created with addItem(String)
and its overload methods.getChildren
in class Component
Id
public List<MenuItem> getItems()
MenuItem
).MenuItem
components in this context menu#addItem(String, ComponentEventListener)
public boolean isOpened()
opened
property from the context menuprotected MenuItem addItem(String text)
text
- the text content for the created menu itemprotected MenuItem addItem(Component component)
component
- the component to add to the created menu itempublic Registration addOpenedChangeListener(ComponentEventListener<GeneratedVaadinContextMenu.OpenedChangeEvent<C>> listener)
opened-changed
events fired by the web
component.addOpenedChangeListener
in class GeneratedVaadinContextMenu<C extends ContextMenuBase<C>>
listener
- the listener to addCopyright © 2019. All rights reserved.