Skip to content

Added warning label that allows user to jump to already existing entry#13390

Merged
calixtus merged 17 commits into
JabRef:mainfrom
jayvardhanghildiyal:fix-for-issue-13261
Jul 4, 2025
Merged

Added warning label that allows user to jump to already existing entry#13390
calixtus merged 17 commits into
JabRef:mainfrom
jayvardhanghildiyal:fix-for-issue-13261

Conversation

@jayvardhanghildiyal

Copy link
Copy Markdown
Contributor

Closes #13261

This pull request adds a checkDOI function, listener logic and some fxml to NewEntryView.java and NewEntry.fxml. This addition aims to add a UI component that warns the user when trying to add an already existing entry to a library, while also allowing them to jump to it instead.

Steps to test

demonstration.mp4

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots/video added in PR description (if change is visible to the user)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

Comment thread jabgui/src/main/java/org/jabref/gui/newentry/NewEntryView.java Outdated
Comment thread jabgui/src/main/java/module-info.java Outdated
@jayvardhanghildiyal

Copy link
Copy Markdown
Contributor Author

Oh binaries for different platforms are re-checked with every commit ? I'll try to make fewer commits.

@calixtus

Copy link
Copy Markdown
Member

Hey @jayvardhanghildiyal , thank you for your PR and interest in JabRef.
About the Message "You must provide" - We are already using controlsfx validation badge in the preferences editor and the entry editor. Would you like to take a look in it and to modify your PR to display the message as a validation note on the doi field?

@calixtus

Copy link
Copy Markdown
Member

O sorry, i just noticed, that message "you must provide" was not your change, that was already before....

but anyways, maybe you still want to take a look into it on the fly?

Comment thread jabgui/src/main/java/org/jabref/gui/newentry/NewEntryViewModel.java Outdated
@jayvardhanghildiyal

jayvardhanghildiyal commented Jun 22, 2025

Copy link
Copy Markdown
Contributor Author

We are already using controlsfx validation

@calixtus I've looked into it and would like to explain what I think is happening. I'll post some code below mostly for my reference and understanding . Do correct me if I've missed the point of the request !

My Understanding of the validation logic

So this validator below helps control the visibility of FXML components.

idTextValidator = new FunctionBasedValidator<>(
            idText,
            StringUtil::isNotBlank,
            ValidationMessage.error(Localization.lang("You must specify an identifier.")));
public ReadOnlyBooleanProperty idTextValidatorProperty() {
        // logic to get validation status
    }

Validators like this can affect labels in the FXML file and the button in the new entry dialog window.

idErrorInvalidText.visibleProperty().....
idErrorInvalidFetcher.visibleProperty()....
generateButton.disableProperty().....

Requested Change

I have to:

  • move the label below the textfield
  • add it alongside all the other validation notes instead
  • use validation logic to modify my implementation
....
      // moved label and hyperlink
    <Label fx:id="duplicateSelectLabel" text="Entry already existing in library."/>
    <Hyperlink fx:id="duplicateSelectLink" text="%Select entry"/>
    <Label fx:id="idErrorInvalidText" text="%You must provide an identifier."/>
    <Label fx:id="idErrorInvalidFetcher" text="%You must select an identifier type."/>

....

@jayvardhanghildiyal

Copy link
Copy Markdown
Contributor Author

I think I've done it, but there is an error that says:

ERROR: Could not find citation style catalog

It comes from the CSLStyleLoader.java. I don't remember changing anything related to it. I'll try to see what it is about.

@calixtus

Copy link
Copy Markdown
Member

Ignore the error, this might because you did not initialize the submodules. But it should run anyways

@koppor

koppor commented Jun 22, 2025

Copy link
Copy Markdown
Member

It comes from the CSLStyleLoader.java. I don't remember changing anything related to it. I'll try to see what it is about.

On the command line, execute git submodule update to have all submodules in the correct state.

Merge latest upstream/main and execute ./gradlew :jabgui:run (or similar in IntelliJ). Then, these files should be generated. :)

As Carl said: it can be ignored for this issue.

@koppor koppor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think, something went wrong during merge of main - and the architecture needs to be fixed 😅

Comment thread jabgui/src/main/java/org/jabref/gui/newentry/NewEntryView.java Outdated
Comment thread jabgui/src/main/java/org/jabref/gui/newentry/NewEntryView.java Outdated
Comment thread jabgui/src/main/java/org/jabref/gui/newentry/NewEntryViewModel.java Outdated
@Siedlerchr

Siedlerchr commented Jun 23, 2025

Copy link
Copy Markdown
Member

Hi,
first, please look at the failing tests.

We discussed this in our devcall:

  • For consistency reason you should use a warning badge like e.g. in the entry editor

In the badge, show the text "Entry already exists in library XXXX" (can we show the library name?)
grafik

  • Add a label "Jump to entry" to the right inside the text field in case it already exists
    grafik

Use localization https://devdocs.jabref.org/code-howtos/localization.html#localization-in-fxml

@Siedlerchr Siedlerchr added the status: changes-required Pull requests that are not yet complete label Jun 23, 2025
@calixtus

Copy link
Copy Markdown
Member

A helpful page about validation in ui:
https://uxplanet.org/designing-more-efficient-forms-assistance-and-validation-f26a5241199d

Wa had a discussion about that in the devcall:
We use the small warning badges in the entry editor, in the preferences etc. Therefor for the sake of consistency, it should work the same here. A small warning badge on the left, a popover saying "Entry already exists".

However in general, we think that the tooltips on the validation badges are not the best ui design. We go with it for now, as this is the current ui design approach in other places and we should think in the future to do this differently. Eventually when the entry editor will be rewritten (TM 😬) But for now, move forward as @Siedlerchr suggested.

Mind that in rtl languages the "Jump to entry" should appear on the left of the textinput control.

@jayvardhanghildiyal

Copy link
Copy Markdown
Contributor Author

Hi @Siedlerchr ! I will keep looking at the tests.

In the badge, show the text "Entry already exists in library XXXX" (can we show the library name?)

Yes, that is doable ! In the commit before the latest one, I used the getOpenDatabases method to get access to all entries across all databases. I can make, say, a map that holds all BibEntrys and their corresponding LibraryTabs and use it to update the validation badge. But I don't think I can jump to another library from the currently active one. So, in case the entry does not belong to the current library tab, we won't be able to jump to it. We would only be able to show the validation badge.

To highlight the entry present in the current library I am using the showAndEdit method. But while using stateManager.getOpenDatabases(), I realised that the entry has to belong to the current library or the method just displays a blacked-out edit menu. I was thinking that maybe I can use the showLibraryTab method from LibraryTabContainer.java, followed by the showAndEdit method to solve that problem. But we don't have access to an instance of LibraryTabContainer either.

I'll try my best !

@calixtus

Copy link
Copy Markdown
Member

A new map with all BibEntry(ies)? This is a bad idea. Think of a library with 10.000 entries. Not uncommon.

@jayvardhanghildiyal

jayvardhanghildiyal commented Jun 26, 2025

Copy link
Copy Markdown
Contributor Author

Looks good so far, just remove the commented out code and i think it's ready

Hey @Siedlerchr ! I wanted to talk about the jump to entry thingy.

Since I do not have access to other LibraryTabs (reason discussed before), let me know which implementation would be better:

  • doiCache has access to all entries across all libraries to warn the user, but we don't give them the option to jump to that entry.
  • doiCache has access to all entries in the currently active library and we give the user the ability to jump to that entry.

I think utility-wise, option 1 is better because the implementation will alert the user over all the entries. And if they want to add a new entry to a library, they will know that the same one exists somewhere else too. Not being able to jump to it sucks, but at least the user will be aware. I will now send out a commit that implements option 1, which I personally think will give out more consistent and useful warnings.

Do let me know ! In the meantime, I'll remove the commented code and add the suggested changes !

Comment thread jabgui/src/main/java/org/jabref/gui/newentry/NewEntryViewModel.java Outdated
@Siedlerchr

Copy link
Copy Markdown
Member

After thinking again of it, The new entry dialog is bound to a library, so it makes sense to only check the entries of the current library and then the jump to entry is useful as well.

And one thing, it's very hard to see the warning, because when I do mouseover I see the tooltip
grafik

so maybe disable that tooltip when the warning is shown?

@jayvardhanghildiyal

Copy link
Copy Markdown
Contributor Author

Oh that's odd. The last time I hovered over the symbol, appeared every single time. I'll look into it once again.

@jayvardhanghildiyal

Copy link
Copy Markdown
Contributor Author

Hi again ! I've added the suggestions !

Working with the Tooltip idTextTooltip methods was a bit weird, because none of it's properties seem to affect it in any way. I figured out a work around.

Also, the jump to entry element that appears on the TextField idText is a hyperlink. Thought it was more intuitive for the user. I hope that is alright.

@koppor

koppor commented Jul 2, 2025

Copy link
Copy Markdown
Member

Current state:

image


Can be improved by the user NOT to have the DOI in the clipboard:

image


Questions:

  1. Can the tooltip for the field be hidden if the clipboard handling kicks in? You already managed for typing, but what at the startup?
  2. Is it possible to move the "jump" label a bit more left so that there is more whitespace at the right?

@calixtus @Siedlerchr

I liked the initial implementation better - much more consistent to other apps :)

image

If question 1 cannot be solved, I vote for reverting to this... Can we have a call on it?

@calixtus

calixtus commented Jul 2, 2025

Copy link
Copy Markdown
Member

Keep consistency. If we do a custom design here, the user will go wtf.

@koppor

koppor commented Jul 2, 2025

Copy link
Copy Markdown
Member

Keep consistency. If we do a custom design here, the user will go wtf.

Move fast? 😇

Hope that question 1 can be solved...

@calixtus

calixtus commented Jul 2, 2025

Copy link
Copy Markdown
Member

About question 1: Should be easy enough with a property being added to the validation function in the viewmodel

@jayvardhanghildiyal

Copy link
Copy Markdown
Contributor Author

Oh sorry guys. I didn't get a notification for this discussion.

I guess question 2 should be easy enough to implement.

I have understood the first question. That's a very good catch ! I don't know how I didn't notice that. I'll see what I can do !

doiCache.clear();
Optional<BibDatabaseContext> activeDatabase = stateManager.getActiveDatabase();

activeDatabase.stream()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we really need .stream() here - isn't a simple map enough?

@jayvardhanghildiyal jayvardhanghildiyal Jul 4, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I guess I can make it cleaner.

I had a question though. Can users create BibEntrys that have a null DOI value in JabRef ? I learned that ifPresents are required while working with optionals, but I was wondering if we can make do without a few.

activeDatabase.map(BibDatabaseContext::getEntries)
                    .ifPresent(entries -> {                                    
                        entries.forEach(entry -> {
                            entry.getField(StandardField.DOI)
                                 .ifPresent(doi -> {
                                     doiCache.put(doi, entry);
                                 });
                        });
                    });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No null values allowed - this would contradict Optional architecture.

@trag-bot

trag-bot Bot commented Jul 4, 2025

Copy link
Copy Markdown

@trag-bot didn't find any issues in the code! ✅✨

@koppor koppor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good.

The implementation is at risk that it is very slow for large libraries (with 10k+ entries)

Future work:

  • Backgroundtask for DOI caching
  • Cache the DOIs "globally" - do a subscription on changes of things etc. (complicated algorithm) -- maybe use the postgres database with views there --> nice opportunity to learn about SQL use

@koppor koppor removed the status: changes-required Pull requests that are not yet complete label Jul 4, 2025
@calixtus

calixtus commented Jul 4, 2025

Copy link
Copy Markdown
Member

A bird in the hand is worth two in the bush.
Just kidding. Looks good! Thanks for your contribution and your patience with our review process.

@calixtus calixtus added this pull request to the merge queue Jul 4, 2025
Merged via the queue into JabRef:main with commit 714e3ba Jul 4, 2025
1 check passed
@jayvardhanghildiyal

jayvardhanghildiyal commented Jul 4, 2025

Copy link
Copy Markdown
Contributor Author

Thank you so much for being patient and giving the important insights necessary to complete this issue ! I'm kinda new to this, but I'd like to contribute more.

Is it okay if i assign other issues to myself and continue contributing ?

@koppor

koppor commented Jul 5, 2025

Copy link
Copy Markdown
Member

Is it okay if i assign other issues to myself and continue contributing ?

Sure - you can also work on the future work outlined at #13390 (review).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New Entry: If DOI already exists in library offer "jump to entry"

5 participants