Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 329926

Summary: Active cell editor does not prevent execution of shell default button when "Enter" is pressed
Product: [RT] RAP Reporter: Jamie <ctljm>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: austin.riddle, juergen.panser, neubauer, rsternberg, swimmer_86
Version: 1.3   
Target Milestone: 1.5 M5   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on: 334504    
Bug Blocks:    

Description Jamie CLA 2010-11-10 12:15:36 EST
Build Identifier: 20100917-0705

I have a TextCellEditor used in a EditingSupport which handles the editing in a TableViewer, and this TableViewer locates in a Dialog. The problem is, when I edited the cell in the table and then pressed 'Enter', the whole dialog was closed.

The correct behavior should be that the editor was deactivated. And the same code works well in RCP. So it is a problem in RAP.

With almost the same code, except that the TableViewer was moved from a dialog to a view, it worked with no problem, even in RAP.

I debug the code, and found that the TextCellEditor.handleDefaultSelection() was not called when the 'Enter' was pressed. While in RCP, or using a view in RAP, the method was called.


Reproducible: Always

Steps to Reproduce:
1.Create your own dialog:
public class ViewerDiaglog extends Dialog
{
...
 protected Control createDialogArea(Composite parent)
    {
...
        viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);

        Table table = viewer.getTable();
        String[] titles = { "First name", "Last name", "Gender", "Married" };
        int[] bounds = { 100, 100, 100, 100 };

        for (int i = 0; i < titles.length; i++)
        {
            final int index = i;
            final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
....
            viewerColumn.setEditingSupport(new PersonEditingSupport(viewer, i));
...
        }
...
    }


2. Create your own editing support:
public class PersonEditingSupport extends EditingSupport {
	private CellEditor editor;
	private int column;

	public PersonEditingSupport(ColumnViewer viewer, int column) {
		super(viewer);
...
			editor = new TextCellEditor(((TableViewer) viewer).getTable());

...
        }
...
}


3.Create a button in your view to open the dialog for testing.
public class View extends ViewPart
{
...
 @Override
    public void createPartControl(Composite parent)
    {
       buttonOK = new Button(parent, SWT.PUSH);
        buttonOK.setText("Open a viewer dialog");

        buttonOK.addSelectionListener(new SelectionAdapter()
        {
            @Override
            public void widgetSelected(SelectionEvent e)
            {
                Shell shell = getViewer().getTable().getShell();
                ViewerDiaglog dialog = new ViewerDiaglog(shell);
                dialog.open();
                // MessageDialog.openInformation(shell, "WARNING", "You pressed OK!");

            }
        });
    }
...
}


4. Run your application in RAP: press the button, the dialog with a viewer should popup.

5. Click a cell in the table to edit the text, key in some characters, then press 'Enter'.

6. Now the dialog is closed, which is wrong.

7. If you set a breakpoint in TextCellEditor.handleDefaultSelection(e), you will find that it is not called, which it should.
Comment 1 Ivan Furnadjiev CLA 2010-11-19 06:11:07 EST
The actual problem is that dialog ( Shell ) default button execution is not prevented if there is an active cell editor. As a workaround set dialog default button to null. Needs more investigation how this is prevented in JFace. Changed the title accordingly.
Comment 2 Yury CLA 2010-12-30 03:56:11 EST
Ivan,

do you know any news about fixing progress of this issue?

Best regards,
Yury.
Comment 3 Ivan Furnadjiev CLA 2011-01-10 03:28:18 EST
Hi Yury, sorry for the late response, but I was in vacation these days. I had no time to investigate it further, but I will look on it again this week.
Comment 4 Ivan Furnadjiev CLA 2011-01-10 05:29:09 EST
Some additional findings. In RCP the default button execution is prevented by canceling the SWT.TRAVERSE_RETURN event - see TextCellEditor line 168. In RAP, the default button does not respect the canceled SWT.TRAVERSE_RETURN event.
Comment 5 Ivan Furnadjiev CLA 2011-01-17 04:55:08 EST
We need first to solve the bug 334504, as SWT.TRAVERSE_RETURN event is not fired at all in IE, Safari, Chrome and Opera.
Comment 6 Ralf Sternberg CLA 2011-01-29 10:02:33 EST
(In reply to comment #5)
> We need first to solve the bug 334504, as SWT.TRAVERSE_RETURN event is not
> fired at all in IE, Safari, Chrome and Opera.

Since bug 334504 is fixed and this bug has been opened for 1.3 - Is this something for a last-minute fix for SR2?
Comment 7 Ivan Furnadjiev CLA 2011-01-29 11:11:11 EST
No... The bug 334504 was a blocker, but not enough to fix this one. Additional fixes (both on client and/or... jface) are needed.
Comment 8 Arnaud MERGEY CLA 2011-10-18 11:09:58 EDT
There is also same issue with ESC key, in RCP esc disable text cell edition without closing the whole dialog. 
In RAP pressing ESC close the dialog
Comment 9 juergen.panser CLA 2011-12-06 03:52:41 EST
Hi,

I ran into the same problem with an editing support in a wizard dialog. Same code in a FormEditor works.

The inital problem was reported about one year ago. Is a fix planned in the near future?
Comment 10 Ivan Furnadjiev CLA 2011-12-13 04:18:48 EST
There is no easy fix for this issue (both client and server side are affected). I will look on it again as soon as possible, but I can't promise anything.
Comment 11 juergen.panser CLA 2011-12-13 04:43:36 EST
Thanks.

A quickfix may be to overwrite the buttonPressed method of the WizardDialog class:

protected void buttonPressed(final int buttonId) {
  if (Display.getDefault().getFocusControl() instanceof Button) {
    super.buttonPressed(buttonId);
  }
}

A second approach may be to change the behavior of the keyReleaseOccured method in the TextCellEditor:

protected void keyReleaseOccured(final KeyEvent keyEvent) {
  if (useHack) {
    if (keyEvent.character == '\r') { // Return key
      //  Because of RAP bug 329926 handleDefaultSelection isn't called -> we have to do it by our own
      if (this.text != null && !this.text.isDisposed() && (this.text.getStyle() & SWT.MULTI) != 0) {
        if ((keyEvent.stateMask & SWT.CTRL) != 0) {
          super.keyReleaseOccured(keyEvent);
          return;
        }
      }
      //handleDefaultSelection(event);
      fireApplyEditorValue();
      deactivate();
    }
  }
  super.keyReleaseOccured(keyEvent);
}

But these are only quickfixes...
Comment 12 Ivan Furnadjiev CLA 2011-12-13 05:14:08 EST
The main problem here is that canceling a key event (ENTER or ESC) works on the client-side "keypress" DOM event. As "default" button execution and dialog close by Escape key is done on "keydown" DOM event (see Shell.js#_onKeydown) the current JFace mechanism does not work. One possible solution will be to change the "default" button execution and dialog close by Escape key to "keypress" DOM event. In this case some additional adjustments are needed as Text widget prevents the propagation of "keypress" events (see TextField.js#_onkeypress).
Comment 13 juergen.panser CLA 2012-01-18 08:27:40 EST
With RAP 1.5 M4 this problem occurs with every Text widget!

If you have a Text widget and buttons the first button gets a selection event if the return key is pressed in the Text widget.
Comment 14 juergen.panser CLA 2012-01-18 09:55:44 EST
The last button that has got the focus triggers the selection event.

Create a composite with e textbox and two button A and B. Click on A (which may open a dialog) then click into the textbox, enter some chars and press the return key. The dialog opens.
Comment 15 Ivan Furnadjiev CLA 2012-01-26 01:51:20 EST
With the implementation of CANCEL_KEY (Bug 367869) and adaption of JFAce code (Bug 367923) to use them, this issue has been fixed. Using ESC and ENTER on active cell editor does not affect parent dialog anymore. Juergen, could you open a separate bugzilla about your findings.