eclipse-rap / org.eclipse.rap

Eclipse RAP Runtime (Remote Application Platform)
https://www.eclipse.org/rap/
Eclipse Public License 1.0
17 stars 19 forks source link

Grid: RowHeadersColumn breaks CheckEditingSupport #218

Closed Sebastian-Habenicht closed 2 weeks ago

Sebastian-Habenicht commented 4 weeks ago

The selection event that is processed in GridViewerColumn#setEditingSupport has a field index, which contains the value of attribute data-cell-index of the selected element. When the grid is rendered, this index includes the row header column. So if two checkable columns were created for the grid, they will have data-cell-index 1 and 2.

As a result, the column index used to detect the CheckEditingSupport for the selected column differs by one from the event's index and the CheckEditingSupport of the next checkable column (if one exists) is invoked. Code to reproduce:

final GridTableViewer gv = new GridTableViewer( shell, SWT.BORDER );
    gv.getGrid().setHeaderVisible( true );

    for( int i = 0; i < 2; i++ ) {
      final GridViewerColumn gvc = new GridViewerColumn( gv, new GridColumn( gv.getGrid(), SWT.CHECK ) );
      gvc.getColumn().setWidth( 100 );
      gvc.getColumn().setText( "Col-Index " + i );
      gvc.setEditingSupport( new CheckEditingSupport( gv ) {

        @Override
        public void setValue( Object element, Object value ) {
          System.out.println( "Set value to col " + gvc.getColumn().getText() );
        }
      } );
    }

    new GridItem( gv.getGrid(), SWT.NONE );

I think that in GridOperationHandler#handleNotifySelection the index should be reduced by the column offset (as it is done in some other places there when columns are detected):

event.index = readIndex( properties ) -  getColumnOffset( grid );

This Is used for different selection types (only the checkbox handling seems to use the event's index), but I guess it is correct to adjust the index for all types of selection events here. Otherwise, the handling in GridViewerColumn#setEditingSupport could be adjusted by using the Grid adapter to detect whether a row header column exists.