Class MenuItem

java.lang.Object
com.jbstrap.core.cache.MenuItem

public class MenuItem extends Object

The menu item POJO class

This class stores the attributes of the menu items. Using these, a menu can be created easily. These can be used with both the MenuBar, and the NavBar components

Since:
4.0
Author:
JBStrap
  • Constructor Details

    • MenuItem

      public MenuItem(String name, Icon icon, String title)
      Creates a new menu item
      Parameters:
      name - The menu item name
      icon - The menu item Icon. If an icon isn't required, specify as null
      title - The menu item title. If a title isn't required, specify as null
      Throws:
      NullPointerException - If the name isn't specified
    • MenuItem

      public MenuItem(String name, Icon icon, String title, MenuOperation operation, String targetPageId)
      Creates a new menu item
      Parameters:
      name - The menu item name
      icon - The menu item Icon. If an icon isn't required, specify as null
      title - The menu item title. If a title isn't required, specify as null
      operation - The menu item operation, which runs when the menu item is clicked. These operations can be found in the MenuOperation enum
      targetPageId - If the specified operation is MenuOperation.OPEN_PAGE, the page ID of the page that has to be opened, can be specified here. This type of navigation will clear the list of previously opened pages.
      Throws:
      NullPointerException - If the menu item name, or menu operation is not specified
  • Method Details

    • setMenuOperation

      public final MenuItem setMenuOperation(MenuOperation operation, String targetPageId)
      Sets the menu item operation
      Parameters:
      operation - The on click menu operation. These operations can be found in the MenuOperation enum
      targetPageId - If the specified operation is MenuOperation.OPEN_PAGE, the page ID of the page that has to be opened, can be specified here. This type of navigation will clear the list of previously opened pages.
      Returns:
      The menu item POJO class
      Throws:
      NullPointerException - If the menu operation was not specified
    • getName

      public String getName()
      Gets the menu item name
      Returns:
      The menu item name
    • getIcon

      public Icon getIcon()
      Gets the menu item icon
      Returns:
      The menu item Icon or null, if the menu item has no icon
    • getTitle

      public String getTitle()
      Gets the menu item title
      Returns:
      The menu item title. If the menu item has no title, it will return an empty string
    • getOperation

      public MenuOperation getOperation()
      Gets the menu item operation
      Returns:
      The menu item operation as a MenuOperation enum constant
    • getTargetPageId

      public String getTargetPageId()
      Gets the target page id
      Returns:
      The target page id or null, if not specified
    • setParent

      protected MenuItem setParent(MenuItem parentMenuItem)
      Parameters:
      parentMenuItem - The parent menu item. If null, the menu item will be a drawn as a root menu item
      Returns:
      The menu item POJO class
    • getParent

      public MenuItem getParent()
      Gets the menu item's parent
      Returns:
      The parent menu item POJO class or null, if the menu item has no parent
    • addSubMenuItem

      public MenuItem addSubMenuItem(MenuItem item)
      Adds a new sub-menu item to the menu item. The sub-menu items appear under the parent menu item
      Parameters:
      item - The sub-menu item POJO class
      Returns:
      The menu item POJO class
    • getSubMenuItems

      public List<MenuItem> getSubMenuItems()
      Gets every sub-menu item that is assigned to the menu item
      Returns:
      A list of every assigned sub-menu item. If there are none, it will return with an empty list
    • hasSubMenuItems

      public boolean hasSubMenuItems()
      Determines if the menu item has any sub-menu items
      Returns:
      true if there are sub-menu items assigned to the menu item, false if there aren't any
    • getSubMenuItemByName

      public MenuItem getSubMenuItemByName(String name)
      Gets the specified sub-menu item
      Parameters:
      name - The sub-menu item name
      Returns:
      The sub-menu item POJO class or null, if it's not found
    • removeSubMenuItem

      public MenuItem removeSubMenuItem(String name)
      Removes the specified sub-menu item.
      Parameters:
      name - The name of the sub-menu item that needs to be removed
      Returns:
      The menu item POJO class
    • removeSubMenuItem

      public MenuItem removeSubMenuItem(MenuItem subMenuItem)
      Removes the specified sub-menu item.
      Parameters:
      subMenuItem - The sub-menu item POJO class, which is to be removed. The operation will only run if the specified class is among the sub-menu items.
      Returns:
      The menu item POJO class
    • findByName

      public MenuItem findByName(String name)
      Finds the specified menu item, by using it's name. . The method won't only look for it under the menu item's sub-menu items, but also under the sub-menu item's sub-menu items (IE, the found menu item won't be necessarily a direct sub-menu item of the menu item). If you only want to look under a specific menu item's sub-menu items, use the getMenuItemByName method
      Parameters:
      name - The name of the menu item to be found
      Returns:
      The specified menu item POJO class or null if the specified menu item is not found
    • addRole

      public MenuItem addRole(String roleCode)

      Adds the specified role to the menu item

      If a menu item has multiple roles assigned to it, the menu item will only appear, if the user is logged in, and has access to at least one of the roles, that are assigned to the menu item.

      Parameters:
      roleCode - The role code
      Returns:
      The menu item POJO class
      See Also:
    • addRoles

      public MenuItem addRoles(String... roleCodes)

      Adds the specified roles to the menu item

      If a menu item has multiple roles assigned to it, the menu item will only appear, if the user is logged in, and has access to at least one of the roles, that are assigned to the menu item.

      Parameters:
      roleCodes - The role codes
      Returns:
      The menu item POJO class
      See Also:
    • removeRole

      public MenuItem removeRole(String roleCode)
      Removes the specified role from the menu item
      Parameters:
      roleCode - The code of the role to be removed
      Returns:
      The menu item POJO class
    • isAccess

      public boolean isAccess(CurrentUser user)
      Parameters:
      user - The POJO class of the user to be checked
      Returns:
      true, if the user has access, otherwise false
    • setClickHandler

      public MenuItem setClickHandler(NavigationEventHandler handler)

      Sets a custom click hanlder

      If the menu item has a custom click handler assigned to it, the menu operation automatically switches to MenuOperation.CUSTOM_EVENT. This means that the previously assigned operation won't run. If a menu item has it's custom handler and the menu item is supposed to open a page, that must also be done by the handler

      Parameters:
      handler - The click handler implementation
      Returns:
      The menu item POJO class
    • getClickHandler

      public NavigationEventHandler getClickHandler()
      Returns:
      The custom handler implementation, or null, if there a custom handler implemented
    • setOrder

      public MenuItem setOrder(Number order)

      Sets the menu item's order. It goes from smallest to largest. If there are multiple menu items with the same order number, They will appear in the order they were added to the menu

      The default order is 0

      Parameters:
      order - The order number
      Returns:
      The menu item POJO class
    • getOrder

      public int getOrder()
      Gets the menu item order number
      Returns:
      The menu item order number
    • setHotKey

      public MenuItem setHotKey(int hotKey)
      Sets a hotkey to the menu item
      Parameters:
      hotKey - The hot key. While setting a hotkey, the constants of the Key class must be used.
      Returns:
      The menu item POJO class
    • getHotKey

      public Integer getHotKey()
      Gets the assigned hotkey
      Returns:
      The assigned hotkey or null, if no hotkey was assigned
    • removeHotKey

      public MenuItem removeHotKey()
      Removes the previously assigned hotkey
      Returns:
      The menu item POJO class
    • copy

      public MenuItem copy()
      Returns:
      The new instance, which is a complete copy of the class
    • getRoles

      public List<String> getRoles()
      Gets every role that is assigned to the menu item
      Returns:
      A list of every role that was assigned to the menu item. If there are none, returns with an empty list
    • setMarker

      public MenuItem setMarker(String markerText, BadgeType markerType)
      Sets a marker text and type to the menu item
      Parameters:
      markerText - The marker text, if set null, the marker is not visible on the menu item
      markerType - The marker type
      Returns:
      The menu item POJO class
      See Also:
    • setMarkerText

      public MenuItem setMarkerText(String markerText)
      Sets a marker text to the menu item
      Parameters:
      markerText - The marker text, if set null, the marker is not visible on the menu item
      Returns:
      The menu item POJO class
    • setMarkerType

      public MenuItem setMarkerType(BadgeType markerType)
      Sets a marker type to the menu item
      Parameters:
      markerType - The marker type
      Returns:
      The menu item POJO class
      See Also:
    • getMarkerText

      public String getMarkerText()
      Gets the assigned marker text
      Returns:
      The assigned marker text or null, if no marker was assigned
    • getMarkerType

      public BadgeType getMarkerType()
      Gets the assigned marker type
      Returns:
      The assigned marker type or null, if no marker was assigned or marker type is not definied
    • sort

      protected void sort()