jfx icon indicating copy to clipboard operation
jfx copied to clipboard

8235491: Tree/TableView: implementation of isSelected(int) violates contract

Open andy-goryachev-oracle opened this issue 3 years ago • 27 comments

  1. reword SelectionModel.isSelected(int) javadoc, removing incorrect statement "Is functionally equivalent to calling getSelectedIndices().contains(index)."
  2. reimplement TableView.TableViewSelectionModel.isSelected(int) method to return true when at least one cell in any column is selected on the given row (was: all columns)
  3. change selectRowWhenInSingleCellSelectionMode() and selectRowWhenInSingleCellSelectionMode2() in TableViewSelectionModelImplTest to reflect new reality.

NOTE: proposed change alters semantics of isSelected(int) method (in the right direction, in my opinion).


Progress

  • [x] Change must not contain extraneous whitespace
  • [x] Commit message must refer to an issue
  • [ ] Change requires a CSR request to be approved
  • [ ] Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issues

  • JDK-8235491: Tree/TableView: implementation of isSelected(int) violates contract
  • JDK-8290741: Tree/TableView: implementation of isSelected(int) violates contract (CSR)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx pull/839/head:pull/839
$ git checkout pull/839

Update a local copy of the PR:
$ git checkout pull/839
$ git pull https://git.openjdk.org/jfx pull/839/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 839

View PR using the GUI difftool:
$ git pr show -t 839

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/839.diff

andy-goryachev-oracle avatar Jul 19 '22 22:07 andy-goryachev-oracle

:wave: Welcome back angorya! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

bridgekeeper[bot] avatar Jul 19 '22 22:07 bridgekeeper[bot]

Because there is a spec change, and a behavioral change, this needs a CSR. What are the implications of this change on applications?

/reviewers 2 /csr

kevinrushforth avatar Jul 19 '22 22:07 kevinrushforth

@kevinrushforth The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

openjdk[bot] avatar Jul 19 '22 22:07 openjdk[bot]

@kevinrushforth has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@andy-goryachev-oracle please create a CSR request for issue JDK-8235491 with the correct fix version. This pull request cannot be integrated until the CSR request is approved.

openjdk[bot] avatar Jul 19 '22 22:07 openjdk[bot]

I think the behavior of utility method SelectionModel.isSelected(int) was poorly defined in the context of TableView, and/or incorrect in case of cell selection enabled.

People who used TableView.isSelected(int, TableColumn|TableColumnBase) will be ok, but those who assumed (arguable incorrect) implementation may need to revisit their code, and only in the case when cell selection is enabled.

andy-goryachev-oracle avatar Jul 19 '22 22:07 andy-goryachev-oracle

OK. When you create the CSR, you can add a note about possible compatibility impact. Seems it should be low.

kevinrushforth avatar Jul 19 '22 22:07 kevinrushforth

@kleopatra Would you have time / interest to review this?

kevinrushforth avatar Jul 19 '22 22:07 kevinrushforth

Kevin: Proposed CSR - JDK-8290741 what would be the "correct fix version"?

andy-goryachev-oracle avatar Jul 21 '22 21:07 andy-goryachev-oracle

Kevin: Proposed CSR - JDK-8290741 what would be the "correct fix version"?

openjfx20

kevinrushforth avatar Jul 21 '22 21:07 kevinrushforth

  1. Would you suggest possible clarification please?

As you have mentioned the impact of this change & using alternate API in "Compatibility Impact" section of the CSR - we are good! No additional change is required.

One minor issue - the description of this PR starts with ...ontract - looks like some typo.

aghaisas avatar Jul 28 '22 10:07 aghaisas

One minor issue - the description of this PR starts with ...ontract - looks like some typo.

github truncated the title and placed the remainder into PR description, I just left it there. fixed.

andy-goryachev-oracle avatar Jul 28 '22 15:07 andy-goryachev-oracle

forgot: will not be near my IDE until next Monday - then I'll run the tests and see for myself :)

kleopatra avatar Jul 28 '22 16:07 kleopatra

@kleopatra : Various scenarios are pretty well covered by the existing tests. Just in case, I've added tests to exercise the model with cell selection enabled.

andy-goryachev-oracle avatar Aug 03 '22 23:08 andy-goryachev-oracle

The doc changes look fine to me, since I agree that further clarification of MultipleSelectionModel.isSelected can be done in a follow-up.

kevinrushforth avatar Aug 04 '22 23:08 kevinrushforth

a bit confused about the csr - shouldn't that be focused entirely on SelectionModel.isSelected)? That's where we clarify the contract - all changes to TableXXSelectionModels are implementation changes, fixing their contract violation. So I would expect these not to be mentioned at all in the csr.

BTW: isSelected is not a convenience method - that's already changed here, all mentions of its being so should be removed from the csr as well, IMO :)

kleopatra avatar Aug 05 '22 10:08 kleopatra

@kleopatra : Various scenarios are pretty well covered by the existing tests.

good - we seem to be lucky :)

kleopatra avatar Aug 05 '22 10:08 kleopatra

a bit confused about the csr - shouldn't that be focused entirely on SelectionModel.isSelected)? That's where we clarify the contract - all changes to TableXXSelectionModels are implementation changes, fixing their contract violation. So I would expect these not to be mentioned at all in the csr.

The specification section of the CSR should (and does) list only the spec change to SelectionModel.isSelected. Since there could be an impact to applications that rely on the current behavior, it also seems reasonable to list those in the Solution section (as well as the Compatibility concerns section). I think that the Summary should start by listing the spec change to SelectionModel.isSelected, but it seems useful to also say that the implementation of TableXXSelectionModel is changing as a result.

BTW: isSelected is not a convenience method - that's already changed here, all mentions of its being so should be removed from the csr as well, IMO :)

Agreed.

kevinrushforth avatar Aug 05 '22 14:08 kevinrushforth

The specification section of the CSR should (and does) list only the spec change to SelectionModel.isSelected. Since there could be an impact to applications that rely on the current behavior, it also seems reasonable to list those in the Solution section (as well as the Compatibility concerns section). I think that the Summary should start by listing the spec change to SelectionModel.isSelected, but it seems useful to also say that the implementation of TableXXSelectionModel is changing as a result.

makes sense - thanks for the explanation :)

kleopatra avatar Aug 06 '22 09:08 kleopatra

the last line fails for cell selection enabled with this implementation and passes when delegating to super (or not override isSelected(int) at all)

I think you are right, @kleopatra ! Took me a while, but I see your point now. This method should indeed delegate to super(), or not be overridden at all.

Thank you for creating the tests - they deserve to be integrated into TableViewSelectionModelImplTest, with your permission.

andy-goryachev-oracle avatar Aug 08 '22 21:08 andy-goryachev-oracle

Aside: there is a general issue with cell selection not updated on columns modification (the selection visual is kept on the same column index without changing selectedCells accordingly - technically due to looping across the visibleLeafCells vs. all leaf columns. Might or might not be what ux requires, but the selectedCells must be in sync with the visuals always).

Personally, I feel that any manipulations with the columns structure should clear the existing selection. I would imagine it's such a rare operation, and the "fix" is so easy (clear selection) that it's not worth even creating an issue for - but I could be wrong.

Don't remember if we have it covered in JBS?

I did not find a close match. There is JDK-8095010; there is ticket you might be familiar with JDK-8093855; and one possibly related JDK-8091191.

andy-goryachev-oracle avatar Aug 08 '22 22:08 andy-goryachev-oracle

I would lean towards creating a new issue, unless one of the three you listed above is a natural fit.

kevinrushforth avatar Aug 08 '22 22:08 kevinrushforth

I think you are right, @kleopatra ! Took me a while, but I see your point now. This method should indeed delegate to super(), or not be overridden at all.

I would prefer removing it (reducing clutter :) As it's a private class, there will be no publicly visible change.

Thank you for creating the tests - they deserve to be integrated into TableViewSelectionModelImplTest, with your permission.

sure, everything here is open source and we don't want to duplicate efforts :)

Probably need to do the same fix and test in TreeTableView selection?

kleopatra avatar Aug 09 '22 11:08 kleopatra

Personally, I feel that any manipulations with the columns structure should clear the existing selection. I would imagine it's such a rare operation, and the "fix" is so easy (clear selection) that it's not worth even creating an issue for - but I could be wrong.

haha .. are you prepared to get lynched by furious users 😜 Just imagine you selected several cells across the table, then decide to hide an unrelated column (which is not as rare as you assume :) and all your previous selection work is destroyed.

Don't remember if we have it covered in JBS?

I did not find a close match. There is JDK-8095010; there is ticket you might be familiar with JDK-8093855; and one possibly related JDK-8091191.

none of those seem to be related to modification of columns, so tend to agree with Kevin that we should file a new issue

kleopatra avatar Aug 09 '22 11:08 kleopatra

@kleopatra : good point! I've tested with swing / JTable, and removing a column seem to deselect the cells in the removed column. I guess this should be the expected behavior - to clear selection in the hidden column(s)? If the app requirements call for preserving selection, this can be done on the app level (store the hidden cell selection and restore once the cells come to view)?

Created a separate ticket (JDK-8292143).

andy-goryachev-oracle avatar Aug 09 '22 18:08 andy-goryachev-oracle

the tests - they deserve to be integrated into TableViewSelectionModelImplTest, with your permission.

similar tests (along with that in the bug report) adapted to treeTable should be added to the treeTable test - we should keep them as sync'ed as possible, to not make future maintainers wonder why they aren't included :)

kleopatra avatar Aug 11 '22 12:08 kleopatra

similar tests (along with that in the bug report) adapted to treeTable should be added to the treeTable test - we should keep them as sync'ed as possible, to not make future maintainers wonder why they aren't included :)

The tests were added to both TableViewSelectionModelImplTest and TreeTableViewSelectionModelImplTest.

andy-goryachev-oracle avatar Aug 11 '22 16:08 andy-goryachev-oracle

The tests were added to both TableViewSelectionModelImplTest and TreeTableViewSelectionModelImplTest.

hmm .. in TreeTableViewSelectionModelImplTest, I don't see any of the testRowSelectionAfterSelectAndHideLastColumnXX nor testSelectRowWhenInSingleCellSelectionModeIsSelected, what am I missing?

kleopatra avatar Aug 12 '22 11:08 kleopatra

hmm .. in TreeTableViewSelectionModelImplTest, I don't see any of the testRowSelectionAfterSelectAndHideLastColumnXX nor testSelectRowWhenInSingleCellSelectionModeIsSelected, what am I missing?

you are right... I am so sorry. missed this one while cherry picking from another branch. will fix it soon.

would it be possible to review https://github.com/openjdk/jfx/pull/858 so there is no need to cherry pick, please?

andy-goryachev-oracle avatar Aug 12 '22 15:08 andy-goryachev-oracle

you are right... I am so sorry. missed this one while cherry picking from another branch. will fix it soon.

no problem, shit happens :)

kleopatra avatar Aug 15 '22 10:08 kleopatra