Disabling Selection with CellList

时间秒杀一切 提交于 2019-12-11 02:17:44

问题


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:


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 {}


来源:https://stackoverflow.com/questions/10590922/disabling-selection-with-celllist

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!