Class MenuItem
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdds the specified role to the menu itemAdds the specified roles to the menu itemaddSubMenuItem
(MenuItem item) Adds a new sub-menu item to the menu item.copy()
findByName
(String name) Finds the specified menu item, by using it's name. .Gets the assigned hotkeygetIcon()
Gets the menu item iconGets the assigned marker textGets the assigned marker typegetName()
Gets the menu item nameGets the menu item operationint
getOrder()
Gets the menu item order numberGets the menu item's parentgetRoles()
Gets every role that is assigned to the menu itemgetSubMenuItemByName
(String name) Gets the specified sub-menu itemGets every sub-menu item that is assigned to the menu itemGets the target page idgetTitle()
Gets the menu item titleboolean
Determines if the menu item has any sub-menu itemsboolean
isAccess
(CurrentUser user) Removes the previously assigned hotkeyremoveRole
(String roleCode) Removes the specified role from the menu itemremoveSubMenuItem
(MenuItem subMenuItem) Removes the specified sub-menu item.removeSubMenuItem
(String name) Removes the specified sub-menu item.setClickHandler
(NavigationEventHandler handler) Sets a custom click hanldersetHotKey
(int hotKey) Sets a hotkey to the menu itemSets a marker text and type to the menu itemsetMarkerText
(String markerText) Sets a marker text to the menu itemsetMarkerType
(BadgeType markerType) Sets a marker type to the menu itemfinal MenuItem
setMenuOperation
(MenuOperation operation, String targetPageId) Sets the menu item operationSets the menu item's order.protected MenuItem
protected void
sort()
-
Constructor Details
-
MenuItem
Creates a new menu item- Parameters:
name
- The menu item nameicon
- The menu itemIcon
. If an icon isn't required, specify asnull
title
- The menu item title. If a title isn't required, specify asnull
- Throws:
NullPointerException
- If the name isn't specified
-
MenuItem
Creates a new menu item- Parameters:
name
- The menu item nameicon
- The menu itemIcon
. If an icon isn't required, specify asnull
title
- The menu item title. If a title isn't required, specify asnull
operation
- The menu item operation, which runs when the menu item is clicked. These operations can be found in theMenuOperation
enumtargetPageId
- If the specified operation isMenuOperation.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
Sets the menu item operation- Parameters:
operation
- The on click menu operation. These operations can be found in theMenuOperation
enumtargetPageId
- If the specified operation isMenuOperation.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
Gets the menu item name- Returns:
- The menu item name
-
getIcon
Gets the menu item icon- Returns:
- The menu item
Icon
ornull
, if the menu item has no icon
-
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
Gets the menu item operation- Returns:
- The menu item operation as a
MenuOperation
enum constant
-
getTargetPageId
Gets the target page id- Returns:
- The target page id or
null
, if not specified
-
setParent
- Parameters:
parentMenuItem
- The parent menu item. Ifnull
, the menu item will be a drawn as a root menu item- Returns:
- The menu item POJO class
-
getParent
Gets the menu item's parent- Returns:
- The parent menu item POJO class or
null
, if the menu item has no parent
-
addSubMenuItem
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
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
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
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
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
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 thegetMenuItemByName
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
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
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
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
- Parameters:
user
- The POJO class of the user to be checked- Returns:
true
, if the user has access, otherwisefalse
-
getClickHandler
- Returns:
- The custom handler implementation, or
null
, if there a custom handler implemented
-
setOrder
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
Sets a hotkey to the menu item- Parameters:
hotKey
- The hot key. While setting a hotkey, the constants of theKey
class must be used.- Returns:
- The menu item POJO class
-
getHotKey
Gets the assigned hotkey- Returns:
- The assigned hotkey or
null
, if no hotkey was assigned
-
removeHotKey
Removes the previously assigned hotkey- Returns:
- The menu item POJO class
-
copy
- Returns:
- The new instance, which is a complete copy of the class
-
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
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 itemmarkerType
- The marker type- Returns:
- The menu item POJO class
- See Also:
-
setMarkerText
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
Sets a marker type to the menu item- Parameters:
markerType
- The marker type- Returns:
- The menu item POJO class
- See Also:
-
getMarkerText
Gets the assigned marker text- Returns:
- The assigned marker text or
null
, if no marker was assigned
-
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()
-