2.17.2: 2011-06-17

net.sf.basedb.clients.web.extensions.menu
Class PermissionMenuItemFactory

java.lang.Object
  extended by net.sf.basedb.clients.web.extensions.AbstractJspFactory
      extended by net.sf.basedb.clients.web.extensions.AbstractJspActionFactory<MenuItemAction>
          extended by net.sf.basedb.clients.web.extensions.menu.PermissionMenuItemFactory
All Implemented Interfaces:
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:

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 Summary
private  String disabledIcon
           
private  String disabledStyle
           
private  String disabledTitle
           
private  String disabledTooltip
           
private  String enabledIcon
           
private  Permission enabledPermission
           
private  String enabledStyle
           
private  String enabledTitle
           
private  String enabledTooltip
           
private  Item itemToCheck
           
private  String menuId
           
private  String onClick
           
private  String submenuId
           
private  MenuItemAction.MenuType type
           
private  Permission visiblePermission
           
 
Constructor Summary
PermissionMenuItemFactory()
          Create a new factory instance.
 
Method Summary
 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 the JspContext.
 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 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 setItem(String item)
          Set the item type to check the permission for.
 void setMenuId(String menuId)
           
 void setOnClick(String onClick)
          Set the javascript action to call when the menu is clicked.
 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(MenuItemAction.MenuType type)
          Set the type of the menu.
 void setType(String type)
          Set the type of 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
getScripts, getStylesheets, prepareContext, setScript, setStylesheet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

onClick

private String onClick

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
Constructor Detail

PermissionMenuItemFactory

public PermissionMenuItemFactory()
Create a new factory instance.

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 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)

setOnClick

@VariableSetter
public void setOnClick(String onClick)
Set the javascript action to call when the menu is clicked.


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)

2.17.2: 2011-06-17