I have two buttons "Next element" and "Previous element" and some custom widget containing CellList. On button clicks I call to my widget's method which changeselection in CellList by calling it's SelectionModel:
selectionModel.setSelected(value, true);
When I refresh CellList's contents, the buttons work just fine, but when I select element in list by clicking on it, this behavior happens: For example, I have elements {0, 1, 2, 3, 4, ..} on the list. I click on element 1, then press "Next element" button two times. These SelectionChangeEvent occurs:
- Change selection from 1 -> 2 (on first button press)
- 2 -> 3 (on second press)
- 3 -> 1
But after step 2 if I press "Previous" it correctly go back to element 1. So element that I clicked with mouse doesn't let selection go more than 1 step around it.
I have no idea where the third event is coming from. My only guess is that manual selection event continues pending after firing, but I don't know how to check that.
Anybody knows the reason of this problem?
upd:
I found confirmation that selection by clicking event continues to hanging there somewhere in the EventBus: when I change search filters I access SelectionModel the same way as on button clicks and set selection to first element. But if there was user click on CellList before that the same thing happens: first, selection changes to 0, second, it goes back to previously selected if new selection of data contains that element.
upd (for Ümit's question):
nextButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
/* Omitting checks that there are elements on the list,
some element is selected and isn't last */
T value = dataProvider.getList().get(currentIndex() + 1);
singleSelectionModel.setSelected(value, true);
singleSelectionModel.isSelected(value);
Element rowElement = cellList.getRowElement(index);
rowElement.scrollIntoView();
}
}
upd: Found what was causing this problem: http://code.google.com/p/google-web-toolkit/issues/detail?id=6310
ClickCallHandler
for "Next element" and "previous element" – Ümit