Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8087555: [ChoiceBox] uncontained value not shown #191

Closed
wants to merge 2 commits into from

Conversation

@kleopatra
Copy link
Collaborator

@kleopatra kleopatra commented Apr 20, 2020

The issue is that ChoiceBoxSkin
a) doesn't update the text of the label if the value is not contained in the items
b) doesn't respect converter for label text

Fixed by

  • listening to value changes to update the label
  • removing ad-hoc updates (not needed), added update on converter change
  • passing all label updates through converter

Added test for text updates that failed before the fix and pass after (note: there were no tests for the display text, so for coveragy, contains also tests that passed before as well as after)


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

Reviewers

  • Ambarish Rapte (arapte - Reviewer)
  • Ajit Ghaisas (aghaisas - Reviewer)

Download

$ git fetch https://git.openjdk.java.net/jfx pull/191/head:pull/191
$ git checkout pull/191

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Apr 20, 2020

👋 Welcome back fastegal! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request.

@openjdk openjdk bot added the rfr label Apr 20, 2020
@mlbridge
Copy link

@mlbridge mlbridge bot commented Apr 20, 2020

Webrevs

@kevinrushforth
Copy link
Member

@kevinrushforth kevinrushforth commented Apr 21, 2020

/reviewers 2

@kevinrushforth
Copy link
Member

@kevinrushforth kevinrushforth commented Apr 21, 2020

@aghaisas @arapte can you review?

@openjdk
Copy link

@openjdk openjdk bot commented Apr 21, 2020

@kevinrushforth
The number of required reviews for this PR is now set to 2 (with at least 1 of role reviewers).

@arapte
Copy link
Member

@arapte arapte commented Apr 24, 2020

I have not reviewed the code but have only tested it.
The value of index is not defined when an uncontained item is selected.
With the current implementation (with and without this PR change) there is a difference of behavior when an uncontained item is selected Vs when an existing item is selected, in scenarios as below,

=> clearSelection()
a) scenario 1

  1. Select/set an uncontained item. selectedIndex would be -1.
  2. call clearSelection(), Does NOT clear the selected item to null
    b) scenario 2
  3. Select an item at index 2, selectedIndex would be 2.
  4. Select/set an uncontained item. selectedIndex would remain 2.
  5. call clearSelection(), => clears the selected item to null and selected index to -1

and similarly the difference of behavior can be observed with selectNext(), selectPrevious()

This is not formally documented(nor decided), so we might need to decide on a value of index for an uncontained value.

@kleopatra
Copy link
Collaborator Author

@kleopatra kleopatra commented Apr 24, 2020

I have not reviewed the code but have only tested it.

Thanks for taking an initial look :) Just keep in mind that this issue is focused on displaying of the box' value reliably.

The value of index is not defined when an uncontained item is selected.

yeah the spec is rather .. well, suboptimal at some crucial points (see also JDK-8088012). To keep the state logically consistent, we need an invariant like:

 assertEquals(getItems().indexOf(selectedItem), selectedIndex)

Which seems to be hinted at in a code comment in SingleSelectionModel.select(item):

    // if we are here, we did not find the item in the entire data model.
    // Even still, we allow for this item to be set to the give object.
    // We expect that in concrete subclasses of this class we observe the
    // data model such that we check to see if the given item exists in it,
    // whilst SelectedIndex == -1 && SelectedItem != null.

For ChoiceBox, that will be fixed in JDK-8241999 (ready for push as soon as this is integrated).

With the current implementation (with and without this PR change) there is a difference of behavior when an uncontained item is selected Vs when an existing item is selected, in scenarios as below,

=> clearSelection()
a) scenario 1

1. Select/set an uncontained item. `selectedIndex` would be -1.

2. call `clearSelection()`, Does NOT clear the selected item to null

true, that's spec'ed in ComboBox only .. so by analogy I considered it being the same here. Hmm .. might need an update of the doc?

   b) scenario 2

3. Select an item at index 2, `selectedIndex` would be 2.

4. Select/set an uncontained item. `selectedIndex` would remain 2.

exactly that is JDK-8241999

5. call `clearSelection()`, => clears the selected item to null  and selected index to -1

interesting, hadn't noticed yet - will add a test to the other fix, thanks :)

and similarly the difference of behavior can be observed with selectNext(), selectPrevious()

yeah, that's another issue .. selection issues are a bottomless pit ..

This is not formally documented(nor decided), so we might need to decide on a value of index for an uncontained value.

see the "natural" constraint above - without we get into hell, IMO.

Good points all, thanks again!

@arapte
Copy link
Member

@arapte arapte commented Apr 27, 2020

Which seems to be hinted at in a code comment in SingleSelectionModel.select(item):

I agree that selectedIndex should be -1 for an uncontained value, so that the below condition always holds true. And this is already working well with ComboBox.

assertEquals(getItems().indexOf(selectedItem), selectedIndex)

The fix for JDK-8241999 would solve most of the behavior differences of contained Vs uncontained item selection. (that I was looking at selectPrevious(), selectNext()).

true, that's spec'ed in ComboBox only .. so by analogy I considered it being the same here. Hmm .. might need an update of the doc?

Thanks for the the pointer, After reading it, I have a doubtful understanding about it as, that,

The spec is only about ComboBox.valueProperty() and not about SelectionModel.selectedIndex or SelectionModel.selectedItem.
so clearSelection() can/should clear the SelectionModel state but should not clear ComboBox.valueProperty().

And ComboBox does not follow this spec,
In below scenario ComboBox.valueProperty() is cleared to NULL.

comboBox.getSelectionModel().select(comboBox.getItems(1));
comboBox.getSelectionModel().clearSelection(); => clears the SelectionModel.selectedIndex to -1, SelectionModel.selectedItem and ComboBox.getValue() to NULL.

So I think, for ChoieBox, In addition to doc change we would need fix the behavior as well, and maintain same behavior of clearSelection() with contained and uncontained items.

But again this is a different issue and not related to this fix.

So the fix itself looks good to me along with the upcoming fix for JDK-8241999.

@arapte
arapte approved these changes Apr 27, 2020
@aghaisas
Copy link
Collaborator

@aghaisas aghaisas commented Apr 28, 2020

The fix is OK.

Test file header should have year 2020 and not 2019.

@arapte
arapte approved these changes Apr 28, 2020
@openjdk
Copy link

@openjdk openjdk bot commented Apr 28, 2020

@kleopatra This change now passes all automated pre-integration checks. When the change also fulfills all project specific requirements, type /integrate in a new comment to proceed. After integration, the commit message will be:

8087555: [ChoiceBox] uncontained value not shown

Reviewed-by: arapte, aghaisas
  • If you would like to add a summary, use the /summary command.
  • To credit additional contributors, use the /contributor command.
  • To add additional solved issues, use the /solves command.

Since the source branch of this PR was last updated there have been 4 commits pushed to the master branch:

  • 818ac00: 8175358: Memory leak when moving MenuButton into another Scene
  • 91d4c8b: 8241737: TabPaneSkin memory leak on replacing selectionModel
  • 48476eb: 8241582: Infinite animation does not start from the end when started with a negative rate
  • dedf7cb: 8242490: Upgrade to gcc 9.2 on Linux

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid automatic rebasing, please merge master into your branch, and then specify the current head hash when integrating, like this: /integrate 818ac007ca3ab3590ff5a39d86d35f8f337df873.

As you do not have Committer status in this project, an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@arapte, @aghaisas) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready label Apr 28, 2020
@kleopatra
Copy link
Collaborator Author

@kleopatra kleopatra commented Apr 28, 2020

/integrate

@openjdk
Copy link

@openjdk openjdk bot commented Apr 28, 2020

@kleopatra
Your change (at version 9b9a28a) is now ready to be sponsored by a Committer.

@openjdk openjdk bot added the sponsor label Apr 28, 2020
@arapte
Copy link
Member

@arapte arapte commented Apr 28, 2020

/sponsor

@openjdk openjdk bot closed this Apr 28, 2020
@openjdk openjdk bot added integrated and removed sponsor ready rfr labels Apr 28, 2020
@openjdk
Copy link

@openjdk openjdk bot commented Apr 28, 2020

@arapte @kleopatra The following commits have been pushed to master since your change was applied:

  • 818ac00: 8175358: Memory leak when moving MenuButton into another Scene
  • 91d4c8b: 8241737: TabPaneSkin memory leak on replacing selectionModel
  • 48476eb: 8241582: Infinite animation does not start from the end when started with a negative rate
  • dedf7cb: 8242490: Upgrade to gcc 9.2 on Linux

Your commit was automatically rebased without conflicts.

Pushed as commit ceb3fce.

@kleopatra kleopatra deleted the kleopatra:bug-fix-JDK-8087555 branch May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants