tcMenuJavaAPI
Classes | Public Member Functions | Static Public Attributes | List of all members
com.thecoderscorner.menu.domain.state.MenuTree Class Reference

Classes

enum  MoveType
 

Public Member Functions

 MenuTree ()
 
void addMenuItem (SubMenuItem parent, MenuItem item)
 
void addOrUpdateItem (int parentId, MenuItem item)
 
Optional< SubMenuItemgetSubMenuById (int parentId)
 
Optional< MenuItemgetMenuById (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< MenuItemgetAllSubMenus ()
 
List< MenuItemgetMenuItems (MenuItem item)
 
Collection< MenuItemgetAllMenuItems ()
 
Collection< MenuItemgetAllMenuItemsFrom (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)
 

Detailed Description

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
MenuItemHelper

Class Documentation

◆ com::thecoderscorner::menu::domain::state::MenuTree::MoveType

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

Constructor & Destructor Documentation

◆ MenuTree()

com.thecoderscorner.menu.domain.state.MenuTree.MenuTree ( )

Create a basic tree that is initially empty

Member Function Documentation

◆ addMenuItem()

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.

Parameters
parentthe submenu where this should appear
itemthe item to be added

◆ addOrUpdateItem()

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.

Parameters
parentIdthe parent where it should be placed / already exists
itemthe item to either add or update.

◆ changeItem()

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.

Parameters
itemthe item to change
menuStatethe new state

◆ findParent()

SubMenuItem com.thecoderscorner.menu.domain.state.MenuTree.findParent ( MenuItem  toFind)

Finds the submenu that the provided object belongs to.

Parameters
toFindthe object to find sub menu for.
Returns
the submenu

◆ getAllMenuItems()

Collection<MenuItem> com.thecoderscorner.menu.domain.state.MenuTree.getAllMenuItems ( )

Gets every menu item held in this menu tree, will be unique

Returns
every menu item in the tree.

◆ getAllMenuItemsFrom()

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.

Parameters
itemthe starting point for traversal.
Returns
every menu item in the tree from the given starting point.

◆ getAllSubMenus()

Set<MenuItem> com.thecoderscorner.menu.domain.state.MenuTree.getAllSubMenus ( )

Returns all the submenus that are currently stored

Returns
all available sub menus

◆ getMenuById()

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.

Parameters
idthe id of the object to find.
Returns
the menu at the given id

◆ getMenuItems()

List<MenuItem> com.thecoderscorner.menu.domain.state.MenuTree.getMenuItems ( MenuItem  item)

Get a list of all menu items for a given submenu

Parameters
itemthe submenu to use
Returns
a list of submenu items that's immutable

◆ getSubMenuById()

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

Parameters
parentIdthe parent to obtain
Returns
an optional that will be populated when present with the sub menu.

◆ initialiseStateForEachItem()

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.

◆ moveItem()

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.

Parameters
itemMovedthe item that has been moved
newLocationthe new location in the structure for the item
beforeshould be before the new location or after, if newLocation is a submenu it is always after

◆ recurseTreeIteratingOnItems()

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.

Parameters
rootthe starting point, normally ROOT
consumerthe consumer that will be called for each item, providing the item and the parent

◆ removeMenuItem() [1/2]

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)

Parameters
toRemovethe item to remove.

◆ removeMenuItem() [2/2]

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.

Parameters
parentthe submenu to search
itemthe item to remove (Search By ID)

◆ replaceMenuById() [1/2]

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.

Parameters
toReplacethe item to replace, by ID

◆ replaceMenuById() [2/2]

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.

Parameters
subMenuthe parent
toReplacethe menu item to replace by ID

Member Data Documentation

◆ ROOT

final SubMenuItem com.thecoderscorner.menu.domain.state.MenuTree.ROOT = new SubMenuItem("Root", null, 0, -1, false, true, false, false)
static

This is the root menu item, the top level item on the display basically


The documentation for this class was generated from the following file: