Define global table actions

Hello,
I have implemented a function to show documents related to an entity. This function is available via the toolbar in the entity table.
It is quite easy to implement for one entity, but now I am wonding what would be the best way to make this available for many entities.

1. Superclass for BrowseController


public abstract class AbstractBrowseWithDocument extends AbstractLookup {
    public void openDocument() {
        openWindow('Document.browse', WindowManager.OpenType.DIALOG)
    }
}
public class MyEntityBrowse extends AbstractBrowseWithDocument { }

<table id="table">
	<actions>
		...
		<action id="document" invoke="openDocument"/>
	</actions>
	<columns />
	<buttonsPanel id="buttonsPanel">
		..-
		<button id="dokumentBtn"
				action="table.document"/>
	</buttonsPanel>
</table>

Good

  • Definition of Action at one place
    ###Bad
  • Edit BrowseController and browse.xml for many entities

2. Extend default list actions

I know that cuba has some build-in actions for lists that I can easily use in all tables (Standard Actions over Collection - CUBA Platform. Developer’s Manual).
Is it possible to extend this list?


public class DocumentAction extends BaseAction {
    public static final String ACTION_ID = "document";
	...
}

// register DocumentAction somewhere

<table id="table">
	<actions>
		...
		<action id="document" />
	</actions>
	<columns />
	<buttonsPanel id="buttonsPanel">
		..-
		<button id="dokumentBtn"
				action="table.document"/>
	</buttonsPanel>
</table>

Good

  • Definition of Action at one place
  • Edit browse.xml for many entities
  • BrowseController can stay the same

Do you have another idea?
Thanks a lot for your support!

Yours,
Joerg

Hi Joerg,

There is one more way of managing actions in screens.

  • Create an action class, extending BaseAction.

  • In the init() method of a screen controller, instantiate the action giving it a specific identifier (e.g. document) and add it to a table.


myTable.addAction(new DocumentAction("document") {
    @Override
    public void actionPerform(Component component) {
        //
    }
});
  • In the screen XML, you don’t have to list the action in the actions element, but you can refer to it just by identifier as to a standard CUBA action, as in your example:

<table id="table">
    <buttonsPanel id="buttonsPanel">
        ..-
        <button id="dokumentBtn"
                action="table.document"/>
    </buttonsPanel>
    <columns />
</table>

Also, you can encapsulate the instantiation of the action in a base class of your controllers.