-
Bug
-
Resolution: Unresolved
-
P4
-
jfx17
In many places, MultipleSelectionModelBase suppresses change notifications for its `selectedIndices` list. One such example (among many others) is in line 405:
if (getSelectionMode() == SINGLE) {
startAtomic();
quietClearSelection();
stopAtomic();
}
selectedIndices.set(row);
As a result, any listeners on `selectedIndices` will miss notifications, and will not be able to correctly reproduce the changes.
For example, run this piece of code:
ListView<String> listView = new ListView<>(FXCollections.observableArrayList("foo", "bar"));
MultipleSelectionModel<String> model = listView.getSelectionModel();
model.setSelectionMode(SelectionMode.SINGLE);
model.getSelectedIndices().addListener((ListChangeListener<? super Integer>)System.out::println);
model.select(0);
model.select(1);
You would expect the following output:
{ [0] added at 0 }
{ [0] replaced by [1] at 0 }
However, the actual output is:
{ [0] added at 0 }
{ [1] added at 0 }
The same problem occurs when subscribing to `selectedItems` instead of `selectedIndices`. Since selected items are updated whenever selected indices change, the `selectedItems` list will also miss some change notifications.
if (getSelectionMode() == SINGLE) {
startAtomic();
quietClearSelection();
stopAtomic();
}
selectedIndices.set(row);
As a result, any listeners on `selectedIndices` will miss notifications, and will not be able to correctly reproduce the changes.
For example, run this piece of code:
ListView<String> listView = new ListView<>(FXCollections.observableArrayList("foo", "bar"));
MultipleSelectionModel<String> model = listView.getSelectionModel();
model.setSelectionMode(SelectionMode.SINGLE);
model.getSelectedIndices().addListener((ListChangeListener<? super Integer>)System.out::println);
model.select(0);
model.select(1);
You would expect the following output:
{ [0] added at 0 }
{ [0] replaced by [1] at 0 }
However, the actual output is:
{ [0] added at 0 }
{ [1] added at 0 }
The same problem occurs when subscribing to `selectedItems` instead of `selectedIndices`. Since selected items are updated whenever selected indices change, the `selectedItems` list will also miss some change notifications.