Classes | |
enum | MoveType |
Public Member Functions | |
MenuTree () | |
void | addMenuItem (SubMenuItem parent, MenuItem item) |
void | addOrUpdateItem (int parentId, MenuItem item) |
Optional< SubMenuItem > | getSubMenuById (int parentId) |
Optional< MenuItem > | getMenuById (int id) |
void | replaceMenuById (MenuItem toReplace) |
void | replaceMenuById (SubMenuItem subMenu, MenuItem toReplace) |
void | moveItem (MenuItem itemMoved, MenuItem newLocation, boolean before) |
int | findIndexOf (SubMenuItem which, MenuItem item) |
void | removeMenuItem (MenuItem toRemove) |
SubMenuItem | findParent (MenuItem toFind) |
void | removeMenuItem (SubMenuItem parent, MenuItem item) |
Set< MenuItem > | getAllSubMenus () |
List< MenuItem > | getMenuItems (MenuItem item) |
Collection< MenuItem > | getAllMenuItems () |
Collection< MenuItem > | getAllMenuItemsFrom (SubMenuItem item) |
void | changeItem (MenuItem item, AnyMenuState menuState) |
void | recurseTreeIteratingOnItems (SubMenuItem root, BiConsumer< MenuItem, SubMenuItem > consumer) |
void | initialiseStateForEachItem () |
Static Public Attributes | |
static final SubMenuItem | ROOT = new SubMenuItem("Root", null, 0, -1, false, true, false, false) |
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.
enum com::thecoderscorner::menu::domain::state::MenuTree::MoveType |
Some operations support moving items up or down in the tree, when they do they use this enumeration to describe the direction of the move.
Enumerator | MOVE_DOWN | MOVE_UP |
---|
com.thecoderscorner.menu.domain.state.MenuTree.MenuTree | ( | ) |
Create a basic tree that is initially empty
void com.thecoderscorner.menu.domain.state.MenuTree.addMenuItem | ( | SubMenuItem | parent, |
MenuItem | item | ||
) |
add a new menu item to a sub menu, for the top level menu use ROOT.
parent | the submenu where this should appear |
item | the item to be added |
void com.thecoderscorner.menu.domain.state.MenuTree.addOrUpdateItem | ( | int | parentId, |
MenuItem | item | ||
) |
This will either add or update an existing item, depending on the ID is already present.
parentId | the parent where it should be placed / already exists |
item | the item to either add or update. |
void com.thecoderscorner.menu.domain.state.MenuTree.changeItem | ( | MenuItem | item, |
AnyMenuState | menuState | ||
) |
Change the value that's associated with a menu item. if you are changing a value, just send a command to the device, it will automatically update the tree.
item | the item to change |
menuState | the new state |
SubMenuItem com.thecoderscorner.menu.domain.state.MenuTree.findParent | ( | MenuItem | toFind | ) |
Finds the submenu that the provided object belongs to.
toFind | the object to find sub menu for. |
Collection<MenuItem> com.thecoderscorner.menu.domain.state.MenuTree.getAllMenuItems | ( | ) |
Gets every menu item held in this menu tree, will be unique
Collection<MenuItem> com.thecoderscorner.menu.domain.state.MenuTree.getAllMenuItemsFrom | ( | SubMenuItem | item | ) |
Gets every menu item held in this menu tree from a given starting point, the starting point is a sub menu, from that submenu, this method will recurse through the rest of the menu structure and provide a complete list. The menu item provided itself will be the first item in the list, the rest will be in exact order as added. Use this method over getAllMenuItems when the order is important, just call with MenuTree.ROOT
to get all items in the tree.
item | the starting point for traversal. |
Set<MenuItem> com.thecoderscorner.menu.domain.state.MenuTree.getAllSubMenus | ( | ) |
Returns all the submenus that are currently stored
Optional<MenuItem> com.thecoderscorner.menu.domain.state.MenuTree.getMenuById | ( | int | id | ) |
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.
id | the id of the object to find. |
Get a list of all menu items for a given submenu
item | the submenu to use |
Optional<SubMenuItem> com.thecoderscorner.menu.domain.state.MenuTree.getSubMenuById | ( | int | parentId | ) |
gets a submenu by its ID. Returns an optional that will be empty when not present
parentId | the parent to obtain |
void com.thecoderscorner.menu.domain.state.MenuTree.initialiseStateForEachItem | ( | ) |
Initialise the state of each menu item to the default value, should be used during initialisation of a local menu application. Will only take effect when there is no state already stored.
void com.thecoderscorner.menu.domain.state.MenuTree.moveItem | ( | MenuItem | itemMoved, |
MenuItem | newLocation, | ||
boolean | before | ||
) |
Moves the item within the menu structure, the new location is either the submenu it should be moved to, or the item it should appear after.
itemMoved | the item that has been moved |
newLocation | the new location in the structure for the item |
before | should be before the new location or after, if newLocation is a submenu it is always after |
void com.thecoderscorner.menu.domain.state.MenuTree.recurseTreeIteratingOnItems | ( | SubMenuItem | root, |
BiConsumer< MenuItem, SubMenuItem > | consumer | ||
) |
Recurse the whole menu tree calling the consumer for each item in turn. This will always be in order so that a child item never comes before its parent.
root | the starting point, normally ROOT |
consumer | the consumer that will be called for each item, providing the item and the parent |
void com.thecoderscorner.menu.domain.state.MenuTree.removeMenuItem | ( | MenuItem | toRemove | ) |
Remove the menu item using this menu item as a prototype (Uses the ID for comparison)
toRemove | the item to remove. |
void com.thecoderscorner.menu.domain.state.MenuTree.removeMenuItem | ( | SubMenuItem | parent, |
MenuItem | item | ||
) |
Remove the menu item for the provided menu item in the provided sub menu.
parent | the submenu to search |
item | the item to remove (Search By ID) |
void com.thecoderscorner.menu.domain.state.MenuTree.replaceMenuById | ( | MenuItem | toReplace | ) |
Replace a menu item with the given ID. Helper to the version of the function that also needs a parent. This is an infrequent operation and not optimised.
toReplace | the item to replace, by ID |
void com.thecoderscorner.menu.domain.state.MenuTree.replaceMenuById | ( | SubMenuItem | subMenu, |
MenuItem | toReplace | ||
) |
Replace the menu item that has a given parent with the one provided. This is an infrequent operation and therefore not optimised.
subMenu | the parent |
toReplace | the menu item to replace by ID |
|
static |
This is the root menu item, the top level item on the display basically