J'ai un prototype fonctionnel d'un CellTable modifiable. Le prototype a un tableau affichant des colonnes de type String, Boolean, Date, Integer avec des éditeurs pour chacune d'entre elles. L'édition de chaque cellule met à jour le modèle correspondant.
public class CellTableDemo implements EntryPoint
{
public void onModuleLoad( )
{
CellTable<SomeDTO> cellTable = createTable( );
addColumns( cellTable );
ListViewAdapter<SomeDTO> listViewAdapter = new ListViewAdapter<SomeDTO>( );
listViewAdapter.setList( getData( ) );
listViewAdapter.addView( cellTable );
RootPanel.get( ).add( new SimplePager<SomeDTO>( cellTable, SimplePager.TextLocation.CENTER ) );
RootPanel.get( ).add( cellTable );
}
private CellTable<SomeDTO> createTable( )
{
CellTable<SomeDTO> cellTable = new CellTable<SomeDTO>( );
cellTable.setSelectionEnabled( true );
cellTable.setSelectionModel( new SingleSelectionModel<SomeDTO>( ) );
cellTable.setPageSize( 5 );
cellTable.setPageStart( 0 );
return cellTable;
}
private void addColumns( CellTable<SomeDTO> cellTable )
{
Column<SomeDTO, String> colA = new Column<SomeDTO, String>( new TextInputCell( ) )
{
public String getValue( SomeDTO object )
{
return object.getA( );
}
};
colA.setFieldUpdater( new FieldUpdater<SomeDTO, String>( ) // updates changes into the backing bean
{
public void update( int index, SomeDTO object, String value )
{
object.setA( value );
}
} );
cellTable.addColumn( colA, "String Column A" );
cellTable.addColumn( new Column<SomeDTO, Integer>( new CurrencyCell( ) )
{
public Integer getValue( SomeDTO object )
{
return object.getB( );
}
}, "Currency Column B" );
Column<SomeDTO, Boolean> colC = new Column<SomeDTO, Boolean>( new CheckboxCell( ) )
{
public Boolean getValue( SomeDTO object )
{
return object.getC( );
}
};
colC.setFieldUpdater( new FieldUpdater<SomeDTO, Boolean>( )
{
public void update( int index, SomeDTO object, Boolean value )
{
object.setC( value );
}
} );
cellTable.addColumn( colC, "Boolean Column C" );
Column<SomeDTO, Date> colD = new Column<SomeDTO, Date>( new DatePickerCell( ) )
{
public Date getValue( SomeDTO object )
{
return object.getD( );
}
};
colD.setFieldUpdater( new FieldUpdater<SomeDTO, Date>( )
{
public void update( int index, SomeDTO object, Date value )
{
object.setD( value );
}
} );
cellTable.addColumn( colD, "Date Column D" );
cellTable.addColumn( new Column<SomeDTO, String>( new ActionCell<String>( "Click of summary of this row", new Delegate<String>( )
{
public void execute( String row )
{
Window.alert( row );
}
} ) )
{
public String getValue( SomeDTO row )
{
return row.getSummary( );
}
} );
}
private ArrayList<SomeDTO> getData( )
{
ArrayList<SomeDTO> tableData = new ArrayList<SomeDTO>( );
tableData.add( new SomeDTO( "A", 10, true, new Date( ) ) );
tableData.add( new SomeDTO( "AA", 200, false, new Date( ) ) );
tableData.add( new SomeDTO( "AAA", 3000, true, new Date( ) ) );
tableData.add( new SomeDTO( "AAAA", 40, false, new Date( ) ) );
tableData.add( new SomeDTO( "AAAAA", 500, true, new Date( ) ) );
tableData.add( new SomeDTO( "AAAAAA", 6000, false, new Date( ) ) );
tableData.add( new SomeDTO( "AAAAAAA", 70, true, new Date( ) ) );
tableData.add( new SomeDTO( "AAAAAAAA", 800, false, new Date( ) ) );
tableData.add( new SomeDTO( "AAAAAAAAA", 9000, true, new Date( ) ) );
tableData.add( new SomeDTO( "AAAAAAAAAA", 10, false, new Date( ) ) );
tableData.add( new SomeDTO( "AAAAAAAAAAA", 11, true, new Date( ) ) );
return tableData;
}
public class SomeDTO
{
private String a;
private Integer b;
private Boolean c;
private Date d;
public SomeDTO( String a, Integer b, Boolean c, Date d )
{
this.a = a;
this.b = b;
this.c = c;
this.d = d;
}
public String getA( )
{
return a;
}
public void setA( String a )
{
this.a = a;
}
public Integer getB( )
{
return b;
}
public void setB( Integer b )
{
this.b = b;
}
public Boolean getC( )
{
return c;
}
public void setC( Boolean c )
{
this.c = c;
}
public Date getD( )
{
return d;
}
public void setD( Date d )
{
this.d = d;
}
public String getSummary( )
{
return getA( ) + " " + getB( ) + " " + getC( ) + " " + getD( );
}
}
}