Class MenuBar
Menu bar component for the JBStrap framework
The component places a menu bar on the top of the page. The menu bar can build itself automatically, based on the
menus, created in the Startup
class. The component also accounts for the logged in user's access rights, when building the menu.
Menu items can also be added through custom implementations.
The menu items on the component can contain submenu items, which are placed under their parent (root) menu item. Moreover, custom event handling can be assigned to each individual menu item, if the item is not used for navigation.
Supported events:
AnimationStart
AnimationEnd
,
Drop
,
DragStart
,
DragEnd
- Since:
- 4.0
- Author:
- JBStrap
- See Also:
-
Field Summary
Fields inherited from class com.jbstrap.ui.Component
animation, attributes, backgroundColor, borderColor, color, defaultHotKeyHandler, handlers, hotKeys, styleClasses, textAlign, toolTip, toolTipPosition
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal MenuBar
addMenuItem
(MenuItem item) Adds a menu item to the menu bar component.final MenuBar
addMenuItem
(MenuItem item, CurrentUser user) Adds a menu item to the navigation menu.addMenuItemToUserMenu
(String name, Icon icon, String text, ClickEventHandler clickHandler) Adds a new custom menu item to the user menu bar.addSearch
(NavBarSeachHandler searchHandler) Adds a generic search component to the navbar.void
The operations to be executed after the drawing of the componentfinal MenuBar
buildFromMenu
(String menuName, CurrentUser user) Creates a menu bar component, based on the specified menu.Gets the brand icon on the top left the menu bar component.Gets the brand text on the top left the menu bar component.getBrand()
Gets the brand component from the menu bar.Gets the brand image on the top left the menu bar component.getRole()
Gets the user role assigned to the menu bar.getUserMenuItemIcon
(String name) Gets a menu item icon from a user menu.getUserMenuItemText
(String name) Gets a menu item icon from a user menu.Gets the username displayed on the menu bar.Gets the user’s avatar image.Gets the user status text in the menu bar.protected void
onOpenPage
(String pageId) The default navigation event handler, that will navigate to the specified page.Removes all menu items associated with a user menu.Removes the search component from the navbar.Removes the complete user menu from the menu bar.removeUserMenuItem
(String name) Removes a menu item from the user menu by referencing its name.Sets the image on the left of the menu bar component.setBrand
(Image image, ClickEventHandler clickHandler) Sets the image on the left of the menu bar component.Sets the text on the left of the menu bar component.setBrand
(Icon icon, String brand, Image image, ClickEventHandler clickHandler) Sets the text on the left of the menu bar component.Sets the text on the left of the menu bar component.setBrand
(String brand, ClickEventHandler clickHandler) Sets the text on the left of the menu bar component.Sets the role for menu bar component elements.setUserMenuItemIcon
(String name, Icon icon) Sets an icon for a user menu item.setUserMenuItemText
(String name, String text) Sets a text for the user menu item.setUsername
(String username) Sets the username on the menu barsetUserPicture
(String pictureUrl) Sets the avatar image displayed in the menu bar.setUserStatus
(String status) Sets the menu bar component’s displayed user status.boolean
writeHTML
(StringWriter writer) Creates the component's HTML equivalentMethods inherited from class com.jbstrap.ui.Component
_hide, _setAttribute, addAllowedRole, addComponent, addComponent, addComponents, addDeniedRole, addHandler, addStyle, addStyleClass, addStyleClasses, clearfix, closeTag, combinateAccess, containsStyle, containsStyleClass, draw, drawSubComponents, error, flattendComponentTree, getAccess, getAccessMode, getAllowedRoles, getAttribute, getAttributes, getBackgroundColor, getBorderColor, getClient, getComponentById, getComponents, getComponents, getComponentsByClass, getData, getDeniedRoles, getHandlers, getId, getLanguageCode, getName, getParent, getParent, getRegisteredEvents, getStyle, getStyleClasses, getTextAlign, getTextColor, getToolTip, getToolTipPosition, getTypeName, getUI, init, insertComponentAfter, insertComponentBefore, isAccess, isDrawn, isEnabled, isEventBubbling, isVisible, onHide, onHotKeyEventHandler, onShow, openTag, redraw, removeAllComponents, removeAllowedRole, removeAllStyleClasses, removeAttribute, removeComponent, removeComponent, removeComponents, removeDeniedRole, removeHandler, removeStyle, removeStyle, removeStyleClass, removeStyleClasses, replaceComponent, replaceStyleClass, runAfterDraw, runJavaScript, runJavaScript, runJavaScript, runOnHide, runOnShow, say, setAttribute, setBackgroundColor, setBorder, setBorderColor, setData, setDisplayType, setEnabled, setEventBubbling, setFlex, setFloating, setHeight100, setHeight25, setHeight50, setHeight75, setHeightAuto, setLanguage, setMargin, setName, setOverflow, setPadding, setParent, setScrollable, setSelectionType, setShadow, setStyle, setTextAlign, setTextColor, setToolTip, setToolTipPosition, setVisible, setWidth100, setWidth25, setWidth50, setWidth75, setWidthAuto, showNotification, showNotification, showProcessIndicator, toggleStyleClass
Methods inherited from class com.jbstrap.core.messagebus.MessageBus
closeMessageBus, messageBusOpened, openMessageBus, renewSubscription, sendMessageToMessageBus, subscribeMessageBus, unsubscribeAllListeners, unsubscribeMessageBus
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.jbstrap.ui.Animatable
addAnimationEndHandler, addAnimationStartHandler, getAnimation, removeAnimation, setAnimation
Methods inherited from interface com.jbstrap.ui.CanDrop
addDropEventHandler
Methods inherited from interface com.jbstrap.ui.Draggable
addDragEndEventHandler, addDragStartEventHandler, setDraggable
-
Constructor Details
-
MenuBar
public MenuBar()Creates an empty menu bar component. -
MenuBar
Creates a menu bar component, based on the specified menu.
The menu items will be built from the specified menu, and they will be placed on the component. The menu items can be parameterized by using the
JBStrap.addMenuItem
method.- Parameters:
menuName
- The referenced menu's name- See Also:
-
MenuBar
Creates a menu bar component, based on the specified menu. The user can also be specified.
The menu items will be built from the specified menu, and they will be placed on the component. The menu items can be parameterized by using the
JBStrap.addMenuItem
method Only those menus will be placed on the component, that the specified user can access. If the user has no access to menu item, those will be ignored, and they will not be placed on the component.- Parameters:
menuName
- The referenced menu's nameuser
- The name of the user, whose access rights will be used to build the menu.- See Also:
-
-
Method Details
-
setBrand
Sets the text on the left of the menu bar component.- Parameters:
brand
- Text on the left of the menu bar component Ifnull
is set, no text is displayed on the left of the menu bar component.- Returns:
- Manu bar component
-
setBrand
Sets the text on the left of the menu bar component.- Parameters:
icon
- The icon appearing before the text on the left of the menu bar Ifnull
is specified, no navbar text icon is displayed. Available icons are listed in the enumIcon
.brand
- Text on the left of the menu bar component Ifnull
is set, no text is displayed on the left of the menu bar component.- Returns:
- Manu bar component
-
setBrand
Sets the text on the left of the menu bar component.- Parameters:
brand
- Text on the left of the menu bar component Ifnull
is set, no text is displayed on the top of the navbar component.clickHandler
- Text click event handler implementation If not specified ornull
is set, the click event for the navbar left text is not handled.- Returns:
- Menu bar component
-
setBrand
Sets the image on the left of the menu bar component.- Parameters:
image
- Image instance on the left of the menu bar component Ifnull
is set, no image is displayed on the top of the navbar component.- Returns:
- Menu bar component
-
setBrand
Sets the image on the left of the menu bar component.- Parameters:
image
- Image instance on the left of the menu bar component Ifnull
is set, no image is displayed on the top of the navbar component.clickHandler
- Image click event handler implementation If not specified ornull
is set, the click event for the navbar left image is not handled.- Returns:
- Menu bar component
-
setBrand
Sets the text on the left of the menu bar component.- Parameters:
icon
- The icon appearing before the text on the left of the menu bar Ifnull
is set, no icon is displayed before the navbar component text. Available icons are listed in the enumIcon
.brand
- Text on the top of the navbar component Ifnull
is set, no text is displayed on the left of the menu bar component.clickHandler
- Text click event handler implementation If not specified ornull
is set, the click event for the navbar left text is not handled.- Returns:
- Navbar component
-
getBarndText
Gets the brand text on the top left the menu bar component.- Returns:
- The brand text on the left of the menu bar or
null
if no brand text is displayed on the left of the menu bar
-
getBarndIcon
Gets the brand icon on the top left the menu bar component.- Returns:
- The brand icon on the left of the menu bar or
null
if no brand icon is displayed on the left of the menu bar
-
getBrandImage
Gets the brand image on the top left the menu bar component.- Returns:
- The brand image on the left of the menu bar or
null
if no brand image is displayed on the left of the menu bar
-
getBrand
Gets the brand component from the menu bar.- Returns:
- Brand component If no brand information is provided, the method returns
null
.
-
addMenuItem
Adds a menu item to the menu bar component.- Parameters:
item
- The menu item that is to be added to the menu bar component. This item is always visible for the user.- Returns:
- The menu bar component.
- See Also:
-
addMenuItem
Adds a menu item to the navigation menu. If the specified user has no access rights to the menu item, the method won't do anything.- Parameters:
item
- The menu item to be added. The item specified here will be a root level menu item.user
- The logged in user, ornull
, if there is no logged in user.- Returns:
- The menu bar component
- See Also:
-
removeSearch
Removes the search component from the navbar.- Returns:
- Menu bar component
-
setUserPicture
Sets the avatar image displayed in the menu bar.- Parameters:
pictureUrl
- Relative URL for navbar header image The URL specified here must be relative to the application URL.- Returns:
- Menu bar component
-
getUserPicture
Gets the user’s avatar image.- Returns:
- Relative URL of the user’s avatar image or
null
if there is no avatar set
-
setUsername
Sets the username on the menu bar- Parameters:
username
- Username Ifnull
is set, no username is displayed on the component.- Returns:
- menu bar component
-
getUsername
Gets the username displayed on the menu bar.- Returns:
- Username displayed in the menu bar or
null
if no username is displayed in the menu bar
-
setRole
Sets the role for menu bar component elements.- Parameters:
role
- User role Ifnull
is set, no user role is set in the menu bar.- Returns:
- Menu bar component
-
getRole
Gets the user role assigned to the menu bar.- Returns:
- The user role or
null
if no user role is present in the menu bar
-
setUserStatus
Sets the menu bar component’s displayed user status.- Parameters:
status
- Text status Ifnull
is set, no user status text is displayed in the menu bar component.- Returns:
- Menu bar component
-
getUserStatus
Gets the user status text in the menu bar.- Returns:
- User status text or
null
if no user status text is displayed
-
addMenuItemToUserMenu
public MenuBar addMenuItemToUserMenu(String name, Icon icon, String text, ClickEventHandler clickHandler) Adds a new custom menu item to the user menu bar.- Parameters:
name
- Unique name of the menu item (required)icon
- Menu item icon Ifnull
is specified, no icon is displayed on the menu item. Available icons are listed in the enumIcon
text
- Menu item text Ifnull
is specified, no text appears on the menu item.clickHandler
- Event handler method to be used when clicking on a menu item- Returns:
- A menu bar component
- Throws:
NullPointerException
- Thrown if the specified menu item name isnull
-
removeUserMenu
Removes the complete user menu from the menu bar.- Returns:
- Menu bar component
-
setUserMenuItemIcon
Sets an icon for a user menu item.- Parameters:
name
- Menu item name If you specify a name that is not included in the user menu, no action is taken.icon
- Menu item icon Ifnull
is specified, no icon is displayed on the menu item. Available icons are listed in the enumIcon
.- Returns:
- Menu bar component
-
getUserMenuItemIcon
Gets a menu item icon from a user menu.- Parameters:
name
- Menu item name- Returns:
- Menu item icon or
null
, if there is no menu item with the specified name in the user menu or there is no icon set
-
setUserMenuItemText
Sets a text for the user menu item.- Parameters:
name
- Menu item name If there is no menu item with the specified name, the method does not perform any action.text
- Menu item text Ifnull
is specified, no text appears on the menu item.- Returns:
- Menu bar component
-
getUserMenuItemText
Gets a menu item icon from a user menu.- Parameters:
name
- Menu item name- Returns:
- Menu item icon or
null
, if there is no menu item with the specified name in the user menu or there is no menu item text
-
removeUserMenuItem
Removes a menu item from the user menu by referencing its name.- Parameters:
name
- Menu item name If there is no menu item with the specified name, the method does not perform any action.- Returns:
- Menu bar component
-
removeAllMenuItemsFromTheUserMenu
Removes all menu items associated with a user menu.- Returns:
- Menu bar component
-
buildFromMenu
Creates a menu bar component, based on the specified menu. The user can also be specified.
The menu items will be built from the specified menu, and they will be placed on the component. The menu items can be parameterized by using the
JBStrap.addMenuItem
method Only those menus will be placed on the component, that the specified user can access. If the user has no access to menu item, those will be ignored, and they will not be placed on the component.- Parameters:
menuName
- The referenced menu's nameuser
- The name of the user, whose access rights will be used to build the menu. If there is no logged in user, it can be set tonull
.- Returns:
- The menu bar component.
- See Also:
-
writeHTML
Description copied from class:Component
Creates the component's HTML equivalentThis method doesn't need to be used during application development. This method is used when developing a custom component. When creating a custom component, this method needs to be implemented. In the parameter (
StringWriter
class) the component's HTML equivalent must be specified, and the method has to return with a Boolean value. This boolean value determines if the component was drawn. If the user doesn't have access right to the component, or if the component couldn't be drawn, it should return withfalse
. Otherwise, it must return withtrue
. -
afterDraw
public void afterDraw()Description copied from class:Component
The operations to be executed after the drawing of the componentBy default, this is an empty method. It has to be overwritten on a component or page if additional operations have to be executed after the drawing process. One such operation is data retrieval, which shouldn't run in constructors so that the user could see results of an operation or navigation process.
-
onOpenPage
The default navigation event handler, that will navigate to the specified page.- Parameters:
pageId
- The id of the page- Throws:
NullPointerException
- If the specified page id wasnull
, or if the page id was not found
-
setContainerType
-
getContainerType
-