DataGrid ENTER key is not directed to the correct instance

Hi

If you have several tabs open with datagrids, only the datagrid in the first open tab will receive the ENTER key.

How to reproduce with sample project attached:

  • open order lines browser (1st datagrid)
  • open orders browser and edit one order (2nd datagrid)
  • in order editor press enter to edit a line, does not work
  • in order lines browser, press enter to edit line, it works
  • close order lines browser (1st tab)
  • in order editor press enter to edit a line, now it works

Through debugging I think found a lead, it seems to be related to ActionManager.handleActions

    public void handleActions(Map<String, Object> variables, Container sender) {
        if (variables.containsKey("action") && actionMapper != null) {
            final String key = (String) variables.get("action");
            final Action action = actionMapper.get(key);
            final Object target = variables.get("actiontarget");
            if (action != null) {
                handleAction(action, sender, target);
            }
        }
    }

actionMapper.get always return the lambda defined in WebDataGrid.initComponent of the first datagrid instantiated (lambda code below).

[...]       
 component.addShortcutListener(new ShortcutListener("dataGridEnter", KeyCode.ENTER, null) {
            @Override
            public void handleAction(Object sender, Object target) {
                CubaGrid dataGridComponent = WebDataGrid.this.component;
                if (target == dataGridComponent) {
                    if (WebDataGrid.this.isEditorEnabled()) {
[...]

I did not push the debugging too far so my analysis may be wrong.

datagrid.zip (114.1 KB)

Hi,

Thank you for reporting the problem, I’ve created a GitHub issue. Also, it seems that platform 7.0+ has no such issue.

Regards,
Gleb

Thanks @gorelov. That’s good to know. We cannot afford yet a migration to 7.0, but we’ll have to plan it this year anyway.

Hi, @michael.renaud!

I’ve investigated your project more closely and found that the problem is that you change editorEnabled programmatically. After I removed all lines changing editorEnabled the problem is gone. So it appears that the problem isn’t related to CUBA.

Regards,
Gleb

Hi @gorelov

If you look at OrderEdit there is a BeforeActionPerformed set on EditActionin order to hide computed columns (i.e amount) before editing, letting more width space for edition.

        editAction.setBeforeActionPerformedHandler(this::onEditHideComputedColumns);

The problem with Datagrid is that when editor is enabled, then ENTER key opens directly grid internal editor without passing through EditAction, and so bypassing the BeforeActionPerformed handler.

The problem is in WebDataGrid.initComponent:

       component.addShortcutListener(new ShortcutListener("dataGridEnter", KeyCode.ENTER, null) {
            @Override
            public void handleAction(Object sender, Object target) {
                CubaGrid dataGridComponent = WebDataGrid.this.component;
                if (target == dataGridComponent) {
                    if (WebDataGrid.this.isEditorEnabled()) {
                        // Prevent custom actions on Enter if DataGrid editor is enabled
                        // since it's the default shortcut to open editor
                        return;
                    }

So if I want my EditAction and particularly its BeforeActionPerformed to work, I have no choice to use this trick… that you have advised yourself in this post.

And in fact, I don’t think this trick used in OrderEdit is the culprit. Try with sample project reattached :

  • open Orders, enter on a line, this opens OrderEdit.
  • open Customers (has a grid), open Orders, enter on a line, does not open OrderEdit
  • close Customers tab, go back to Orders, enter on a line, it now works

As you can see the issue happens even before OrderEdit is open, so it cannot be the cause.

Best Regards
Michael

datagrid.zip (122.3 KB)