You can specify a set of actions in an XML screen descriptor for any component that implements the Component.ActionsHolder
interface, including the entire window or fragment. This is done in the actions
element, which contains nested action
elements.
The action
element can have the following attributes:
-
id
− identifier, which should be unique within theActionsHolder
component. -
caption
– action name. -
description
– action description. -
enable
– accessibility flag (true
/false
). -
icon
– action icon.
-
primary
- attribute that indicates if a button representing this action should be highlighted with a special visual style (true
/false
).The highlighting is available by default in the
hover
theme; to enable this feature in thehalo
theme, settrue
for the$cuba-highlight-primary-action
style variable.The
create
standard list action and thelookupSelectAction
in the lookup screen are primary by default. -
shortcut
- a keyboard shortcut.Shortcut values can be hard-coded in the XML descriptor. Possible modifiers,
ALT
,CTRL
,SHIFT
, are separated by the "-" character. For example:<action id="create" shortcut="ALT-N"/>
To avoid the hard-coded values, you can use the predefined shortcut aliases from the list below, for example:
<action id="edit" shortcut="${TABLE_EDIT_SHORTCUT}"/>
-
TABLE_EDIT_SHORTCUT
-
COMMIT_SHORTCUT
-
CLOSE_SHORTCUT
-
FILTER_APPLY_SHORTCUT
-
FILTER_SELECT_SHORTCUT
-
NEXT_TAB_SHORTCUT
-
PREVIOUS_TAB_SHORTCUT
-
PICKER_LOOKUP_SHORTCUT
-
PICKER_OPEN_SHORTCUT
-
PICKER_CLEAR_SHORTCUT
Another option is to use the fully qualified name of the
Config
interface and method which returns shortcut:<action id="remove" shortcut="${com.haulmont.cuba.client.ClientConfig#getTableRemoveShortcut}"/>
-
-
visible
– visibility flag (true
/false
).
The examples of action declaration and handling are provided below.
-
Declaring actions for the whole screen:
link:../../../../../source/gui/actions_1.xml[role=include]
link:../../../../../source/gui/actions_2.java[role=include]
In the example above, an action with
sayHello
identifier and a caption from the screen’s message pack is declared. This action is bound to a button, which caption will be set to the action’s name. The screen controller subscribes to the action’sActionPerformedEvent
, so theonSayHelloActionPerformed()
method will be invoked when the user clicks the button or presses the ALT-T keyboard shortcut. -
Declaring actions for PopupButton:
link:../../../../../source/gui/actions_3.xml[role=include]
link:../../../../../source/gui/actions_3_1.java[role=include]
-
Declaring actions for Table:
link:../../../../../source/gui/actions_4.xml[role=include]
link:../../../../../source/gui/actions_4_1.java[role=include]
In this example, the
copy
action is declared in addition tocreate
,edit
andremove
standard actions of the table. ThetrackSelection="true"
attribute means that the action and corresponding button become disabled if no row is selected in the table. It is useful if the action is intended to be executed for a currently selected table row. -
Declaring PickerField actions:
link:../../../../../source/gui/actions_5.xml[role=include]
link:../../../../../source/gui/actions_5_1.java[role=include]
In the example above, the standard
picker_lookup
action and an additionalshow
action are declared for thePickerField
component. SincePickerField
buttons that display actions use icons instead of captions, the caption attribute is not set. Thedescription
attribute allows you to display a tooltip when hovering over the action button.
You can obtain a reference to any declared action in the screen controller either directly by injection, or from a component that implements the Component.ActionsHolder
interface. It can be useful to set action properties programmatically. For example:
link:../../../../../source/gui/actions_6.java[role=include]