Class CommandAction

  • All Implemented Interfaces:
    ActionListener, EventListener, Action, ContextualAction, ContextListener

    public class CommandAction
    extends Object
    implements Action, ContextListener, ContextualAction
    Super class for all actions.

    A CommandAction contains information about its presentation and behavior. It implements Action interface. In addition to this, it provides more action parameters:

    For example with parameter setSelected(boolean) for the actions which have two states.

    Permission checking for an action works as follows:

    0. Check action.properties if the action is visible.
    1. Check user privileges if action is visible. (no -> break)
    2. Check user privileges if action is enabled. (no -> break)
    3. Check user privileges if commands for the action are executable. (no -> break)
    4. Ask the command object if the command is executable with the given context objects. (no -> break)

    Author:
    l.boureanu@levigo.de, Carolin Koehler
    • Field Detail

      • MULTISCREEN_ABILITY

        public static final String MULTISCREEN_ABILITY
        In multi screen environments positioning of tooltips, popups and other graphics configuration dependent component functionalities do not work correctly caused by a VM bug. Some action framework components are able to apply a workaround for the erroneous VM behavior but with the cost of some performance penalty. Therefore the workaround is not the default behavior and have to be forced by the action configuration with this key identifier.
        See Also:
        Constant Field Values
      • enabled

        protected boolean enabled
        Specifies whether action is enabled; the default is true.
    • Constructor Detail

      • CommandAction

        public CommandAction​(Context context,
                             Collection<Command> commands,
                             String key,
                             String name,
                             String shortDescription,
                             String longDescription,
                             Icon smallIcon,
                             Icon largeIcon,
                             String actionCommandKey,
                             KeyStroke acceleratorKey,
                             int mnemonicKey,
                             Map<String,​Object> otherParameters)
        Constructor

        It sets a context and registers the commandAction as one of the ContextListenerin the context.

        It sets the commandList for this commandAction and sets all parameters in from the Action.

        Parameters:
        context - which the action belongs in
        commands - all commands for this action
        key - the action key, same as Action.DEFAULT useful constants that can be used as the storage-retrieval key when setting or getting one of this object's properties
        name - same as Action.NAME used for storing the String name for the action, used for a menu or button.
        shortDescription - same as Action.SHORT_DESCRIPTION used for storing a short String description for the action, used for tooltip text.
        longDescription - same as Action.LONG_DESCRIPTION used for storing a longer String description for the action, could be used for context-sensitive help.
        smallIcon - same as Action.SMALL_ICON used for storing a small Icon
        largeIcon - same as Action.LARGE_ICON_KEY used for storing a large Icon
        actionCommandKey - same as Action.ACTION_COMMAND_KEY used to determine the command String for the ActionEvent that will be created when an Action is going to be notified
        acceleratorKey - same as Action.ACCELERATOR_KEY used for storing a KeyStroke to be used as the accelerator for the action
        mnemonicKey - same as Action.MNEMONIC_KEY used for storing an Integer that corresponds to one of the KeyEvent key codes.
        otherParameters - parameters which will be added to the action (can be null)
    • Method Detail

      • getCommands

        public Collection<Command> getCommands()
        Method returns collection of the commands which are related to the action.
        Returns:
        Collection of the related commands
      • setSelected

        public void setSelected​(boolean newValue)
        Sets the selected state of this action by setting given value with the Action.SELECTED_KEY.

        This is typically used only if this action has a meaningful selection state.

        Parameters:
        newValue - true selects the action, false the action is not selected
        See Also:
        Action.SELECTED_KEY
      • getValue

        public Object getValue​(String key)
        Gets the Object associated with the specified key.
        Specified by:
        getValue in interface Action
        Parameters:
        key - a string containing the specified key
        Returns:
        the binding Object stored with this key; if there are no keys, it will return null
        See Also:
        Action.getValue(java.lang.String)
      • getContext

        public Context getContext()
      • isEnabled

        public boolean isEnabled()
        Returns true if the action is enabled.
        Specified by:
        isEnabled in interface Action
        Returns:
        true if the action is enabled, false otherwise
        See Also:
        Action.isEnabled()
      • setEnabled

        public void setEnabled​(boolean newValue)
        Enables or disables the action.
        Specified by:
        setEnabled in interface Action
        Parameters:
        newValue - true to enable the action, false to disable it
        See Also:
        Action.setEnabled(boolean)
      • firePropertyChange

        protected void firePropertyChange​(String propertyName,
                                          Object oldValue,
                                          Object newValue)
        Supports reporting bound property changes. This method can be called when a bound property has changed and it will send the appropriate PropertyChangeEvent to any registered PropertyChangeListeners.
        Parameters:
        propertyName - the programmatic name of the property that was changed
        oldValue - the old value of the property
        newValue - the new value of the property
      • addPropertyChangeListener

        public void addPropertyChangeListener​(PropertyChangeListener listener)
        Adds a PropertyChangeListener to the listener list. The listener is registered for all properties.

        A PropertyChangeEvent will get fired in response to setting a bound property, e.g. setFont, setBackground, or setForeground. Note that if the current component is inheriting its foreground, background, or font from its container, then no event will be fired in response to a change in the inherited property.

        Specified by:
        addPropertyChangeListener in interface Action
        Parameters:
        listener - The PropertyChangeListener to be added
        See Also:
        Action.addPropertyChangeListener(java.beans.PropertyChangeListener)
      • getPropertyChangeListeners

        public PropertyChangeListener[] getPropertyChangeListeners()
        Returns an array of all the PropertyChangeListeners added to this AbstractAction with addPropertyChangeListener().
        Returns:
        all of the PropertyChangeListeners added or an empty array if no listeners have been added
      • setLastTriggerEvent

        public static void setLastTriggerEvent​(AWTEvent lastTriggerEvent)
        Due to technical reasons this method is temporary part of this class.

        It is strongly recommended that developers should not use this method. levigo reserves the right to remove or to change this method with future releases.

        Parameters:
        lastTriggerEvent - the lastTriggerEvent
      • getLastTriggerEvent

        public static AWTEvent getLastTriggerEvent()
        Due to technical reasons this method is temporary part of this class.

        It is strongly recommended that developers should not use this method. levigo reserves the right to remove or to change this method with future releases.

        Returns:
        the lastTriggerEvent