Class MenuTree
java.lang.Object
com.thecoderscorner.menu.domain.state.MenuTree
Menu tree holds all the menu items for a specific remote connection or local session. It holds a hierarchy of
items, where items of type submenu can hold other items. As menu items are immutable, the state for each item is
held separately, and can be accessed from here for each item. There are many helper methods on `MenuItemHelper`
that make working with menu items easier.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSome operations support moving items up or down in the tree, when they do they use this enumeration to describe the direction of the move. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SubMenuItemThis is the root menu item, the top level item on the display basically -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMenuItem(SubMenuItem parent, MenuItem item) add a new menu item to a sub menu, for the top level menu use ROOT.voidaddOrUpdateItem(int parentId, MenuItem item) This will either add or update an existing item, depending on the ID is already present.voidchangeItem(MenuItem item, AnyMenuState menuState) Change the value that's associated with a menu item.findParent(MenuItem toFind) Finds the submenu that the provided object belongs to.Gets every menu item held in this menu tree, will be uniqueReturns all the submenus that are currently storedgetMenuById(int id) Gets the menu item with the specified ID, finding the submenu if needed.getMenuItems(MenuItem item) Get a list of all menu items for a given submenu<T extends AnyMenuState>
TgetMenuState(MenuItem item) Gets the menu state that's associated with a given menu item.getSubMenuById(int parentId) gets a submenu by its ID.voidInitialise the state of each menu item to the default value, should be used during initialisation of a local menu application.voidmoveItem(SubMenuItem parent, MenuItem newItem, MenuTree.MoveType moveType) Moves the item either up or down in the list for that submenuvoidrecurseTreeIteratingOnItems(SubMenuItem root, BiConsumer<MenuItem, SubMenuItem> consumer) Recurse the whole menu tree calling the consumer for each item in turn.voidremoveMenuItem(MenuItem toRemove) Remove the menu item using this menu item as a prototype (Uses the ID for comparison)voidremoveMenuItem(SubMenuItem parent, MenuItem item) Remove the menu item for the provided menu item in the provided sub menu.voidreplaceMenuById(MenuItem toReplace) Replace a menu item with the given ID.voidreplaceMenuById(SubMenuItem subMenu, MenuItem toReplace) Replace the menu item that has a given parent with the one provided.
-
Field Details
-
ROOT
This is the root menu item, the top level item on the display basically
-
-
Constructor Details
-
MenuTree
public MenuTree()Create a basic tree that is initially empty
-
-
Method Details
-
getSubMenuById
gets a submenu by its ID. Returns an optional that will be empty when not present- Parameters:
parentId- the parent to obtain- Returns:
- an optional that will be populated when present with the sub menu.
-
getMenuById
Gets the menu item with the specified ID, finding the submenu if needed. In most cases the linkage between ID and item will be cached and therefore fast, if you don't know the sub menu set it to null, and it will be determined.- Parameters:
id- the id of the object to find.- Returns:
- the menu at the given id
-
getAllSubMenus
Returns all the submenus that are currently stored- Returns:
- all available sub menus
-
getAllMenuItems
Gets every menu item held in this menu tree, will be unique- Returns:
- every menu item in the tree.
-
initialiseStateForEachItem
public void initialiseStateForEachItem()Initialise the state of each menu item to the default value, should be used during initialisation of a local menu application.