happens when cell selection is enabled with multiple mode
failing test:
@Test public void selectRowWhenInMultipleCellSelectionModeNotification() {
model.setSelectionMode(SelectionMode.MULTIPLE);
model.setCellSelectionEnabled(true);
model.clearSelection();
List<Change> changes = new ArrayList<>();
model.getSelectedIndices().addListener((Change<? extends Integer> c) -> {
changes.add(c);
// Note: simple logging points to the reason for the error:
// System.out.println(c);
});
model.select(1);
assertEquals("indices must fire single change: ", 1, changes.size());
}
The underlying reason is ControlUtils.updateSelectedIndices: its task is to map the notifications received from selectedCells to notifications of selectedIndices. It fails by sending multiple notifications for the same row (probably with incorrect to/from coordinates)
Yeah, the change coordinates fired by updateSelectedIndices are definitely wrong:
// the change originated in selectedCells, coordinates in a flat list
public static <S> void updateSelectedIndices(MultipleSelectionModelBase<S> sm, ListChangeListener.Change<? extends TablePositionBase<?>> c) {
sm.selectedIndices._beginChange();
while (c.next()) {
// [.. ] do some magic to change the indices under their feet ..
// error: c.getFrom is in coordinates of the list of cells
final int to = c.getFrom() ... ;
// error: mark a change multiple time (for each next)
if (c.wasReplaced()) {
sm.selectedIndices._nextReplace(c.getFrom(), to, removed);
} ...
}