CheckboxCell as SelectionModel provider

336 views
Skip to first unread message

Baloe

unread,
Nov 9, 2010, 10:40:25 AM11/9/10
to Google Web Toolkit
Hi all,

I'm trying to get a CheckboxCell working as a selector for the row,
but it doesn't work. And there is no getValue() on the CheckboxCell as
well, so any weird saving of added checkboxes is no alternative as
well.

The code is as follows:
...
cellTable = new CellTable<DtoContactList>();
cellTable.setSelectionModel(new
MultiSelectionModel<DtoContactList>());

flowPanel.add(cellTable);

cellTable.addColumn(new Column<DtoContactList, Boolean>(
new CheckboxCell(true)) {
@Override
public Boolean getValue(DtoContactList object) {
return false;
}
}, new TextHeader("Select"));
...
Because it says 'true' in the CheckboxCell, it should function as a
selection controller, right? Well, it doesn't:

@Override
public List<DtoContactList> getSelected() {
MultiSelectionModel<? super DtoContactList> model =
(MultiSelectionModel<? super
DtoContactList>) cellTable.getSelectionModel();
LOG.log(Level.INFO, "selected size=" +
model.getSelectedSet().size());

Thanks for any hints!

Baloe

Thomas Broyer

unread,
Nov 9, 2010, 11:47:10 AM11/9/10
to Google Web Toolkit


On 9 nov, 16:40, Baloe <nielsba...@gmail.com> wrote:
> Hi all,
>
> I'm trying to get a CheckboxCell working as a selector for the row,
> but it doesn't work. And there is no getValue() on the CheckboxCell as
> well, so any weird saving of added checkboxes is no alternative as
> well.
>
> The code is as follows:
> ...
>                 cellTable = new CellTable<DtoContactList>();
>                 cellTable.setSelectionModel(new
> MultiSelectionModel<DtoContactList>());
>
>                 flowPanel.add(cellTable);
>
>                 cellTable.addColumn(new Column<DtoContactList, Boolean>(
>                                 new CheckboxCell(true)) {
>                         @Override
>                         public Boolean getValue(DtoContactList object) {
>                                 return false;
>                         }
>                 }, new TextHeader("Select"));
> ...
> Because it says 'true' in the CheckboxCell, it should function as a
> selection controller, right?

No.

> Thanks for any hints!

See http://gwt.google.com/samples/Showcase/Showcase.html#!CwCellTable
// Checkbox column. This table will uses a checkbox column for
selection.
// Alternatively, you can call cellTable.setSelectionEnabled(true)
to enable
// mouse selection.
Column<ContactInfo, Boolean> checkColumn = new Column<ContactInfo,
Boolean>(
new CheckboxCell(true)) {
@Override
public Boolean getValue(ContactInfo object) {
// Get the value from the selection model.
return selectionModel.isSelected(object);
}
};
checkColumn.setFieldUpdater(new FieldUpdater<ContactInfo,
Boolean>() {
public void update(int index, ContactInfo object, Boolean value)
{
// Called when the user clicks on a checkbox.
selectionModel.setSelected(object, value);
}
});
cellTable.addColumn(checkColumn,
SafeHtmlUtils.fromSafeConstant("<br>"));
Reply all
Reply to author
Forward
0 new messages