Override default table double click action

Hello,

I’m attempting to override the default action of double-clicking a table entry within a browse screen.

I’ve found examples:

Here
Here
And referencing this

The problem is that I’m still a bit new to CUBA and haven’t been able to find the correct syntax to do this.

Basically, I’ve got an attachment browse screen, and I’ve got a custom action/button to download the attachment like so:

@Subscribe(“downloadBtn”)
public void onDownloadBtnClick() {
FileDescriptor fileDescriptor = sOPsTable.getSingleSelected().getSopDocument();
if (fileDescriptor != null) {
exportDisplay.show(fileDescriptor);
}
}

This works correctly. But now I need to figure out the syntax to override the double-clicking default action and have it perform just like clicking the Download button. When I tried to set this up like in the examples, I keep getting syntax errors.

I’m hoping someone can provide an example that will do what I’m attempting.

Thanks in advance! (and I apologize if the answer is in there and I’m too thick to understand it)

Basically, I’m looking for the solution of how to execute the setItemClickAction() on the sOPsTable. I do not know the method of how to implement this.

Hi,

In order to define ItemClickAction for a table, you need to use the setItemClickAction method, e.g.:

@Inject
private Table<Customer> customerTable;

@Subscribe
protected void onInit(InitEvent event) {
    customerTable.setItemClickAction(new BaseAction("itemClickAction")
            .withHandler(actionPerformedEvent -> {
                Customer customer = customerTable.getSingleSelected();
                if (customer != null) {
                    ...
                }
            }));
}

You can see the code above in action in the live demo.

Regards,
Gleb

1 Like

This is perfect, and exactly what I needed. Thank you!