Class PermissionMenuItemFactory

All Implemented Interfaces:
DynamicActionAttributes, ActionFactory<MenuItemAction>

public class PermissionMenuItemFactory
extends AbstractJspActionFactory<MenuItemAction>
A menu item factory that can hide or disable menu items based on the logged in user's permissions. It is possible to set different text, tooltip, icon, etc. for a disabled menu.

The permissions are checked for a given item type (setItem(String)). Permission levels can be set for when the menu item should be:

  • visible and enabled
  • visible but disabled
  • hidden
If the menu item is hidden this is indicated by returning false from the prepareContext(InvokationContext) method. Most properties can have different values for the enabled/disabled state. For example:
Version:
2.7
Author:
nicklas
Last modified
$Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $
  • Field Details

    • id

      private String id
    • enabledClazz

      private String enabledClazz
    • disabledClazz

      private String disabledClazz
    • type

    • visiblePermission

      private Permission visiblePermission
    • enabledPermission

      private Permission enabledPermission
    • itemToCheck

      private Item itemToCheck
    • enabledIcon

      private String enabledIcon
    • disabledIcon

      private String disabledIcon
    • enabledStyle

      private String enabledStyle
    • disabledStyle

      private String disabledStyle
    • enabledTitle

      private String enabledTitle
    • disabledTitle

      private String disabledTitle
    • enabledTooltip

      private String enabledTooltip
    • disabledTooltip

      private String disabledTooltip
  • Constructor Details

    • PermissionMenuItemFactory

      public PermissionMenuItemFactory()
      Create a new factory instance.
  • Method Details

    • getActions

      public MenuItemAction[] getActions​(InvokationContext<? super MenuItemAction> context)
      Description copied from interface: ActionFactory
      This method may be called one or several times for each request. This is decided by the extension point. If, for example, the extension point is a pure single-item extension point then this method is probably only called once. If the extension point is a per-item extension point in a list context, then this method may be called once for every item in the list. The context parameter contains all information about the context of the extension point, including the current item, if any.
      Parameters:
      context - The current invokation context
      Returns:
      An array of actions that should be added to the extension point. Returns null or an empty array if there are no actions in the current context.
    • prepareContext

      public boolean prepareContext​(InvokationContext<? super MenuItemAction> context)
      Description copied from class: AbstractJspActionFactory
      If scripts and stylesheets has been added to the factory, propagates those to the JspContext. A subclass that overrides this method should call super.prepareContext() if it hasn't decided to return FALSE already.
      Specified by:
      prepareContext in interface ActionFactory<MenuItemAction>
      Overrides:
      prepareContext in class AbstractJspActionFactory<MenuItemAction>
      Parameters:
      context - The current invokation context
      Returns:
      Always TRUE
    • setEnabledPermission

      public void setEnabledPermission​(String permission)
      Set the minimum permission that is required to make the menu item enabled.
      Parameters:
      permission - One of Permission constants
    • setVisiblePermission

      public void setVisiblePermission​(String permission)
      Set the minimum permission that is required to make the menu item visible.
      Parameters:
      permission - One of Permission constants
    • setItem

      public void setItem​(String item)
      Set the item type to check the permission for.
      Parameters:
      item - One of Item constants
    • setEnabledIcon

      @VariableSetter @PathSetter public void setEnabledIcon​(String icon)
      Set the icon to use when the menu is enabled.
    • setDisabledIcon

      @VariableSetter @PathSetter public void setDisabledIcon​(String icon)
      Set the icon to use when the menu is disabled.
    • setIcon

      @VariableSetter @PathSetter public void setIcon​(String icon)
      Set the icon to use in all cases.
    • setMenuId

      public void setMenuId​(String menuId)
    • setId

      public void setId​(String id)
    • setDisabledClazz

      public void setDisabledClazz​(String clazz)
      Set the class to use when the menu is disabled.
    • setEnabledClazz

      public void setEnabledClazz​(String clazz)
      Set the class to use when the menu is enabled.
      Since:
      3.3
    • setEnabledStyle

      public void setEnabledStyle​(String style)
      Set the style to use when the menu is enabled.
    • setDisabledStyle

      public void setDisabledStyle​(String style)
      Set the style to use when the menu is disabled.
    • setStyle

      public void setStyle​(String style)
      Set the style to use in all cases.
    • setSubmenuId

      public void setSubmenuId​(String submenuId)
    • setEnabledTitle

      public void setEnabledTitle​(String title)
      Set the title of the menu item when it is enabled.
    • setDisabledTitle

      public void setDisabledTitle​(String title)
      Set the title of the menu item when it is disabled.
    • setTitle

      public void setTitle​(String title)
      Set the title of the menu item in all cases.
    • setEnabledTooltip

      public void setEnabledTooltip​(String tooltip)
      Set the tooltip of the menu item when it is enabled.
    • setDisabledTooltip

      public void setDisabledTooltip​(String tooltip)
      Set the tooltip of the menu item when it is disabled.
    • setTooltip

      public void setTooltip​(String tooltip)
      Set the tooltip of the menu item in all cases.
    • setType

      public void setType​(MenuItemAction.MenuType type)
      Set the type of the menu.
    • setType

      public void setType​(String type)
      Set the type of menu.
    • hasPermission

      private boolean hasPermission​(SessionControl sc, Permission permission)