Class MenuItemBase<C extends ContextMenuBase<C,I,S>,I extends MenuItemBase<C,I,S>,S extends SubMenuBase<C,I,S>>
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.contextmenu.MenuItemBase<C,I,S>
- Type Parameters:
C- the context menu typeI- the menu item typeS- the sub menu type
- All Implemented Interfaces:
AttachNotifier,DetachNotifier,HasAriaLabel,HasComponents,HasElement,HasEnabled,HasStyle,HasText,Serializable
- Direct Known Subclasses:
GridMenuItem,MenuItem
@Tag("vaadin-context-menu-item")
@NpmPackage(value="@vaadin/polymer-legacy-adapter",
version="24.9.5")
@JsModule("@vaadin/polymer-legacy-adapter/style-modules.js")
public abstract class MenuItemBase<C extends ContextMenuBase<C,I,S>,I extends MenuItemBase<C,I,S>,S extends SubMenuBase<C,I,S>>
extends Component
implements HasAriaLabel, HasComponents, HasEnabled, HasText
Base class for item component used inside
ContextMenus.- Author:
- Vaadin Ltd.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasText
HasText.WhiteSpace -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddThemeNames(String... themeNames) Adds one or more theme names to this item.protected abstract Sprotected voidexecuteJsWhenAttached(String expression, Serializable... parameters) Gets the context menu component that this item belongs to.Gets the sub menu API for this menu item.booleanhasThemeName(String themeName) Checks if the item has the given theme name.booleanGets whether this item toggles a checkmark icon when clicked.booleanGets the checked state of this item.booleanGets whether the item is set to be disabled when clicked.booleanGets whether clicking this item keeps the menu open.booleanGets whether this item has a sub menu attached to it or not.voidremoveThemeNames(String... themeNames) Removes one or more theme names from this item.voidsetCheckable(boolean checkable) Sets the checkable state of this menu item.voidsetChecked(boolean checked) Sets the checked state of this item.voidsetDisableOnClick(boolean disableOnClick) Sets whether the item should be disabled when clicked.voidsetEnabled(boolean enabled) Sets the UI object explicitly disabled or enabled.voidsetKeepOpen(boolean keepOpen) Sets the keep open state of this menu item.Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, 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.HasAriaLabel
getAriaLabel, getAriaLabelledBy, setAriaLabel, setAriaLabelledByMethods inherited from interface com.vaadin.flow.component.HasComponents
add, add, add, addComponentAsFirst, addComponentAtIndex, remove, remove, removeAllMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabledMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasText
getText, getWhiteSpace, setText, setWhiteSpace
-
Constructor Details
-
MenuItemBase
Default constructor- Parameters:
contextMenu- the context menu to which this item belongs to
-
-
Method Details
-
getContextMenu
Gets the context menu component that this item belongs to.- Returns:
- the context-menu component
-
getSubMenu
Gets the sub menu API for this menu item. Adding content to the returned sub menu makes this component a parent item which opens the sub menu overlay. When the sub menu has no content, it won't be rendered.- Returns:
- the sub menu that can be opened via this item
-
isParentItem
public boolean isParentItem()Gets whether this item has a sub menu attached to it or not.- Returns:
trueif this component has a sub menu with content inside it,falseotherwise- See Also:
-
setCheckable
public void setCheckable(boolean checkable) Sets the checkable state of this menu item. A checkable item toggles a checkmark icon when clicked. Changes in the checked state can be handled in the item's click handler withisChecked().Setting a checked item un-checkable also makes it un-checked.
- Parameters:
checkable-trueto enable toggling the checked-state of this menu item by clicking,falseto disable it.- Throws:
IllegalStateException- if setting a parent item checkable
-
isCheckable
public boolean isCheckable()Gets whether this item toggles a checkmark icon when clicked.- Returns:
- the checkable state of the item
- See Also:
-
setChecked
public void setChecked(boolean checked) Sets the checked state of this item. A checked item displays a checkmark icon next to it. The checked state is also toggled by clicking the item.Note that the item needs to be explicitly set as checkable via
setCheckable(boolean)in order to check it.- Parameters:
checked-trueto check this item,falseto un-check it- Throws:
IllegalStateException- if trying to check the item when it's checkable
-
isChecked
public boolean isChecked()Gets the checked state of this item. The item can be checked and un-checked withsetChecked(boolean)or by clicking it when it is checkable. A checked item displays a checkmark icon inside it.- Returns:
trueif the item is checked,falseotherwise- See Also:
-
setKeepOpen
public void setKeepOpen(boolean keepOpen) Sets the keep open state of this menu item. An item that marked as keep open prevents menu from closing when clicked.- Parameters:
keepOpen-trueto enable keeping the menu open when toggle this item selection,falseto disable it.
-
isKeepOpen
public boolean isKeepOpen()Gets whether clicking this item keeps the menu open.- Returns:
- the keep open state of the item
- See Also:
-
setDisableOnClick
public void setDisableOnClick(boolean disableOnClick) Sets whether the item should be disabled when clicked.When set to
true, the item will be immediately disabled on the client-side when clicked, preventing further clicks until re-enabled from the server-side.- Parameters:
disableOnClick- whether the item should be disabled when clicked
-
isDisableOnClick
public boolean isDisableOnClick()Gets whether the item is set to be disabled when clicked.- Returns:
- whether the item is set to be disabled on click
-
setEnabled
public void setEnabled(boolean enabled) Description copied from interface:HasEnabledSets the UI object explicitly disabled or enabled.- Specified by:
setEnabledin interfaceHasEnabled- Parameters:
enabled- iffalsethen explicitly disables the object, iftruethen enables the object so that its state depends on parent
-
addThemeNames
Adds one or more theme names to this item. Multiple theme names can be specified by using multiple parameters.- Parameters:
themeNames- the theme name or theme names to be added to the item
-
removeThemeNames
Removes one or more theme names from this item. Multiple theme names can be specified by using multiple parameters.- Parameters:
themeNames- the theme name or theme names to be removed from the item
-
hasThemeName
Checks if the item has the given theme name.- Parameters:
themeName- the theme name to check for- Returns:
trueif the item has the given theme name,falseotherwise
-
createSubMenu
-
executeJsWhenAttached
-