ccocco_dw
30 Mar 2011, 12:01 PM
When a cell is selected in an editable grid with a RowEditor, it puts the entire row into edit mode. If one of the columns is a CheckBoxSelectionModel, selecting a checkbox in that column puts the row in edit mode but throws a NullPointerException in RowEditor.doFocus() as getTargetColumnIndex() returns a -1 for the column index and this causes the subsequent code to fail. I'm providing the fix here:
public class GridRowEditor<M extends ModelData>
extends RowEditor<M>
{
@Override
protected void doFocus( Point pt )
{
if ( isVisible() )
{
int index = 0;
if ( pt != null )
{
index = getTargetColumnIndex( pt );
}
// The following is a kludge to fix an issue in the GXT RowEditor. Occassionally getTargetColumnIndex()
// returns -1 and this causes a NullPointerException for the cm.getColumn() call below since there isn't
// a valid column at that index...
if ( index == -1 )
{
index = 0;
}
ColumnModel cm = this.grid.getColumnModel();
for ( int i = index, len = cm.getColumnCount(); i < len; i++ )
{
ColumnConfig c = cm.getColumn( i );
if ( !c.isHidden() && c.getEditor() != null )
{
c.getEditor().getField().focus();
break;
}
}
}
}
}
public class GridRowEditor<M extends ModelData>
extends RowEditor<M>
{
@Override
protected void doFocus( Point pt )
{
if ( isVisible() )
{
int index = 0;
if ( pt != null )
{
index = getTargetColumnIndex( pt );
}
// The following is a kludge to fix an issue in the GXT RowEditor. Occassionally getTargetColumnIndex()
// returns -1 and this causes a NullPointerException for the cm.getColumn() call below since there isn't
// a valid column at that index...
if ( index == -1 )
{
index = 0;
}
ColumnModel cm = this.grid.getColumnModel();
for ( int i = index, len = cm.getColumnCount(); i < len; i++ )
{
ColumnConfig c = cm.getColumn( i );
if ( !c.isHidden() && c.getEditor() != null )
{
c.getEditor().getField().focus();
break;
}
}
}
}
}