(Quick Reference)

8.1.2 The Action Manager - Reference Documentation

Authors: Andres Almiray

Version: 1.2.0

8.1.2 The Action Manager

Controller actions may automatically be wrapped and exposed as toolkit specific actions in a group's builder; this greatly simplifies how actions can be configured based on i18n concerns.

At the heart of this feature lies the GriffonControllerActionManager. This component is responsible for instantiating, configuring and keeping references to all actions per controller. It will automatically harvest all action candidates from a Controller once it has been instantiated. Each action has all of its properties configured following this strategy:

  • match <controller.class.name>.action.<action.name>.<key>
  • match application.action.<action.name>.<key>

<action.name> should be properly capitalized. In other words, you can configure action properties specifically per Controller or application wide. Available keys are

KeyDefault value
nameGriffonNameUtils.getNaturalName() applied to the action's name - 'Action' suffix (if it exists)
acceleratorundefined
short_descriptionundefined
long_descriptionundefined
mnemonicundefined
small_iconundefined; should point to an URL in the classpath
large_iconundefined; should point to an URL in the classpath
enabledundefined; boolean value
selectedundefined; boolean value

Values must be placed in resources files following the internationalization configuration guidelines.

Example

The following Controller defines four actions, the first two as closure properties while the others as methods. Two actions have an 'Action' suffix in their names.

package sample
import java.awt.event.ActionEvent
class SampleController {
    def newAction = { … }
    def open = { … }
    void close(ActionEvent evt) { … }
    void deleteAction(ActionEvent evt) { … }
}

The actions new and delete use the 'Action' suffix in order to avoid compilation errors given that they make use of reserved keywords. It's all the same to the GriffonControllerActionManager as it will generate the following variables in the group's builder: newAction, openAction, closeAction and deleteAction. ActionManager expects the following keys to be available in the application's i18n resources (i.e. griffon-app/i18n/messages.properties)

sample.SampleController.action.New.name = New
sample.SampleController.action.Open.name = Open
sample.SampleController.action.Close.name = Close
sample.SampleController.action.Delete.name = Delete
# additional keys per action elided

In the case that you'd like the close action to be customized for all controllers, say using the Spanish language, then you'll have to provide a file named griffon-app/i18n/messages_es.properties with the following keys

application.action.Close.name = Cerrar

Make sure to remove any controller specific keys when reaching for application wide configuration.