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

Fix options databinding by adding elements if they are not in the initial map #3539

Merged
merged 6 commits into from
Dec 17, 2017

Conversation

Siedlerchr
Copy link
Member

@Siedlerchr Siedlerchr commented Dec 15, 2017

Fixes #3538

I dunno if this is the best idea, but it works...


  • Change in CHANGELOG.md described
  • Tests created for changes
  • Screenshots added (for bigger UI changes)
  • Manually tested changed features in running JabRef
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)
  • If you changed the localization: Did you run gradle localizationUpdate?

@Siedlerchr Siedlerchr changed the title Add elements to map if not found Fix options databinding by adding elements if they are not in the initial map Dec 15, 2017
@tobiasdiez
Copy link
Member

Can you please explain the reason for the bug? In general, the string converter should not modify the source or target map.

@Siedlerchr
Copy link
Member Author

The reason for the bug is that the fromString method does a lookup in the map with the current txt in the field. If you enter a non predefined String into it, the map lookup returns null because not found.

return getItemMap().getOrDefault(string, null);

if (getItemMap().get(string) == null) {
getItemMap().put(string, (T) string);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks!
According to the documentation

a string converter property is provided to allow for developers to specify how to translate a users string into an object of type T, such that the value property may contain it. By default the converter simply returns the String input as the user typed it, which therefore assumes that the type of the editable ComboBox is String.

So you are right that the string converter should return something non-null even when the text is not recognized. However, there is no need to add it to the item map. Moreover, we need to handle the case when T is not a string type. Thus I would propose to create a new protected method that converts an unknown string to a T object. If not overridden, it should try to cast to T as in your code above (and throw an exception with details how to properly implement it if casting was not successful).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now added a method for checking.
We also need such kind for dates to allow custom values which we currently don't support. All input in the field will be cleared if not parseable

…ding

* upstream/master: (29 commits)
  New translations JabRef_en.properties (Indonesian)
  Changed workflow because of Crowdin
  Update various junit plugins
  Update johnrengelman.shadow from 2.0.1 -> 2.0.2
  update Junit5 from 5.0.2 -> 5.1.0-M1
  Update build-scan from 1.10.3 -> 1.11
  Update antlr4 from 4.7 -> 4.7.1
  Update log4j from 2.9.1 -> 2.10.0
  Update mockito-core from 2.12.0 -> 2.13.0
  New translations JabRef_en.properties (Vietnamese)
  New translations JabRef_en.properties (Italian)
  New translations JabRef_en.properties (Indonesian)
  New translations JabRef_en.properties (Greek)
  New translations JabRef_en.properties (German)
  New translations JabRef_en.properties (French)
  New translations JabRef_en.properties (Dutch)
  New translations JabRef_en.properties (Danish)
  New translations JabRef_en.properties (Chinese Simplified)
  New translations JabRef_en.properties (Japanese)
  New translations JabRef_en.properties (Norwegian)
  ...
@Siedlerchr Siedlerchr added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Dec 16, 2017
Copy link
Member

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good.

Copy link
Member

@LinusDietz LinusDietz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know a better solution out of the top of my head. Let's give it a try.

@LinusDietz LinusDietz merged commit 64e6145 into master Dec 17, 2017
@LinusDietz LinusDietz deleted the fixoptionsdatabinding branch December 17, 2017 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants