Skip to content

Commit

Permalink
Implement a duplicate checker for Citation Relations entities (JabRef…
Browse files Browse the repository at this point in the history
…#11186)

* Implement a duplicate checker for Citation Relations entities

- implemented a duplicate checker by comparing entries names
- Marked existing entries "Light Green"
- Added a "localEntry" in the  "CitationRelationItem"

* Use the existing duplicate checker

* Fix the "CitationRelationItem" initializer in the "CitationsRelationsTabViewModelTest" to match the new constructor

* add "duplicate-entry" class to 'Base.css' and simplify the "duplicate check"

Signed-off-by: AbdAlRahmanGad <[email protected]>

* Create another Constructor for "CitationRelationItem" for non-duplicate entries

Signed-off-by: AbdAlRahmanGad <[email protected]>

---------

Signed-off-by: AbdAlRahmanGad <[email protected]>
  • Loading branch information
AbdAlRahmanGad authored Apr 12, 2024
1 parent 3ddb9e0 commit 580fe7f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We added support for offline extracting refereferences from PDFs following the IEEE format. [#11156](https://github.com/JabRef/jabref/pull/11156)
- We added a new keyboard shortcut <kbd>ctrl</kbd> + <kbd>,</kbd> to open the preferences. [#11154](https://github.com/JabRef/jabref/pull/11154)
- We added value selection (such as for month) for content selectors in custom entry types. [#11109](https://github.com/JabRef/jabref/issues/11109)
- We added a duplicate checker for the Citation Relations tab. [#10414](https://github.com/JabRef/jabref/issues/10414)
- We added tooltip on main table cells that shows cell content or cell content and entry preview if set in preferences. [10925](https://github.com/JabRef/jabref/issues/10925)
- We added the ability to add a keyword/crossref when typing the separator character (e.g., comma) in the keywords/crossref fields. [#11178](https://github.com/JabRef/jabref/issues/11178)

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/gui/Base.css
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,10 @@ TextFlow > .tooltip-text-monospaced {
-fx-background-color: -jr-warn;
}

.duplicate-entry {
-fx-background-color: -jr-light-green;
}

.file-row-text {
-fx-fill: -jr-search-text;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@
*/
public record CitationRelationItem(
BibEntry entry,
BibEntry localEntry,
boolean isLocal) {
public CitationRelationItem(BibEntry entry, boolean isLocal) {
this(entry, null, isLocal);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import javax.swing.undo.UndoManager;

Expand Down Expand Up @@ -40,9 +39,12 @@
import org.jabref.gui.util.NoSelectionModel;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.database.DuplicateCheck;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseModeDetection;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.identifier.DOI;
import org.jabref.model.strings.StringUtil;
Expand Down Expand Up @@ -75,6 +77,7 @@ public class CitationRelationsTab extends EntryEditorTab {
private final TaskExecutor taskExecutor;
private final BibEntryRelationsRepository bibEntryRelationsRepository;
private final CitationsRelationsTabViewModel citationsRelationsTabViewModel;
private final DuplicateCheck duplicateCheck;

public CitationRelationsTab(EntryEditorPreferences preferences, DialogService dialogService,
BibDatabaseContext databaseContext, UndoManager undoManager,
Expand All @@ -92,6 +95,7 @@ public CitationRelationsTab(EntryEditorPreferences preferences, DialogService di
setText(Localization.lang("Citation relations"));
setTooltip(new Tooltip(Localization.lang("Show articles related by citation")));

this.duplicateCheck = new DuplicateCheck(new BibEntryTypesManager());
this.bibEntryRelationsRepository = new BibEntryRelationsRepository(new SemanticScholarFetcher(preferencesService.getImporterPreferences()),
new BibEntryRelationsCache());
citationsRelationsTabViewModel = new CitationsRelationsTabViewModel(databaseContext, preferencesService, undoManager, stateManager, dialogService, fileUpdateMonitor, Globals.TASK_EXECUTOR);
Expand Down Expand Up @@ -210,14 +214,15 @@ private void styleFetchedListView(CheckListView<CitationRelationItem> listView)
VBox vContainer = new VBox();

if (entry.isLocal()) {
hContainer.getStyleClass().add("duplicate-entry");
Button jumpTo = IconTheme.JabRefIcons.LINK.asButton();
jumpTo.setTooltip(new Tooltip(Localization.lang("Jump to entry in library")));
jumpTo.getStyleClass().add("addEntryButton");
jumpTo.setOnMouseClicked(event -> {
libraryTab.showAndEdit(entry.entry());
libraryTab.clearAndSelect(entry.entry());
citingTask.cancel();
citedByTask.cancel();
libraryTab.showAndEdit(entry.localEntry());
libraryTab.clearAndSelect(entry.localEntry());
});
vContainer.getChildren().add(jumpTo);
} else {
Expand Down Expand Up @@ -384,8 +389,16 @@ private void onSearchForRelationsSucceed(BibEntry entry, CheckListView<CitationR
ObservableList<CitationRelationItem> observableList) {
hideNodes(abortButton, progress);

observableList.setAll(fetchedList.stream().map(entr -> new CitationRelationItem(entr, false))
.collect(Collectors.toList()));
observableList.setAll(
fetchedList.stream()
.map(entr -> duplicateCheck.containsDuplicate(
databaseContext.getDatabase(),
entr,
BibDatabaseModeDetection.inferMode(databaseContext.getDatabase()))
.map(localEntry -> new CitationRelationItem(entr, localEntry, true))
.orElseGet(() -> new CitationRelationItem(entr, false)))
.toList()
);

if (!observableList.isEmpty()) {
listView.refresh();
Expand Down

0 comments on commit 580fe7f

Please sign in to comment.