Class ActionStore


  • public class ActionStore
    extends Object

    A class for maintaining action objects.

    This class provides access to the actions available in an application or for a certain component. Actions can be queried by their name, or lists of all existing actions can be requested. It is also possible to organize actions in groups. Then for example all actions that belong to a group can be disabled at once.

    An ActionStore object also holds a reference to a parent store. If defined, all actions in the parent store can be accessed by this store, too. This provides for a hierarchical action architecture. E.g. there may be a central ActionStore holding the global actions of the application. Sub components of the application (e.g. internal frames or dialogs) can define their own ActionStore with their specific set of actions, but through the parent reference have also access to the global actions.

    Note: The operations of this class are thread-safe.

    Version:
    $Id: ActionStore.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    • Constructor Detail

      • ActionStore

        public ActionStore()
        Creates a new empty instance of ActionStore.
      • ActionStore

        public ActionStore​(ActionStore parent)
        Creates a new instance of ActionStore and initializes the parent reference.
        Parameters:
        parent - this action store's parent
    • Method Detail

      • addAction

        public void addAction​(FormAction action)
        Adds the specified action to this store.
        Parameters:
        action - the action to add (must not be null)
      • removeAction

        public FormAction removeAction​(String name)
        Removes the action with the specified name from this store. This method only removes actions that belong to this store; actions in the parent store are not removed.
        Parameters:
        name - the name of the action to remove
        Returns:
        the removed action or null if it was not found
      • getAction

        public FormAction getAction​(String name)
        Returns the action with the given name. If this action does not exist, an exception will be thrown.
        Parameters:
        name - the name of the desired action
        Returns:
        the action with this name
        Throws:
        NoSuchElementException - if no such action exists
      • hasAction

        public boolean hasAction​(String name)
        Returns a flag whether the specified action is contained in this store or in the parent store.
        Parameters:
        name - the action's name
        Returns:
        a flag whether this action exists
      • getActionNames

        public Set<String> getActionNames()
        Returns a collection with the names of the actions stored in this ActionStore. The returned collection will not contain the names of the actions that are stored in the parent ActionStore.
        Returns:
        a collection with the names of the actions directly stored in this ActionStore
      • getAllActionNames

        public Set<String> getAllActionNames()
        Returns a collection with the names of all actions stored in this ActionStore or in one of its parents. With this method really all names can be found out that can be passed to the getAction(String) method. Note: the set returned by this method is a snapshot reflecting the state of this action time at the time it was created. It is not connected to this action store, so later updates are not visible.
        Returns:
        a collection with all defined action names
      • getActions

        public Collection<FormAction> getActions​(Collection<String> names)
        Returns all action objects whose names are specified in the given collection. This is a convenience method for easily accessing groups of actions. If one of the requested actions does not exist, a NoSuchElementException exception will be thrown. If an action cannot be found in this store, the parent store (if it is defined), is also searched.
        Parameters:
        names - a collection with the names of the desired actions
        Returns:
        the corresponding actions
        Throws:
        NoSuchElementException - if one of the actions cannot be resolved
      • addActionToGroup

        public void addActionToGroup​(String actionName,
                                     String groupName)
        Adds the specified action to the given group. This establishes a logical connection between this action and the group. If no group with this name exists, it is created now. If the action is unknown in this store or in the parent stores, a NoSuchElementException exception will be thrown.
        Parameters:
        actionName - the name of the action
        groupName - the name of the group (must not be null)
      • removeActionFromGroup

        public boolean removeActionFromGroup​(String actionName,
                                             String groupName)
        Removes the specified action from the given group. If the group becomes empty after this operation, it is removed itself.
        Parameters:
        actionName - the action's name
        groupName - the group's name
        Returns:
        a flag if the action was removed (false if either the action did not belong to this group or the group does not exist)
      • isActionInGroup

        public boolean isActionInGroup​(String actionName,
                                       String groupName)
        Checks if the specified action belongs to the given group.
        Parameters:
        actionName - the action's name
        groupName - the group's name
        Returns:
        a flag if the action belongs to this group
      • removeGroup

        public boolean removeGroup​(String groupName)
        Removes the group with the specified name. This does not affect any actions in this group; only the actions' associations to this group are removed.
        Parameters:
        groupName - the name of the group to remove
        Returns:
        a flag if the group existed
      • getActionNamesForGroup

        public Set<String> getActionNamesForGroup​(String groupName)
        Returns a set with the names of all actions that belong to the given group. If the group does not exist, the returned set is empty. The returned set is only a copy, so modifications won't have any effect on the groups of this store.
        Parameters:
        groupName - the name of the group
        Returns:
        a set with the names of all actions in this group
      • getGroupNames

        public Set<String> getGroupNames()
        Returns the names of all defined groups. Groups are a means for logically grouping actions. With the set returned here a client can iterate over all existing groups. Note that groups defined in one ActionStore are completely independent on the parent's groups, i.e. this method won't return any groups defined in the parent store.
        Returns:
        a collection with the names of the defined action groups
      • enableGroup

        public void enableGroup​(String groupName,
                                boolean enabled)
        Sets the enabled flag for all actions in the specified group. If the group cannot be found, this method has no effect.
        Parameters:
        groupName - the name of the group
        enabled - the value of the enabled flag
      • getParent

        public ActionStore getParent()
        Returns the parent store.
        Returns:
        the parent store (can be null)
      • setParent

        public void setParent​(ActionStore parent)
        Sets the parent store. Some of the methods also include a parent store in look up operations.
        Parameters:
        parent - the parent store