Disabling Selection with CellList

1.1k Views Asked by At

I have a CellList:

friendCellList = new CellList<PlayerDataEntity>(new PlayerCell());
friendCellList.setSelectionModel(new NoSelectionModel<PlayerDataEntity>());

I am hoping that passing the NoSelectionModel will prevent the UI from reacting to the user selecting items in the cell list. However, the user is able to select elements normally. Am I not applying the selection model correctly?

1

There are 1 best solutions below

2
On

From the Javadoc of NoSelectionModel:

A selection model that does not allow selection, but fires selection change events. Use this model if you want to know when a user selects an item, but do not want the view to update based on the selection.

That's what it does: In the Standard theme, this will result in the row not being highlighted in blue anymore ("cellListSelectedItem" style class). However, it will still be highlighted in yellow ("cellListKeyboardSelectedItem" style class). Also, the SelectionChangeEvent will still be fired.

To turn off the SelectionChangeEvent, use

cellList.setSelectionModel(new NoSelectionModel<String>(), 
  DefaultSelectionEventManager.<PlayerDataEntity>createWhitelistManager());

The whitelist manager without arguments means, that you can't select any column.

If you also want to turn off the "yellow" highlighting, you should instantiate CellList with a different CellList.Resources instance:

public interface MyResources extends CellList.Resources {
  @Override
  @Source("com/mypackage/my.css")
    Style cellListStyle();
}
...
friendCellList = new CellList<PlayerDataEntity>(new PlayerCell(),
    (MyResources) GWT.create(MyResources.class);

my.css:

.cellListEvenItem {}
.cellListKeyboardSelectedItem {}
.cellListOddItem {}
.cellListSelectedItem {}
.cellListWidget {}