Standard Actions

The framework provides standard actions to solve common tasks, such as an invocation of an edit screen for an entity selected in a table. A standard action should be declared in the screen XML descriptor by specifying its type in the type attribute.

Each standard action is implemented by a class annotated with @ActionType("<some_type>"). The class defines the action’s default properties and behavior.

You can specify any basic action XML attributes to override common action properties: caption, icon, shortcut, etc. For example:

<action id="create" type="create"
        caption="Create customer" icon="USER_PLUS"/>

There are two categories of standard actions:

List Actions

List actions work with collections of entities that are displayed in tables or trees. These are AddAction, BulkEditAction, CreateAction, EditAction, ExcludeAction, RefreshAction, RelatedAction, RemoveAction, ViewAction.

When a list action is added to a table, tree, or data grid, it can be invoked from the component’s context menu item and by its predefined keyboard shortcut. Usually, the action is also invoked by a button added to the buttons panel.

<groupTable id="customersGroupTable"
            width="100%"
            dataContainer="customersDc">
    <actions>
        <action id="create" type="create"/>
        <action id="edit" type="edit"/>
        <action id="remove" type="remove"/>
    </actions>
    <columns>
        <column id="firstName"/>
        <column id="lastName"/>
    </columns>
    <buttonsPanel alwaysVisible="true">
        <button action="customersGroupTable.create"/>
        <button action="customersGroupTable.edit"/>
        <button action="customersGroupTable.remove"/>
    </buttonsPanel>
</groupTable>

Picker Actions

When a picker action is added to the component, it is automatically represented by a button inside the field.

<entityPicker dataContainer="orderDc"
              property="customer"
              caption="msg://ui.ex1.entity/Order.customer">
    <actions>
        <action id="lookup" type="entity_lookup"/>
        <action id="open" type="entity_open"/>
        <action id="clear" type="entity_clear"/>
    </actions>
</entityPicker>

Additional Properties

Standard actions have additional properties that can be set in XML or using setters in Java. In XML, additional properties are configured using the nested <properties> element, where each <property> element corresponds to a setter existing in this action class:

<action id="create" type="create">
    <properties>
        <property name="openMode" value="DIALOG"/>
        <property name="screenClass" value="ui.ex1.screen.entity.customer.CustomerEdit"/>
    </properties>
</action>

The same can be done in Java controller:

@Named("customersGroupTable.create")
private CreateAction<Customer> createAction;

@Subscribe
public void onInit(InitEvent event) {
    createAction.setOpenMode(OpenMode.DIALOG);
    createAction.setScreenClass(CustomerEdit.class);
}

Installing Handlers

If a setter accepts a functional interface, you can install a handler method in the screen controller. For example, CreateAction has setAfterCommitHandler(Consumer) method which is used to set a handler to be invoked after the created entity is committed. Then you can provide the handler as follows:

@Install(to = "customersGroupTable.create", subject = "afterCommitHandler")
private void customersGroupTableCreateAfterCommitHandler(Customer customer) {
    notifications.create()
            .withCaption("Created  " + customer)
            .show();
}

You can generate handlers implementation stubs using Studio.

There is a common enabledRule handler available to all actions, which allows you to set the action "enabled" state depending on the situation. In the example below, it disables RemoveAction for some entities:

@Autowired
private GroupTable<Customer> customersGroupTable;

@Install(to = "customersGroupTable.remove", subject = "enabledRule")
private boolean customersGroupTableRemoveEnabledRule() {
    Set<Customer> customers = customersGroupTable.getSelected();
    return canBeRemoved(customers);
}