2.17.2: 2011-06-17

net.sf.basedb.clients.web.extensions.toolbar
Class PermissionButtonFactory

java.lang.Object
  extended by net.sf.basedb.clients.web.extensions.AbstractJspFactory
      extended by net.sf.basedb.clients.web.extensions.AbstractJspActionFactory<ButtonAction>
          extended by net.sf.basedb.clients.web.extensions.toolbar.PermissionButtonFactory
All Implemented Interfaces:
ActionFactory<ButtonAction>

public class PermissionButtonFactory
extends AbstractJspActionFactory<ButtonAction>

A button factory that can hide or disable button items based on the logged in user's permissions. It is possible to set different text, tooltip, icon, etc. for a disabled button.

If the ClientContext has a current item that is an AccessControlled item permissions are checked against that item: AccessControlled.hasPermission(Permission). If no item type has been specified with setItem(String) the factory will accept any kind of item, otherwise it will only generate button actions if the item type matches.

If the ClientContext doesn't have a current item, the factory checks the role-based permissions with SessionControl.hasPermission(Permission, Item).

Permission levels can be set for when the button should be:

If the button is hidden this is indicated by returning false from the AbstractJspActionFactory.prepareContext(InvokationContext) method. Most properties can have different values for the enabled/disabled state. For example:

The default settings will accept all items that the user has read access to and make the button visible and enabled.

If the extension point supports scripts and stylesheets, use the AbstractJspFactory.setScript(String) and AbstractJspFactory.setStylesheet(String) methods. Each call to these methods will add the argument to a set. Use the AbstractJspFactory.getScripts() and AbstractJspFactory.getStylesheets() methods to gain access to the sets, for example, to remove added items.

Version:
2.7
Author:
nicklas
Last modified
$Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $

Field Summary
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 onClick
           
private  Permission visiblePermission
           
 
Constructor Summary
PermissionButtonFactory()
          Create a new factory instance.
 
Method Summary
 ButtonAction[] getActions(InvokationContext context)
          This method may be called one or several times for each request.
private  boolean hasPermission(ClientContext cc, Item accepted, Permission permission)
           
 void setClazz(String clazz)
          Set the class to use in all cases.
 void setDisabledClazz(String clazz)
          Set the class to use when the button is disabled.
 void setDisabledIcon(String icon)
          Set the icon to use when the button is disabled.
 void setDisabledStyle(String style)
          Set the style to use when the button is disabled.
 void setDisabledTitle(String title)
          Set the title of the button when it is disabled.
 void setDisabledTooltip(String tooltip)
          Set the tooltip of the button when it is disabled.
 void setEnabledClazz(String clazz)
          Set the class to use when the button is enabled.
 void setEnabledIcon(String icon)
          Set the icon to use when the button is enabled.
 void setEnabledPermission(String permission)
          Set the minimum permission that is required to make the button enabled.
 void setEnabledStyle(String style)
          Set the style to use when the button is enabled.
 void setEnabledTitle(String title)
          Set the title of the button when it is enabled.
 void setEnabledTooltip(String tooltip)
          Set the tooltip of the button when it is enabled.
 void setIcon(String icon)
          Set the icon to use in all cases.
 void setId(String id)
          Set the ID of the button.
 void setItem(String item)
          Set the item type to check the permission for.
 void setOnClick(String onClick)
           
 void setStyle(String style)
          Set the style to use in all cases.
 void setTitle(String title)
          Set the title of the button in all cases.
 void setTooltip(String tooltip)
          Set the tooltip of the button in all cases.
 void setVisiblePermission(String permission)
          Set the minimum permission that is required to make the button visible.
 
Methods inherited from class net.sf.basedb.clients.web.extensions.AbstractJspActionFactory
prepareContext
 
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

id

private String id

onClick

private String onClick

visiblePermission

private Permission visiblePermission

enabledPermission

private Permission enabledPermission

itemToCheck

private Item itemToCheck

enabledClazz

private String enabledClazz

disabledClazz

private String disabledClazz

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

PermissionButtonFactory

public PermissionButtonFactory()
Create a new factory instance.

Method Detail

getActions

public ButtonAction[] getActions(InvokationContext 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.

setEnabledPermission

public void setEnabledPermission(String permission)
Set the minimum permission that is required to make the button enabled.

Parameters:
permission - One of Permission constants

setVisiblePermission

public void setVisiblePermission(String permission)
Set the minimum permission that is required to make the button 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 or null to accept all items

setEnabledClazz

public void setEnabledClazz(String clazz)
Set the class to use when the button is enabled.


setDisabledClazz

public void setDisabledClazz(String clazz)
Set the class to use when the button is disabled.


setClazz

public void setClazz(String clazz)
Set the class to use in all cases.


setEnabledIcon

@VariableSetter
@PathSetter
public void setEnabledIcon(String icon)
Set the icon to use when the button is enabled.


setDisabledIcon

@VariableSetter
@PathSetter
public void setDisabledIcon(String icon)
Set the icon to use when the button is disabled.


setIcon

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


setId

public void setId(String id)
Set the ID of the button.


setOnClick

@VariableSetter
public void setOnClick(String onClick)

setEnabledStyle

public void setEnabledStyle(String style)
Set the style to use when the button is enabled.


setDisabledStyle

public void setDisabledStyle(String style)
Set the style to use when the button is disabled.


setStyle

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


setEnabledTitle

public void setEnabledTitle(String title)
Set the title of the button when it is enabled.


setDisabledTitle

public void setDisabledTitle(String title)
Set the title of the button when it is disabled.


setTitle

public void setTitle(String title)
Set the title of the button in all cases.


setEnabledTooltip

public void setEnabledTooltip(String tooltip)
Set the tooltip of the button when it is enabled.


setDisabledTooltip

public void setDisabledTooltip(String tooltip)
Set the tooltip of the button when it is disabled.


setTooltip

public void setTooltip(String tooltip)
Set the tooltip of the button in all cases.


hasPermission

private boolean hasPermission(ClientContext cc,
                              Item accepted,
                              Permission permission)

2.17.2: 2011-06-17