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
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c0f54ec
- Added a "Compare" button for duplicate entries in the CitationRelat…
KumaLuo Oct 11, 2024
2edb8b6
- Implemented functionality to open a "Possible duplicate entries" fo…
KumaLuo Oct 12, 2024
e3c759c
Merge branch 'main' into fix-for-issue-11192
KumaLuo Oct 12, 2024
ea4bb0e
Updated changelog
KumaLuo Oct 12, 2024
a708875
Merge branch 'fix-for-issue-11192' of https://github.com/KumaLuo/jabr…
KumaLuo Oct 12, 2024
09a35b0
- Updated localization key for compare button tooltip.
KumaLuo Oct 13, 2024
95c1362
Merge branch 'main' into fix-for-issue-11192
KumaLuo Oct 13, 2024
8bec936
Modified CitationsRelationsTabViewModel and ImportHandler to pass Cit…
KumaLuo Oct 13, 2024
8fc4f91
Merge branch 'fix-for-issue-11192' of https://github.com/KumaLuo/jabr…
KumaLuo Oct 13, 2024
5eed679
- Deleted old code in CitationRelationTab.java which to implement tha…
KumaLuo Oct 13, 2024
99fa500
Merge branch 'main' into fix-for-issue-11192
KumaLuo Oct 13, 2024
4bd4872
Optimised citation relations item merge: Added a citation merge flag …
KumaLuo Oct 14, 2024
4bf1f44
Optimised MainTable#clearAndSelect: make the code look more concise.
KumaLuo Oct 14, 2024
0710c3d
Merge branch 'main' into fix-for-issue-11192
KumaLuo Oct 14, 2024
9566980
Fixed bug: As original local entry of citation relation item has been…
KumaLuo Oct 14, 2024
272e686
Merge branch 'main' into fix-for-issue-11192
KumaLuo Oct 14, 2024
f8736fc
Adapted tool tip of compare button.
KumaLuo Oct 15, 2024
6cfb3b9
Merge branch 'main' of https://github.com/JabRef/jabref into fix-for-…
KumaLuo Oct 15, 2024
447f220
Merge branch 'main' into fix-for-issue-11192
koppor Oct 15, 2024
080e80f
- renamed some variables to make them more understandable
KumaLuo Oct 15, 2024
5f4264c
Merge branch 'main' into fix-for-issue-11192
koppor Oct 16, 2024
fbbd5f0
Move statement closer to intended use
koppor Oct 16, 2024
2631280
Modified the column headings of the merge entries dialog to make them…
KumaLuo Oct 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- We 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)
- We added automatic browser extension install on Windows for Chrome and Edge. [#6076](https://github.com/JabRef/jabref/issues/6076)
- We added a search bar for filtering keyboard shortcuts. [#11686](https://github.com/JabRef/jabref/issues/11686)
- By double clicking on a local citation in the Citation Relations Tab you can now jump the the linked entry. [#11955](https://github.com/JabRef/jabref/pull/11955)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import javax.swing.undo.UndoManager;

Expand Down Expand Up @@ -39,7 +40,12 @@
import org.jabref.gui.entryeditor.citationrelationtab.semanticscholar.CitationFetcher;
import org.jabref.gui.entryeditor.citationrelationtab.semanticscholar.SemanticScholarFetcher;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.mergeentries.EntriesMergeResult;
import org.jabref.gui.mergeentries.MergeEntriesDialog;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.gui.undo.NamedCompound;
import org.jabref.gui.undo.UndoableInsertEntries;
import org.jabref.gui.undo.UndoableRemoveEntries;
import org.jabref.gui.util.NoSelectionModel;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.bibtex.BibEntryWriter;
Expand All @@ -51,6 +57,7 @@
import org.jabref.logic.os.OS;
import org.jabref.logic.util.BackgroundTask;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.database.BibDatabaseModeDetection;
Expand Down Expand Up @@ -89,6 +96,8 @@ public class CitationRelationsTab extends EntryEditorTab {
private final CitationsRelationsTabViewModel citationsRelationsTabViewModel;
private final DuplicateCheck duplicateCheck;
private final BibEntryTypesManager entryTypesManager;
private final StateManager stateManager;
private final UndoManager undoManager;

public CitationRelationsTab(DialogService dialogService,
BibDatabaseContext databaseContext,
Expand All @@ -104,6 +113,8 @@ public CitationRelationsTab(DialogService dialogService,
this.preferences = preferences;
this.libraryTab = libraryTab;
this.taskExecutor = taskExecutor;
this.undoManager = undoManager;
this.stateManager = stateManager;
setText(Localization.lang("Citation relations"));
setTooltip(new Tooltip(Localization.lang("Show articles related by citation")));

Expand Down Expand Up @@ -238,6 +249,13 @@ private void styleFetchedListView(CheckListView<CitationRelationItem> listView)
}
});
vContainer.getChildren().add(jumpTo);

Button compareButton = IconTheme.JabRefIcons.MERGE_ENTRIES.asButton();
compareButton.setTooltip(new Tooltip(Localization.lang("Compare with existing entry")));
compareButton.setOnMouseClicked(event -> {
openPossibleDuplicateEntriesWindow(entry, listView);
});
vContainer.getChildren().add(compareButton);
} else {
ToggleButton addToggle = IconTheme.JabRefIcons.ADD.asToggleButton();
addToggle.setTooltip(new Tooltip(Localization.lang("Select entry")));
Expand Down Expand Up @@ -511,4 +529,42 @@ private void importEntries(List<CitationRelationItem> entriesToImport, CitationF

dialogService.notify(Localization.lang("Number of entries successfully imported") + ": " + entriesToImport.size());
}

/**
* Function to open possible duplicate entries window to compare duplicate entries
*
* @param duplicateItem duplicate in the citation relations tab
* @param listView CheckListView to display citations
*/
private void openPossibleDuplicateEntriesWindow(CitationRelationItem duplicateItem, CheckListView<CitationRelationItem> listView) {
BibEntry localEntry = duplicateItem.localEntry();
BibEntry duplicateEntry = duplicateItem.entry();

MergeEntriesDialog dialog = new MergeEntriesDialog(localEntry, duplicateEntry, preferences);
dialog.setTitle(Localization.lang("Possible duplicate entries"));

Optional<EntriesMergeResult> entriesMergeResult = dialogService.showCustomDialogAndWait(dialog);
entriesMergeResult.ifPresentOrElse(mergeResult -> {

BibEntry mergedEntry = mergeResult.mergedEntry();
libraryTab.getMainTable().setCitationMergeMode(true);
// update local entry of selected citation relation item
listView.getItems().set(listView.getItems().indexOf(duplicateItem), new CitationRelationItem(duplicateItem.entry(), mergedEntry, true));

// Merge method is similar to MergeTwoEntriesAction#execute
BibDatabase database = stateManager.getActiveDatabase().get().getDatabase();

database.removeEntry(mergeResult.originalLeftEntry());
database.insertEntry(mergedEntry);

NamedCompound ce = new NamedCompound(Localization.lang("Merge entries"));
ce.addEdit(new UndoableRemoveEntries(database, mergeResult.originalLeftEntry()));
ce.addEdit(new UndoableInsertEntries(stateManager.getActiveDatabase().get().getDatabase(), mergedEntry));
ce.end();

undoManager.addEdit(ce);

dialogService.notify(Localization.lang("Merged entries"));
}, () -> dialogService.notify(Localization.lang("Canceled merging entries")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ private void importCites(List<BibEntry> entries, BibEntry existingEntry, ImportH

List<String> citeKeys = getExistingEntriesFromCiteField(existingEntry);
citeKeys.removeIf(String::isEmpty);

for (BibEntry entryToCite : entries) {
if (generateNewKeyOnImport || entryToCite.getCitationKey().isEmpty()) {
String key = generator.generateKey(entryToCite);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public void importEntries(List<BibEntry> entries) {
}

public void importCleanedEntries(List<BibEntry> entries) {
entries = entries.stream().map(entry -> (BibEntry) entry.clone()).toList();
bibDatabaseContext.getDatabase().insertEntries(entries);
generateKeys(entries);
setAutomaticFields(entries);
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public class MainTable extends TableView<BibEntryTableViewModel> {

private long lastKeyPressTime;
private String columnSearchTerm;
private boolean citationMergeMode = false;

public MainTable(MainTableDataModel model,
LibraryTab libraryTab,
Expand Down Expand Up @@ -249,11 +250,18 @@ public void listen(EntriesAddedEvent event) {
}

public void clearAndSelect(BibEntry bibEntry) {
getSelectionModel().clearSelection();
findEntry(bibEntry).ifPresent(entry -> {
getSelectionModel().select(entry);
scrollTo(entry);
});
// check if entries merged from citation relations tab
if (citationMergeMode) {
// keep original entry selected and reset citation merge mode
this.citationMergeMode = false;
} else {
// select new entry
getSelectionModel().clearSelection();
findEntry(bibEntry).ifPresent(entry -> {
getSelectionModel().select(entry);
scrollTo(entry);
});
}
}

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

public void setCitationMergeMode(boolean citationMerge) {
this.citationMergeMode = citationMerge;
}
}
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2797,3 +2797,5 @@ Warning\:\ The\ selected\ directory\ is\ not\ a\ valid\ directory.=Warning: The
Currently\ selected\ JStyle\:\ '%0' = Currently selected JStyle: '%0'
Currently\ selected\ CSL\ Style\:\ '%0' = Currently selected CSL Style: '%0'
Store\ url\ for\ downloaded\ file=Store url for downloaded file

Compare\ with\ existing\ entry=Compare with existing entry
Loading