Class MenuManager<C extends Component,I extends MenuItemBase<?,I,S>,S extends SubMenuBase<?,I,S>>
- java.lang.Object
-
- com.vaadin.flow.component.contextmenu.MenuManager<C,I,S>
-
- Type Parameters:
C- the context menu typeI- the menu item typeS- the sub menu type
- All Implemented Interfaces:
Serializable
public class MenuManager<C extends Component,I extends MenuItemBase<?,I,S>,S extends SubMenuBase<?,I,S>> extends Object implements Serializable
Common management logic for context menus and sub menus. Maintains the list of components to stamp into one overlay.- Author:
- Vaadin Ltd.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description MenuManager(C menu, SerializableRunnable contentReset, SerializableBiFunction<C,SerializableRunnable,I> itemGenerator, Class<I> itemType, I parentMenuItem)Creates a new manager instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Component... components)Adds components to the (sub)menu.voidaddComponentAtIndex(int index, Component component)Inserts component to the (sub)menu using theindex.IaddItem(Component component)Adds a component as a menu item.IaddItem(Component component, ComponentEventListener<ClickEvent<I>> clickListener)Adds a component as a menu item with a click listener.IaddItem(String text)Adds a text as a menu item.IaddItem(String text, ComponentEventListener<ClickEvent<I>> clickListener)Adds a text as a menu item with a click listener.Stream<Component>getChildren()Gets all (sub)menu children.List<I>getItems()Gets all children items.voidremove(Component... components)Removes components to the (sub)menu.voidremoveAll()Remove all components and items from (sub)menu.
-
-
-
Constructor Detail
-
MenuManager
public MenuManager(C menu, SerializableRunnable contentReset, SerializableBiFunction<C,SerializableRunnable,I> itemGenerator, Class<I> itemType, I parentMenuItem)
Creates a new manager instance.- Parameters:
menu- the context menucontentReset- callback to reset the context menuitemGenerator- the item generator/factoryitemType- the item typeparentMenuItem- the parent menu item of the subemnu
-
-
Method Detail
-
addItem
public I addItem(String text)
Adds a text as a menu item.- Parameters:
text- the text for the menu item- Returns:
- a new menu item
-
addItem
public I addItem(Component component)
Adds a component as a menu item.- Parameters:
component- the component for the menu item- Returns:
- a new menu item
-
addItem
public I addItem(String text, ComponentEventListener<ClickEvent<I>> clickListener)
Adds a text as a menu item with a click listener.- Parameters:
text- the text for the menu itemclickListener- a click listener- Returns:
- a new menu item
-
addItem
public I addItem(Component component, ComponentEventListener<ClickEvent<I>> clickListener)
Adds a component as a menu item with a click listener.- Parameters:
component- the component for the menu itemclickListener- a click listener- Returns:
- a new menu item
-
add
public void add(Component... components)
Adds components to the (sub)menu.The components are added into the content as is, they are not wrapped as menu items.
- Parameters:
components- components to add- See Also:
remove(Component...),addComponentAtIndex(int, Component)
-
remove
public void remove(Component... components)
Removes components to the (sub)menu.- Parameters:
components- components to remove- See Also:
add(Component...)
-
removeAll
public void removeAll()
Remove all components and items from (sub)menu.- See Also:
remove(Component...)
-
addComponentAtIndex
public void addComponentAtIndex(int index, Component component)Inserts component to the (sub)menu using theindex.The component is inserted into the content as is, it is not wrapped as a menu item.
- Parameters:
index- index to insert, not negativecomponent- component to insert- See Also:
add(Component...),remove(Component...)
-
getChildren
public Stream<Component> getChildren()
Gets all (sub)menu children.Children consist of components and items.
- Returns:
- the children components
- See Also:
add(Component...),addItem(Component),getItems()
-
getItems
public List<I> getItems()
Gets all children items.The items are filtered using the provided item type in the constructor.
- Returns:
- all children items
- See Also:
getChildren()
-
-