Class MenuBar

All Implemented Interfaces:
Animatable<MenuBar>, CanDrop<MenuBar>, Draggable<MenuBar>

public class MenuBar extends Component<MenuBar> implements Animatable<MenuBar>, CanDrop<MenuBar>, Draggable<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:
  • Constructor Details

  • Method Details

    • setBrand

      public MenuBar setBrand(String brand)
      Sets the text on the left of the menu bar component.
      Parameters:
      brand - Text on the left of the menu bar component If null is set, no text is displayed on the left of the menu bar component.
      Returns:
      Manu bar component
    • setBrand

      public MenuBar setBrand(Icon icon, String brand)
      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 If null is specified, no navbar text icon is displayed. Available icons are listed in the enum Icon.
      brand - Text on the left of the menu bar component If null is set, no text is displayed on the left of the menu bar component.
      Returns:
      Manu bar component
    • setBrand

      public MenuBar setBrand(String brand, ClickEventHandler clickHandler)
      Sets the text on the left of the menu bar component.
      Parameters:
      brand - Text on the left of the menu bar component If null is set, no text is displayed on the top of the navbar component.
      clickHandler - Text click event handler implementation If not specified or null is set, the click event for the navbar left text is not handled.
      Returns:
      Menu bar component
    • setBrand

      public MenuBar setBrand(Image image)
      Sets the image on the left of the menu bar component.
      Parameters:
      image - Image instance on the left of the menu bar component If null is set, no image is displayed on the top of the navbar component.
      Returns:
      Menu bar component
    • setBrand

      public MenuBar setBrand(Image image, ClickEventHandler clickHandler)
      Sets the image on the left of the menu bar component.
      Parameters:
      image - Image instance on the left of the menu bar component If null is set, no image is displayed on the top of the navbar component.
      clickHandler - Image click event handler implementation If not specified or null is set, the click event for the navbar left image is not handled.
      Returns:
      Menu bar component
    • setBrand

      public MenuBar setBrand(Icon icon, String brand, Image image, ClickEventHandler clickHandler)
      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 If null is set, no icon is displayed before the navbar component text. Available icons are listed in the enum Icon.
      brand - Text on the top of the navbar component If null is set, no text is displayed on the left of the menu bar component.
      clickHandler - Text click event handler implementation If not specified or null is set, the click event for the navbar left text is not handled.
      Returns:
      Navbar component
    • getBarndText

      public String 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

      public Icon 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

      public Image 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

      public MenuBarBrand getBrand()
      Gets the brand component from the menu bar.
      Returns:
      Brand component If no brand information is provided, the method returns null.
    • addMenuItem

      public final MenuBar addMenuItem(MenuItem item)
      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

      public final MenuBar addMenuItem(MenuItem item, CurrentUser user)
      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, or null, if there is no logged in user.
      Returns:
      The menu bar component
      See Also:
    • addSearch

      public MenuBar addSearch(NavBarSeachHandler searchHandler)
      Adds a generic search component to the navbar. If you add a search component to the navbar, an input field will appear below the header and above the menu items. Users can specify a search term here. The search must be performed by the NavBarSeachHandler implementation passed to the method.
      The placeholder text that appears on the search component ("Search ...." by default) can be modified or localized using MessageSourceAPI by entering the navBar.searchItemPlaceholder key.
      Parameters:
      searchHandler - Search implementation
      Returns:
      Menu bar component
    • removeSearch

      public MenuBar removeSearch()
      Removes the search component from the navbar.
      Returns:
      Menu bar component
    • setUserPicture

      public MenuBar setUserPicture(String pictureUrl)
      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

      public String 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

      public MenuBar setUsername(String username)
      Sets the username on the menu bar
      Parameters:
      username - Username If null is set, no username is displayed on the component.
      Returns:
      menu bar component
    • getUsername

      public String 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

      public MenuBar setRole(String role)
      Sets the role for menu bar component elements.
      Parameters:
      role - User role If null is set, no user role is set in the menu bar.
      Returns:
      Menu bar component
    • getRole

      public String 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

      public MenuBar setUserStatus(String status)
      Sets the menu bar component’s displayed user status.
      Parameters:
      status - Text status If null is set, no user status text is displayed in the menu bar component.
      Returns:
      Menu bar component
    • getUserStatus

      public String 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 If null is specified, no icon is displayed on the menu item. Available icons are listed in the enum Icon
      text - Menu item text If null 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 is null
    • removeUserMenu

      public MenuBar removeUserMenu()
      Removes the complete user menu from the menu bar.
      Returns:
      Menu bar component
    • setUserMenuItemIcon

      public MenuBar setUserMenuItemIcon(String name, Icon icon)
      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 If null is specified, no icon is displayed on the menu item. Available icons are listed in the enum Icon.
      Returns:
      Menu bar component
    • getUserMenuItemIcon

      public Icon getUserMenuItemIcon(String name)
      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

      public MenuBar setUserMenuItemText(String name, String text)
      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 If null is specified, no text appears on the menu item.
      Returns:
      Menu bar component
    • getUserMenuItemText

      public String getUserMenuItemText(String name)
      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

      public MenuBar removeUserMenuItem(String name)
      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

      public MenuBar removeAllMenuItemsFromTheUserMenu()
      Removes all menu items associated with a user menu.
      Returns:
      Menu bar component
    • buildFromMenu

      public final MenuBar buildFromMenu(String menuName, CurrentUser user)

      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 name
      user - 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 to null.
      Returns:
      The menu bar component.
      See Also:
    • writeHTML

      public boolean writeHTML(StringWriter writer)
      Description copied from class: Component
      Creates the component's HTML equivalent

      This 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 with false. Otherwise, it must return with true.

      Specified by:
      writeHTML in class Component<MenuBar>
      Returns:
      If the componentwas drawn, true, otherwise false
    • afterDraw

      public void afterDraw()
      Description copied from class: Component
      The operations to be executed after the drawing of the component

      By 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.

      Overrides:
      afterDraw in class Component<MenuBar>
    • onOpenPage

      protected void onOpenPage(String pageId)
      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 was null, or if the page id was not found
    • setContainerType

      public MenuBar setContainerType(ContainerType type)
    • getContainerType

      public ContainerType getContainerType()