Add compare button to duplicates in Citation relations tab#11915
Conversation
…ionsTab. - Added localization key for 'Compare with duplicate entries'.
|
For opening the compare window check out the MergeDialogEntriesDialog |
…r comparing and merging duplicate entries. - Updated changelog for compare button feature.
| - We added a different background color to the search bar to indicate when the search syntax is wrong. [#11658](https://github.com/JabRef/jabref/pull/11658) | ||
| - We added a setting which always adds the literal "Cited on pages" text before each JStyle citation. [#11691](https://github.com/JabRef/jabref/pull/11732) | ||
| - We added a new plain citation parser that uses LLMs. [#11825](https://github.com/JabRef/jabref/issues/11825) | ||
| - Added a compare button to the duplicates in the citation relations tab to open the "Possible duplicate entries" window. [#11192](https://github.com/JabRef/jabref/issues/11192) |
| Button compareButton = IconTheme.JabRefIcons.MERGE_ENTRIES.asButton(); | ||
| compareButton.setTooltip(new Tooltip(Localization.lang("Compare with duplicate entries"))); | ||
| compareButton.setOnMouseClicked(event -> { | ||
| openPossibleDuplicateEntriesWindow(entry); |
There was a problem hiding this comment.
Does this mean that every entry is potentially a duplicate?
There was a problem hiding this comment.
In the broader context of the code, there’s a DuplicateCheck object that checks if an entry in the database has a duplicate. When the comparison button is created, the button is only shown when a potential duplicate is detected. This happens because of the duplicateCheck.containsDuplicate() method. If this method detects a duplicate for a given entry, the compareButton will allow the user to compare the entries. I'm sorry.I may not understand the point of the question, do I need to make any changes?😅
There was a problem hiding this comment.
Ah, CitationRelationItem.isLocal() returns whether it's a duplicate or not?
… into fix-for-issue-11192
koppor
left a comment
There was a problem hiding this comment.
Good first step.
After clicking "merge", the current entry should be kept selected - and not the merged entry be selected.
However, does not always work. It uses the entry of the citation relation if the entry was added to the library before
- Open citationr relations for paper P1
- Add citing paper P2 to library
- Edit P2 using JabRef
- Go back toi P1: Citatoin relations
- See that P2 is used - and not the paper retrieved by citation relatations
This could be another issue -- if you don't see how to fix it. - I think, there "only" needs to be a clone made when adding an entry to the library.
| vContainer.getChildren().add(jumpTo); | ||
|
|
||
| Button compareButton = IconTheme.JabRefIcons.MERGE_ENTRIES.asButton(); | ||
| compareButton.setTooltip(new Tooltip(Localization.lang("Compare with duplicate entries"))); |
There was a problem hiding this comment.
I think "duplicate" is not a good term. It is about an existing entry in the library
| compareButton.setTooltip(new Tooltip(Localization.lang("Compare with duplicate entries"))); | |
| compareButton.setTooltip(new Tooltip(Localization.lang("Compare with existing entries"))); |
- Fixed bug that when adding an entry to the library from Citation Relations Tab by adding the entry's clone instead of itself. - Optimised openPossibleDuplicateEntriesWindow function in CitationRelationsTab.java to show result of undo and redo. - Implemented that After clicking "merge", the current entry will be kept selected - and not the merged entry be selected.
|
Hi@koppor, I think my approach to change focus is a bit stupid, by reading the code in the LibraryTab.java and MainTable.java, it seems like that new added entry will always be selected, and my approach won't affect other functionalities. Any better suggestions? Thank you very much for your help! |
|
test failed, I will try to fix🥲 |
…ationsRelationsTabViewModelTest with clone entries.
… into fix-for-issue-11192
koppor
left a comment
There was a problem hiding this comment.
IMHO you should add code comments on the "why" of some things. I think, the five lines I commented on can just be removed without any change in functionality.
| BibEntry current = libraryTab.getEntryEditor().getCurrentlyEditedEntry(); | ||
| stateManager.getActiveDatabase().get().getDatabase().removeEntry(current); | ||
| stateManager.getActiveDatabase().get().getDatabase().insertEntry(current); |
There was a problem hiding this comment.
Why this? These three lines remove and add the same entry? Can these lines just be removed?
There was a problem hiding this comment.
😅As I said, this is a stupid method to change selected entry from merged entry to original one. And I have tested that org.jabref.gui.LibraryTab#clearAndSelect seems to have nothing to do with merge entries, the operation of merge entries should be related to Maintable#clearAndSelect, which will clear the current selection and select the entry just added. So I remove and add the original entry to make sure the original entry be selected after merge. I think I have found a better way. I'm working on it!🥰
| } | ||
|
|
||
| public void importCleanedEntries(List<BibEntry> entries) { | ||
| entries = entries.stream().map(entry -> (BibEntry) entry.clone()).filter(Objects::nonNull).toList(); |
There was a problem hiding this comment.
Why this filter(Objects::nonNull)? I think, this can be removed. -- the list of entries should not contain null
(This code fragment seems to be AI generated - otherwise, it is OK)
| libraryTab.showAndEdit(current); | ||
| libraryTab.clearAndSelect(current); |
There was a problem hiding this comment.
Here you change to the new entry. What happens if you remove these two lines?
This is part of the journey! Suggestion add a breakpoint at |
…t original entry be selected after citation item merge. - Modified MainTable#clearAndSelect to ensure original entry be selected after citation item merge. - Added some comments.
koppor
left a comment
There was a problem hiding this comment.
Two things; I think, they correlate. If one is fixed, the other might be fixed, too.
Jumping to an entry does not work any more
Cllick on the button just scrolls to another position in the "Citation relations".
Keep scroll position
After merging of an entry, the scroll bar of "Citation relations" moves up.
Before:
After:
My test entry:
@Article{Thames2016,
author = {Thames, Lane and Schaefer, Dirk},
date = {2016},
journaltitle = {Procedia CIRP},
title = {Software-defined Cloud Manufacturing for Industry 4.0},
doi = {10.1016/j.procir.2016.07.041},
issn = {2212-8271},
pages = {12--17},
volume = {52},
abstract = {Procedia CIRP, 52 (2016) 12-17. doi:10.1016/j.procir.2016.07.041},
publisher = {Elsevier BV},
}…in MainTable.java to let original entry get selected after merge instead of selecting new merged entry.
… changed to new merged entry, need to refresh selected citation relation item to ensure that the item link to current local entry instead of the old one.
| vContainer.getChildren().add(jumpTo); | ||
|
|
||
| Button compareButton = IconTheme.JabRefIcons.MERGE_ENTRIES.asButton(); | ||
| compareButton.setTooltip(new Tooltip(Localization.lang("Compare with existing entries"))); |
There was a problem hiding this comment.
I think, it compares with a single entry – string should be adapted!
| MergeEntriesDialog dialog = new MergeEntriesDialog(localEntry, duplicateEntry, preferences); | ||
| dialog.setTitle(Localization.lang("Possible duplicate entries")); | ||
|
|
||
| Optional<EntriesMergeResult> mergeResultOpt = dialogService.showCustomDialogAndWait(dialog); |
There was a problem hiding this comment.
Do you really need the Opt suffix? - You can name it entriesMergeResult and one line below use mergeResult if you like shorter variables.
|
|
||
| Optional<EntriesMergeResult> mergeResultOpt = dialogService.showCustomDialogAndWait(dialog); | ||
| mergeResultOpt.ifPresentOrElse(entriesMergeResult -> { | ||
| entriesMerge = entriesMergeResult.mergedEntry(); |
There was a problem hiding this comment.
Please rename to mergedEntry. -- The variable name should state what's stored inside. It are not multiple entries. Moreover, consistency with a method name is nice.
|
|
||
| private long lastKeyPressTime; | ||
| private String columnSearchTerm; | ||
| private boolean citationMerge = false; // citation merge flag |
There was a problem hiding this comment.
The comment could be directed from the variable name. The "why" is missing. Either add a comment why this is required - or remove the comment (both is OK for me)
Name the variable citationMergeMode.
| .findFirst(); | ||
| } | ||
|
|
||
| public void setCitationMerge(boolean merge) { |
There was a problem hiding this comment.
Maybe name it setCitationMergeMode
| BibDatabase database = stateManager.getActiveDatabase().get().getDatabase(); | ||
|
|
||
| database.removeEntry(entriesMergeResult.originalLeftEntry()); | ||
| database.insertEntry(entriesMergeResult.mergedEntry()); |
There was a problem hiding this comment.
Right before this line, the setCitationMergeMode should be called.
| // let main table know this is a citation merge | ||
| libraryTab.getMainTable().setCitationMerge(true); |
There was a problem hiding this comment.
Wrong position - because if I click "cancel" on the merge, the mode is not reset - I show you a better position in the code below.
- fixed wrong position codes: codes that updating citation relation item and setting state of citationMergeMode now be moved into CitationRelationsTab#openPossibleDuplicateEntriesWindow - modified some comments and Java doc
koppor
left a comment
There was a problem hiding this comment.
The column headings of the merge entries dialog are not self-explanatory
What is "left", what is "right"?`
Proposal:
- Swap left and right - because the left is the new thing flowing into the middle thing and then the output is the merged entry
- Set "Citation" and "Library" as titles for the columns
I hope this is possible with the current base offered by JabRef
I moved the statement libraryTab.getMainTable().setCitationMergeMode(true); close to insertEntry, because it is needed right before there. (fbbd5f0)
Other
… more self-explanatory.
|
Finally approved. Thank you for the fast follow-ups! I hope you will take another issue to improve JabRef even more! |
|
@koppor Thank you for the approval and your continuous support throughout the process! 🙌 It was a pleasure contributing to JabRef, and I appreciate your helpful guidance along the way. I look forward to tackling more issues and helping improve JabRef even further! 🚀 |








screenshot before:

screenshot after:

screen recording preview:
preview.mov
This PR fixes #11192
Mandatory checks
CHANGELOG.mddescribed in a way that is understandable for the average user (if applicable)