Class PermissionButtonFactory
- java.lang.Object
-
- net.sf.basedb.clients.web.extensions.AbstractJspFactory
-
- net.sf.basedb.clients.web.extensions.AbstractJspActionFactory<ButtonAction>
-
- net.sf.basedb.clients.web.extensions.toolbar.PermissionButtonFactory
-
- All Implemented Interfaces:
DynamicActionAttributes
,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 anAccessControlled
item permissions are checked against that item:AccessControlled.hasPermission(Permission)
. If no item type has been specified withsetItem(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 withSessionControl.hasPermission(Permission, Item)
.Permission levels can be set for when the button should be:
- visible and enabled
- visible but disabled
- hidden
AbstractJspActionFactory.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
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)
andAbstractJspFactory.setStylesheet(String)
methods. Each call to these methods will add the argument to a set. Use theAbstractJspFactory.getScripts()
andAbstractJspFactory.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
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
onClick
private Permission
visiblePermission
-
Constructor Summary
Constructors Constructor Description PermissionButtonFactory()
Create a new factory instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ButtonAction[]
getActions(InvokationContext<? super ButtonAction> 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
getDynamicActionAttributes, getParameter, getScripts, getStylesheets, prepareContext, setParameter, setScript, setStylesheet
-
-
-
-
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
-
-
Method Detail
-
getActions
public ButtonAction[] getActions(InvokationContext<? super ButtonAction> 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 ofPermission
constants
-
setVisiblePermission
public void setVisiblePermission(String permission)
Set the minimum permission that is required to make the button 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 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)
-
-