-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Changes from 9 commits
c0f54ec
2edb8b6
e3c759c
ea4bb0e
a708875
09a35b0
95c1362
8bec936
8fc4f91
5eed679
99fa500
4bd4872
4bf1f44
0710c3d
9566980
272e686
f8736fc
6cfb3b9
447f220
080e80f
5f4264c
fbbd5f0
2631280
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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, | ||
|
@@ -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"))); | ||
|
||
|
@@ -238,6 +249,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 existing entries"))); | ||
compareButton.setOnMouseClicked(event -> { | ||
openPossibleDuplicateEntriesWindow(entry); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this mean that every entry is potentially a duplicate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the broader context of the code, there’s a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}); | ||
vContainer.getChildren().add(compareButton); | ||
} else { | ||
ToggleButton addToggle = IconTheme.JabRefIcons.ADD.asToggleButton(); | ||
addToggle.setTooltip(new Tooltip(Localization.lang("Select entry"))); | ||
|
@@ -504,4 +522,40 @@ 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 | ||
*/ | ||
private void openPossibleDuplicateEntriesWindow(CitationRelationItem duplicateItem) { | ||
BibEntry localEntry = duplicateItem.localEntry(); | ||
BibEntry duplicateEntry = duplicateItem.entry(); | ||
|
||
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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you really need the |
||
mergeResultOpt.ifPresentOrElse(entriesMergeResult -> { | ||
BibDatabase database = stateManager.getActiveDatabase().get().getDatabase(); | ||
|
||
database.removeEntry(entriesMergeResult.originalLeftEntry()); | ||
database.insertEntry(entriesMergeResult.mergedEntry()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right before this line, the |
||
|
||
NamedCompound ce = new NamedCompound(Localization.lang("Merge entries")); | ||
ce.addEdit(new UndoableRemoveEntries(database, entriesMergeResult.originalLeftEntry())); | ||
ce.addEdit(new UndoableInsertEntries(stateManager.getActiveDatabase().get().getDatabase(), entriesMergeResult.mergedEntry())); | ||
ce.end(); | ||
|
||
undoManager.addEdit(ce); | ||
|
||
dialogService.notify(Localization.lang("Merged entries")); | ||
}, () -> dialogService.notify(Localization.lang("Canceled merging entries"))); | ||
|
||
BibEntry current = libraryTab.getEntryEditor().getCurrentlyEditedEntry(); | ||
stateManager.getActiveDatabase().get().getDatabase().removeEntry(current); | ||
stateManager.getActiveDatabase().get().getDatabase().insertEntry(current); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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!🥰 |
||
libraryTab.showAndEdit(current); | ||
libraryTab.clearAndSelect(current); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import javax.swing.undo.CompoundEdit; | ||
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this (This code fragment seems to be AI generated - otherwise, it is OK) |
||
bibDatabaseContext.getDatabase().insertEntries(entries); | ||
generateKeys(entries); | ||
setAutomaticFields(entries); | ||
|
There was a problem hiding this comment.
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!