Class MenuTree


  • public class MenuTree
    extends java.lang.Object
    Menu tree holds all the menu items for a specific remote connection or session. It holds a hierarchy of items, where some items of type submenu can hold other items.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  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.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static SubMenuItem ROOT
      This is the root menu item, the top level item on the display basically
    • Constructor Summary

      Constructors 
      Constructor Description
      MenuTree()
      Create a basic tree that is initially empty
    • Field Detail

      • ROOT

        public static final SubMenuItem ROOT
        This is the root menu item, the top level item on the display basically
    • Constructor Detail

      • MenuTree

        public MenuTree()
        Create a basic tree that is initially empty
    • Method Detail

      • addMenuItem

        public void addMenuItem​(SubMenuItem parent,
                                MenuItem item)
        add a new menu item to a sub menu, for the top level menu use ROOT.
        Parameters:
        parent - the submenu where this should appear
        item - the item to be added
      • addOrUpdateItem

        public void addOrUpdateItem​(int parentId,
                                    MenuItem item)
        This will either add or update an existing item, depending if the ID is already present.
        Parameters:
        parentId - the parent where it should be placed / already exists
        item - the item to either add or update.
      • getSubMenuById

        public java.util.Optional<SubMenuItem> getSubMenuById​(int parentId)
        gets a submenu by it's 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

        public java.util.Optional<MenuItem> getMenuById​(SubMenuItem root,
                                                        int id)
        Gets the menu item with the specified ID, in a given submenu. If you don't know the sub menu call the findMenuItem to obtain the parent.
        Parameters:
        root - the sub menu
        id - the id of the object to find.
        Returns:
      • replaceMenuById

        public void replaceMenuById​(MenuItem toReplace)
        Replace a menu item with the given ID. Helper to the version of the function that also needs a parent.
        Parameters:
        toReplace - the item to replace, by ID
      • replaceMenuById

        public void replaceMenuById​(SubMenuItem subMenu,
                                    MenuItem toReplace)
        Replace the menu item that has a given parent with the one provided
        Parameters:
        subMenu - the parent
        toReplace - the menu item to replace by ID
      • moveItem

        public void moveItem​(SubMenuItem parent,
                             MenuItem newItem,
                             MenuTree.MoveType moveType)
        Moves the item either up or down in the list for that submenu
        Parameters:
        parent - the parent id
        newItem - the item to move
        moveType - the direction of the move.
      • removeMenuItem

        public void removeMenuItem​(MenuItem toRemove)
        Remove the menu item using this menu item as a prototype (Uses the ID for comparison)
        Parameters:
        toRemove - the item to remove.
      • findParent

        public SubMenuItem findParent​(MenuItem toFind)
        Finds the submenu that the provided object belongs to.
        Parameters:
        toFind - the object to find sub menu for.
        Returns:
        the submenu
      • removeMenuItem

        public void removeMenuItem​(SubMenuItem parent,
                                   MenuItem item)
        Remove the menu item for the provided menu item in the provided sub menu.
        Parameters:
        parent - the submenu to search
        item - the item to remove (Search By ID)
      • getAllSubMenus

        public java.util.Set<MenuItem> getAllSubMenus()
        Returns all the submenus that are currently stored
        Returns:
        all available sub menus
      • getMenuItems

        public java.util.List<MenuItem> getMenuItems​(MenuItem item)
        Get a list of all menu items for a given submenu
        Parameters:
        item - the submenu to use
        Returns:
        a list of submenu items that's immutable
      • changeItem

        public <T> void changeItem​(MenuItem<T> item,
                                   MenuState<T> 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.
        Type Parameters:
        T - the type of the state, picked up automatically
        Parameters:
        item - the item to change
        menuState - the new state
      • getMenuState

        public <T> MenuState<T> getMenuState​(MenuItem<T> item)
        Gets the menu state that's associated with a given menu item. This is the current value for the menu item.
        Type Parameters:
        T - determined automatically
        Parameters:
        item - the item which the state belongs to
        Returns:
        the state for the given menu item