Class ActionHelper
- java.lang.Object
-
- net.sf.jguiraffe.gui.builder.action.ActionHelper
-
public final class ActionHelper extends Object
A helper class for dealing with actions.
This class provides some utility methods that can be used when working with actions and their tasks.
- Version:
- $Id: ActionHelper.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
checkActionTask(Object task)
Tests whether the specified object is a valid task for an action.static void
enableActions(Collection<FormAction> actions, boolean enabled)
Sets the enabled flag for all actions in the specified collection.static Collection<FormAction>
fetchActionsInGroup(ActionStore actionStore, String groupName)
Returns all actions that belong to the specified group in the givenActionStore
.static Collection<FormAction>
fetchAllActionsInGroup(ActionStore actionStore, String groupName, boolean distinct)
Returns all actions that belong to the specified group in the givenActionStore
or one of its parents.static Set<String>
getAllGroupNames(ActionStore actionStore)
Returns the names of all groups defined for the specifiedActionStore
and its parents.static void
invokeActionTask(Object task, FormAction action, BuilderEvent event)
Invokes the specified action task.static boolean
isValidActionTask(Object task)
Returns a flag whether the specified object is a valid task for an action.
-
-
-
Method Detail
-
isValidActionTask
public static boolean isValidActionTask(Object task)
Returns a flag whether the specified object is a valid task for an action. This method tests whether the object can be casted to a type supported by actions.- Parameters:
task
- the task object to be inspected- Returns:
- a flag whether this is an allowed task for an action
-
checkActionTask
public static void checkActionTask(Object task)
Tests whether the specified object is a valid task for an action. This method delegates toisValidActionTask()
. If the result is false, anIllegalArgumentException
exception will be thrown.- Parameters:
task
- the task to be inspected- Throws:
IllegalArgumentException
- if the task is not supported by actions
-
invokeActionTask
public static void invokeActionTask(Object task, FormAction action, BuilderEvent event)
Invokes the specified action task. This method tries to cast the passed in task object to one of the supported types and then invoke then correct method. If the passed in task is invalid, an exception will be thrown.- Parameters:
task
- the task to be invokedaction
- the corresponding actionevent
- the event that triggered the action- Throws:
IllegalArgumentException
- if the task cannot be invoked
-
getAllGroupNames
public static Set<String> getAllGroupNames(ActionStore actionStore)
Returns the names of all groups defined for the specifiedActionStore
and its parents. This method navigates through the hierarchy of stores collecting all existing groups.- Parameters:
actionStore
- theActionStore
to start with- Returns:
- a set with the names of all groups existing in this hierarchy; if the passed in action store is null, an empty set is returned
-
fetchActionsInGroup
public static Collection<FormAction> fetchActionsInGroup(ActionStore actionStore, String groupName)
Returns all actions that belong to the specified group in the givenActionStore
. If the action store is null or the group does not exist, an empty collection is returned.- Parameters:
actionStore
- the action storegroupName
- the name of the desired group- Returns:
- a collection with the actions of this group
-
fetchAllActionsInGroup
public static Collection<FormAction> fetchAllActionsInGroup(ActionStore actionStore, String groupName, boolean distinct)
Returns all actions that belong to the specified group in the givenActionStore
or one of its parents. Thedistinct
parameter determines how actions with the same names are to be treated. If set to true, actions in a parent store are not added to the results collection if there are already actions with the same name in a child store. If the parameter is false, all actions are added.- Parameters:
actionStore
- the actionStore to start with (can be null, then an empty collection will be returned)groupName
- the name of the groupdistinct
- the distinct flag- Returns:
- a collection with the actions in this group
-
enableActions
public static void enableActions(Collection<FormAction> actions, boolean enabled)
Sets the enabled flag for all actions in the specified collection. With this method a set of actions can be enabled or disabled at once.- Parameters:
actions
- a collection with the involved actions (can be null, then this operation has no effect)enabled
- the enabled flag
-
-