Fixes [8380933](https://bugs.openjdk.org/browse/JDK-8380933)
`TableView` and `TreeTableView` notify listeners when the selected cells change
after a sort with a very expensive check:
if (!newState.contains(prevItem)) {
removed.add(prevItem);
}
If `removed` is not empty, the method conservatively notifies the listeners
that the entire table was replaced:
ListChangeListener.Change<TreeTablePosition<S, ?>> c = new
NonIterableChange.GenericAddRemoveChange<>(0, itemCount, removed, newState);
The slowness is not attributed to the sort at all, but the logic in handling
change notifications. We can preserve this behavior and address the performance
issues with minimal changes by creating a temporary `HashSet` for the
`contains` checks.
However, this change notification is conservative and includes cells that
weren't affected by the sort. For example:
before sort: `{"a", "c", "b"}` with selected cells `{"0", "1"}`
after sort: `{"a", "b", "c"}` with selected cells `{"0", "2"}`
Although the first item is not affected by the sort, the current code will
notify listeners that cells `{"0", "2"}` were added and `{"1"}` was removed.
That is, the entire selection set was replaced.
This PR scans `prevState` and `newState` and fires change events for the
affected ranges only, which addresses the performance issues, and minimizes
notifications. This PR also handles the scenario where the size of the
selection set is changed after the sort. This seemed prudent as a custom sort
policy could do anything to the selection set.
-------------
Commit messages:
- simplify tests
- increment i in the header; use i instead of from
- fix tableview test, apply fix and make test for treetableview
- add unit tests to cover new behavior
- fire events for contiguous portions of the selected cells list
Changes: https://git.openjdk.org/jfx/pull/2131/files
Webrev: https://webrevs.openjdk.org/?repo=jfx&pr=2131&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8380933
Stats: 241 lines in 4 files changed: 213 ins; 18 del; 10 mod
Patch: https://git.openjdk.org/jfx/pull/2131.diff
Fetch: git fetch https://git.openjdk.org/jfx.git pull/2131/head:pull/2131
PR: https://git.openjdk.org/jfx/pull/2131