So this is my scenario:
I have a list view with a change listener in its selection model:
ObjectProperty<MultipleSelectionModel<MyType>> selectionModelProperty = ...
selectionModelProperty.get().selectedItemProperty().addListener(new ChangeListener<MyType>(){
...
}
When the user clicks certain button, the selected item should be deleted from the list. Also, a new item at the same position of the deleted item should be automatically selected. In case the selected item was the last one, after deletion the new selected item will be the one that was before the deleted one (the new last item in the list).
The code I have looks a bit like this:
int currentIndex = selectionModelProperty.get().getSelectedIndex();
containerList.remove(item);
if(!containerList.isEmpty()) {
if(currentIndex == containerList.size())
currentIndex--;
selectionModelProperty.get().select(currentIndex);
}
This works fine if the item to delete is not the last one. However, if the item to delete is the last one, the change event in the selection model is not triggered !. Is this a bug or an expected behavior ?
I discover that if I clear the selection just before removing the item, a change event in the selection model is correctly fired:
selectionModelProperty.get().clearSelection();
Edited by: se**** on May 11, 2013 1:39 AM