JDK-8286261 : Selection of non-expanded non-leaf treeItem grows unexpectedly when adding two-level descendants
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: openjfx19
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-05-05
  • Updated: 2022-07-04
  • Resolved: 2022-05-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
openjfx17.0.4Fixed
Related Reports
Relates :  
Description
On a TreeTableView, with multiple selection enabled, when a non-expanded non-leaf node, that has at least two levels of descendants, is selected, the selection grows unexpectedly to the next sibling of the top-level node, once a new treeItem is added to the second (or deeper) level of the selected item.

The attached test shows the issue. 

- Node 0 (non-leaf) is selected and not expanded. It has as child Node 1, which also has Node 2 as child. 
- Node 3 is a sibling of Node 0.

When Node 4 is added as sibling of Node 2, Node 3 gets selected unexpectedly (see attached picture).

This issue can be reproduced with any JavaFX version and platform.

Comments
A pull request was submitted for review. URL: https://git.openjdk.org/jfx17u/pull/70 Date: 2022-06-29 19:43:14 +0000
30-06-2022

Changeset: 19a855e8 Author: Jose Pereda <jpereda@openjdk.org> Date: 2022-05-22 18:36:41 +0000 URL: https://git.openjdk.java.net/jfx/commit/19a855e8ec3972377359ecbc0f71808f34c1b288
22-05-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jfx/pull/791 Date: 2022-05-06 10:16:41 +0000
06-05-2022

In the test we have: - Node 0 <-- Collapsed |-- Node 1 |-- Node 2 |-- Node 4 <--- added - Node 3 After Node 4 is added, in https://github.com/openjdk/jfx/blob/master/modules/javafx.controls/src/main/java/javafx/scene/control/TreeTableView.java#L2614: shift += treeItem.isExpanded() ? addedSize : 0; where treeItem is set to the parent of Node 4, Node 1, which is expanded, and therefore shift is set to 1, which explains the unexpected selection of Node 3. However, given that the ancestor of Node 1 is collapsed, this shift shouldn't apply. A fix for this issue (which affects added/removed changes for both selection and focus models) should consider replacing all calls to treeItem.isExpanded() with something like (treeItem.isExpanded() And AllItsAncestors.areExpanded()).
06-05-2022