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

Add compare button to duplicates in Citation relations tab #11915

Merged
merged 23 commits into from
Oct 16, 2024

Conversation

KumaLuo
Copy link
Contributor

@KumaLuo KumaLuo commented Oct 11, 2024

  • Added a "Compare" button for duplicate entries in the CitationRelationsTab.

screenshot before:
previous

screenshot after:
after

  • Implemented functionality that the compare button will open the "Possible duplicate entries" window

screen recording preview:

preview.mov

This PR fixes #11192

Mandatory checks

  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • 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.

…ionsTab.

- Added localization key for 'Compare with duplicate entries'.
@KumaLuo KumaLuo changed the title Add compare button to duplicates in Citation relations tab [WIP]Add compare button to duplicates in Citation relations tab Oct 11, 2024
@KumaLuo KumaLuo changed the title [WIP]Add compare button to duplicates in Citation relations tab [WIP] Add compare button to duplicates in Citation relations tab Oct 11, 2024
@Siedlerchr
Copy link
Member

For opening the compare window check out the MergeDialogEntriesDialog

…r comparing and merging duplicate entries.

- Updated changelog for compare button feature.
@KumaLuo KumaLuo changed the title [WIP] Add compare button to duplicates in Citation relations tab Add compare button to duplicates in Citation relations tab Oct 12, 2024
@KumaLuo KumaLuo marked this pull request as ready for review October 12, 2024 02:50
CHANGELOG.md Outdated
@@ -34,6 +34,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- 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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

"We added" 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😂 I will fix that

Button compareButton = IconTheme.JabRefIcons.MERGE_ENTRIES.asButton();
compareButton.setTooltip(new Tooltip(Localization.lang("Compare with duplicate entries")));
compareButton.setOnMouseClicked(event -> {
openPossibleDuplicateEntriesWindow(entry);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this mean that every entry is potentially a duplicate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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?😅

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, CitationRelationItem.isLocal() returns whether it's a duplicate or not?

Copy link
Contributor Author

@KumaLuo KumaLuo Oct 12, 2024

Choose a reason for hiding this comment

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

I think CitationRelationItem.isLocal() returns true if entries in citation relations tab have been detected there is a possible duplicate entry in local current database.
image

Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

Good first step.

After clicking "merge", the current entry should be kept selected - and not the merged entry be selected.

image

image


However, does not always work. It uses the entry of the citation relation if the entry was added to the library before

image

  1. Open citationr relations for paper P1
  2. Add citing paper P2 to library
  3. Edit P2 using JabRef
  4. Go back toi P1: Citatoin relations
  5. 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.

@@ -238,6 +246,13 @@ private void styleFetchedListView(CheckListView<CitationRelationItem> listView)
libraryTab.clearAndSelect(entry.localEntry());
});
vContainer.getChildren().add(jumpTo);

Button compareButton = IconTheme.JabRefIcons.MERGE_ENTRIES.asButton();
compareButton.setTooltip(new Tooltip(Localization.lang("Compare with duplicate entries")));
Copy link
Member

Choose a reason for hiding this comment

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

I think "duplicate" is not a good term. It is about an existing entry in the library

Suggested change
compareButton.setTooltip(new Tooltip(Localization.lang("Compare with duplicate entries")));
compareButton.setTooltip(new Tooltip(Localization.lang("Compare with existing entries")));

KumaLuo and others added 2 commits October 13, 2024 16:37
- 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.
@KumaLuo
Copy link
Contributor Author

KumaLuo commented Oct 13, 2024

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!

@KumaLuo
Copy link
Contributor Author

KumaLuo commented Oct 13, 2024

test failed, I will try to fix🥲

@KumaLuo KumaLuo requested a review from koppor October 13, 2024 07:28
Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines 555 to 557
BibEntry current = libraryTab.getEntryEditor().getCurrentlyEditedEntry();
stateManager.getActiveDatabase().get().getDatabase().removeEntry(current);
stateManager.getActiveDatabase().get().getDatabase().insertEntry(current);
Copy link
Member

Choose a reason for hiding this comment

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

Why this? These three lines remove and add the same entry? Can these lines just be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😅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!🥰

@@ -194,6 +195,7 @@ public void importEntries(List<BibEntry> entries) {
}

public void importCleanedEntries(List<BibEntry> entries) {
entries = entries.stream().map(entry -> (BibEntry) entry.clone()).filter(Objects::nonNull).toList();
Copy link
Member

Choose a reason for hiding this comment

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

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)

Comment on lines 558 to 559
libraryTab.showAndEdit(current);
libraryTab.clearAndSelect(current);
Copy link
Member

Choose a reason for hiding this comment

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

Here you change to the new entry. What happens if you remove these two lines?

@koppor
Copy link
Member

koppor commented Oct 13, 2024

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!

This is part of the journey!

Suggestion add a breakpoint at org.jabref.gui.LibraryTab#clearAndSelect and inspect the call hiearchy to see why the entry is selected.

KumaLuo and others added 2 commits October 14, 2024 03:02
…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.
@KumaLuo KumaLuo requested a review from koppor October 13, 2024 16:16
Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

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

image

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:

image

After:

image


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},
}

… 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.
@KumaLuo KumaLuo requested a review from koppor October 14, 2024 16:16
@@ -238,6 +250,18 @@ private void styleFetchedListView(CheckListView<CitationRelationItem> listView)
libraryTab.clearAndSelect(entry.localEntry());
});
vContainer.getChildren().add(jumpTo);

Button compareButton = IconTheme.JabRefIcons.MERGE_ENTRIES.asButton();
compareButton.setTooltip(new Tooltip(Localization.lang("Compare with existing entries")));
Copy link
Member

Choose a reason for hiding this comment

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

I think, it compares with a single entry – string should be adapted!

@KumaLuo KumaLuo requested a review from koppor October 15, 2024 01:56
MergeEntriesDialog dialog = new MergeEntriesDialog(localEntry, duplicateEntry, preferences);
dialog.setTitle(Localization.lang("Possible duplicate entries"));

Optional<EntriesMergeResult> mergeResultOpt = dialogService.showCustomDialogAndWait(dialog);
Copy link
Member

Choose a reason for hiding this comment

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

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();
Copy link
Member

Choose a reason for hiding this comment

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

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.

@@ -82,6 +82,7 @@ public class MainTable extends TableView<BibEntryTableViewModel> {

private long lastKeyPressTime;
private String columnSearchTerm;
private boolean citationMerge = false; // citation merge flag
Copy link
Member

Choose a reason for hiding this comment

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

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.

@@ -492,4 +500,8 @@ private Optional<BibEntryTableViewModel> findEntry(BibEntry entry) {
.filter(viewModel -> viewModel.getEntry().equals(entry))
.findFirst();
}

public void setCitationMerge(boolean merge) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe name it setCitationMergeMode

BibDatabase database = stateManager.getActiveDatabase().get().getDatabase();

database.removeEntry(entriesMergeResult.originalLeftEntry());
database.insertEntry(entriesMergeResult.mergedEntry());
Copy link
Member

Choose a reason for hiding this comment

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

Right before this line, the setCitationMergeMode should be called.

Comment on lines 261 to 262
// let main table know this is a citation merge
libraryTab.getMainTable().setCitationMerge(true);
Copy link
Member

Choose a reason for hiding this comment

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

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
@KumaLuo KumaLuo requested a review from koppor October 15, 2024 10:49
Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

The column headings of the merge entries dialog are not self-explanatory

image

What is "left", what is "right"?`

Proposal:

  1. Swap left and right - because the left is the new thing flowing into the middle thing and then the output is the merged entry
  2. 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

@KumaLuo KumaLuo requested a review from koppor October 16, 2024 05:52
@koppor koppor enabled auto-merge October 16, 2024 08:00
@koppor
Copy link
Member

koppor commented Oct 16, 2024

Finally approved. Thank you for the fast follow-ups! I hope you will take another issue to improve JabRef even more!

@KumaLuo
Copy link
Contributor Author

KumaLuo commented Oct 16, 2024

@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! 🚀

@KumaLuo KumaLuo requested a review from InAnYan October 16, 2024 08:09
@koppor koppor added this pull request to the merge queue Oct 16, 2024
Merged via the queue into JabRef:main with commit ec2059a Oct 16, 2024
23 checks passed
ExrosZ pushed a commit to ExrosZ/jabref that referenced this pull request Oct 17, 2024
)

* - Added a "Compare" button for duplicate entries in the CitationRelationsTab.
- Added localization key for 'Compare with duplicate entries'.

* - Implemented functionality to open a "Possible duplicate entries" for comparing and merging duplicate entries.
- Updated changelog for compare button feature.

* Updated changelog

* - Updated localization key for compare button tooltip.
- 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.

* Modified CitationsRelationsTabViewModel and ImportHandler to pass CitationsRelationsTabViewModelTest with clone entries.

* - Deleted old code in CitationRelationTab.java which to implement that original entry be selected after citation item merge.
- Modified MainTable#clearAndSelect to ensure original entry be selected after citation item merge.
- Added some comments.

* Optimised citation relations item merge: Added a citation merge flag in MainTable.java to let original entry get selected after merge instead of selecting new merged entry.

* Optimised MainTable#clearAndSelect: make the code look more concise.

* Fixed bug: As original local entry of citation relation item has been 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.

* Adapted tool tip of compare button.

* - renamed some variables to make them more understandable
- 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

* Move statement closer to intended use

* Modified the column headings of the merge entries dialog to make them more self-explanatory.

---------

Co-authored-by: Oliver Kopp <[email protected]>
ExrosZ pushed a commit to ExrosZ/jabref that referenced this pull request Oct 17, 2024
)

* - Added a "Compare" button for duplicate entries in the CitationRelationsTab.
- Added localization key for 'Compare with duplicate entries'.

* - Implemented functionality to open a "Possible duplicate entries" for comparing and merging duplicate entries.
- Updated changelog for compare button feature.

* Updated changelog

* - Updated localization key for compare button tooltip.
- 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.

* Modified CitationsRelationsTabViewModel and ImportHandler to pass CitationsRelationsTabViewModelTest with clone entries.

* - Deleted old code in CitationRelationTab.java which to implement that original entry be selected after citation item merge.
- Modified MainTable#clearAndSelect to ensure original entry be selected after citation item merge.
- Added some comments.

* Optimised citation relations item merge: Added a citation merge flag in MainTable.java to let original entry get selected after merge instead of selecting new merged entry.

* Optimised MainTable#clearAndSelect: make the code look more concise.

* Fixed bug: As original local entry of citation relation item has been 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.

* Adapted tool tip of compare button.

* - renamed some variables to make them more understandable
- 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

* Move statement closer to intended use

* Modified the column headings of the merge entries dialog to make them more self-explanatory.

---------

Co-authored-by: Oliver Kopp <[email protected]>
ExrosZ pushed a commit to ExrosZ/jabref that referenced this pull request Oct 21, 2024
)

* - Added a "Compare" button for duplicate entries in the CitationRelationsTab.
- Added localization key for 'Compare with duplicate entries'.

* - Implemented functionality to open a "Possible duplicate entries" for comparing and merging duplicate entries.
- Updated changelog for compare button feature.

* Updated changelog

* - Updated localization key for compare button tooltip.
- 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.

* Modified CitationsRelationsTabViewModel and ImportHandler to pass CitationsRelationsTabViewModelTest with clone entries.

* - Deleted old code in CitationRelationTab.java which to implement that original entry be selected after citation item merge.
- Modified MainTable#clearAndSelect to ensure original entry be selected after citation item merge.
- Added some comments.

* Optimised citation relations item merge: Added a citation merge flag in MainTable.java to let original entry get selected after merge instead of selecting new merged entry.

* Optimised MainTable#clearAndSelect: make the code look more concise.

* Fixed bug: As original local entry of citation relation item has been 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.

* Adapted tool tip of compare button.

* - renamed some variables to make them more understandable
- 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

* Move statement closer to intended use

* Modified the column headings of the merge entries dialog to make them more self-explanatory.

---------

Co-authored-by: Oliver Kopp <[email protected]>
@LoayGhreeb LoayGhreeb mentioned this pull request Oct 29, 2024
7 tasks
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.

Add compare button to duplicates in Citation relations tab
4 participants