Class PermissionMenuItemFactory
- java.lang.Object
-
- net.sf.basedb.clients.web.extensions.AbstractJspFactory
-
- net.sf.basedb.clients.web.extensions.AbstractJspActionFactory<MenuItemAction>
-
- net.sf.basedb.clients.web.extensions.menu.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
prepareContext(InvokationContext)
method. Most properties can have different values for the enabled/disabled state. For example:setTitle(String)
sets the title for both statessetDisabledTitle(String)
sets the title for the disabled statesetEnabledTitle(String)
sets the title for the enabled state
- Version:
- 2.7
- Author:
- nicklas
- Last modified
- $Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $
-
-
Field Summary
Fields Modifier and Type Field Description private String
disabledClazz
private String
disabledIcon
private String
disabledStyle
private String
disabledTitle
private String
disabledTooltip
private String
enabledClazz
private String
enabledIcon
private Permission
enabledPermission
private String
enabledStyle
private String
enabledTitle
private String
enabledTooltip
private String
id
private Item
itemToCheck
private String
menuId
private String
submenuId
private MenuItemAction.MenuType
type
private Permission
visiblePermission
-
Constructor Summary
Constructors Constructor Description PermissionMenuItemFactory()
Create a new factory instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MenuItemAction[]
getActions(InvokationContext<? super MenuItemAction> context)
This method may be called one or several times for each request.private boolean
hasPermission(SessionControl sc, Permission permission)
boolean
prepareContext(InvokationContext<? super MenuItemAction> context)
If scripts and stylesheets has been added to the factory, propagates those to theJspContext
.void
setDisabledClazz(String clazz)
Set the class to use when the menu is disabled.void
setDisabledIcon(String icon)
Set the icon to use when the menu is disabled.void
setDisabledStyle(String style)
Set the style to use when the menu is disabled.void
setDisabledTitle(String title)
Set the title of the menu item when it is disabled.void
setDisabledTooltip(String tooltip)
Set the tooltip of the menu item when it is disabled.void
setEnabledClazz(String clazz)
Set the class to use when the menu is enabled.void
setEnabledIcon(String icon)
Set the icon to use when the menu is enabled.void
setEnabledPermission(String permission)
Set the minimum permission that is required to make the menu item enabled.void
setEnabledStyle(String style)
Set the style to use when the menu is enabled.void
setEnabledTitle(String title)
Set the title of the menu item when it is enabled.void
setEnabledTooltip(String tooltip)
Set the tooltip of the menu item when it is enabled.void
setIcon(String icon)
Set the icon to use in all cases.void
setId(String id)
void
setItem(String item)
Set the item type to check the permission for.void
setMenuId(String menuId)
void
setStyle(String style)
Set the style to use in all cases.void
setSubmenuId(String submenuId)
void
setTitle(String title)
Set the title of the menu item in all cases.void
setTooltip(String tooltip)
Set the tooltip of the menu item in all cases.void
setType(String type)
Set the type of menu.void
setType(MenuItemAction.MenuType type)
Set the type of the menu.void
setVisiblePermission(String permission)
Set the minimum permission that is required to make the menu item visible.-
Methods inherited from class net.sf.basedb.clients.web.extensions.AbstractJspFactory
getDynamicActionAttributes, getParameter, getScripts, getStylesheets, prepareContext, setParameter, setScript, setStylesheet
-
-
-
-
Field Detail
-
id
private String id
-
enabledClazz
private String enabledClazz
-
disabledClazz
private String disabledClazz
-
type
private MenuItemAction.MenuType type
-
menuId
private String menuId
-
submenuId
private String submenuId
-
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
-
-
Method Detail
-
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 theJspContext
. A subclass that overrides this method should callsuper.prepareContext()
if it hasn't decided to return FALSE already.- Specified by:
prepareContext
in interfaceActionFactory<MenuItemAction>
- Overrides:
prepareContext
in classAbstractJspActionFactory<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 ofPermission
constants
-
setVisiblePermission
public void setVisiblePermission(String permission)
Set the minimum permission that is required to make the menu item visible.- Parameters:
permission
- One ofPermission
constants
-
setItem
public void setItem(String item)
Set the item type to check the permission for.- Parameters:
item
- One ofItem
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)
-
-