-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable the exploration of bib entries' relations (cited by and citing) (
#10324) Co-authored-by: Tim Bachmann <58782027+timbachmann@users.noreply.github.com> Co-authored-by: Raphael Kreft <r.kreft@unibas.ch> Co-authored-by: Marcel Luethi <marcel.luethi@unibas.ch> Co-authored-by: olivierM <olivier.mattmann@stud.unibas.ch> Co-authored-by: matiascg <matiascargon@hotmail.com>
- Loading branch information
1 parent
8d7d772
commit 0c6c0a9
Showing
17 changed files
with
973 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/org/jabref/gui/entryeditor/citationrelationtab/BibEntryRelationsCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.jabref.gui.entryeditor.citationrelationtab; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.identifier.DOI; | ||
|
||
public class BibEntryRelationsCache { | ||
private static final Map<String, List<BibEntry>> CITATIONS_MAP = new HashMap<>(); | ||
private static final Map<String, List<BibEntry>> REFERENCES_MAP = new HashMap<>(); | ||
|
||
public List<BibEntry> getCitations(BibEntry entry) { | ||
return CITATIONS_MAP.getOrDefault(entry.getDOI().map(DOI::getDOI).orElse(""), Collections.emptyList()); | ||
} | ||
|
||
public List<BibEntry> getReferences(BibEntry entry) { | ||
return REFERENCES_MAP.getOrDefault(entry.getDOI().map(DOI::getDOI).orElse(""), Collections.emptyList()); | ||
} | ||
|
||
public void cacheOrMergeCitations(BibEntry entry, List<BibEntry> citations) { | ||
entry.getDOI().ifPresent(doi -> CITATIONS_MAP.put(doi.getDOI(), citations)); | ||
} | ||
|
||
public void cacheOrMergeReferences(BibEntry entry, List<BibEntry> references) { | ||
entry.getDOI().ifPresent(doi -> REFERENCES_MAP.putIfAbsent(doi.getDOI(), references)); | ||
} | ||
|
||
public boolean citationsCached(BibEntry entry) { | ||
return CITATIONS_MAP.containsKey(entry.getDOI().map(DOI::getDOI).orElse("")); | ||
} | ||
|
||
public boolean referencesCached(BibEntry entry) { | ||
return REFERENCES_MAP.containsKey(entry.getDOI().map(DOI::getDOI).orElse("")); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...main/java/org/jabref/gui/entryeditor/citationrelationtab/BibEntryRelationsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.jabref.gui.entryeditor.citationrelationtab; | ||
|
||
import java.util.List; | ||
|
||
import org.jabref.gui.entryeditor.citationrelationtab.semanticscholar.SemanticScholarFetcher; | ||
import org.jabref.logic.importer.FetcherException; | ||
import org.jabref.model.entry.BibEntry; | ||
|
||
public class BibEntryRelationsRepository { | ||
private final SemanticScholarFetcher fetcher; | ||
private final BibEntryRelationsCache cache; | ||
|
||
public BibEntryRelationsRepository(SemanticScholarFetcher fetcher, BibEntryRelationsCache cache) { | ||
this.fetcher = fetcher; | ||
this.cache = cache; | ||
} | ||
|
||
public List<BibEntry> getCitations(BibEntry entry) { | ||
if (needToRefreshCitations(entry)) { | ||
forceRefreshCitations(entry); | ||
} | ||
|
||
return cache.getCitations(entry); | ||
} | ||
|
||
public List<BibEntry> getReferences(BibEntry entry) { | ||
if (needToRefreshReferences(entry)) { | ||
List<BibEntry> references = fetcher.searchCiting(entry); | ||
cache.cacheOrMergeReferences(entry, references); | ||
} | ||
|
||
return cache.getReferences(entry); | ||
} | ||
|
||
public void forceRefreshCitations(BibEntry entry) { | ||
try { | ||
List<BibEntry> citations = fetcher.searchCitedBy(entry); | ||
cache.cacheOrMergeCitations(entry, citations); | ||
} catch (FetcherException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public boolean needToRefreshCitations(BibEntry entry) { | ||
return !cache.citationsCached(entry); | ||
} | ||
|
||
public boolean needToRefreshReferences(BibEntry entry) { | ||
return !cache.referencesCached(entry); | ||
} | ||
|
||
public void forceRefreshReferences(BibEntry entry) { | ||
List<BibEntry> references = fetcher.searchCiting(entry); | ||
cache.cacheOrMergeReferences(entry, references); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/org/jabref/gui/entryeditor/citationrelationtab/BibEntryView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.jabref.gui.entryeditor.citationrelationtab; | ||
|
||
import java.util.EnumSet; | ||
|
||
import javafx.scene.Node; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.layout.HBox; | ||
import javafx.scene.layout.VBox; | ||
import javafx.scene.text.Text; | ||
|
||
import org.jabref.gui.icon.IconTheme; | ||
import org.jabref.gui.util.TextFlowLimited; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.field.StandardField; | ||
import org.jabref.model.entry.types.EntryType; | ||
import org.jabref.model.entry.types.StandardEntryType; | ||
|
||
/** | ||
* Class to unify the display method of BibEntries in ListViews. | ||
*/ | ||
public class BibEntryView { | ||
|
||
/** | ||
* Creates a layout for a given {@link BibEntry} to be displayed in a List | ||
* | ||
* @param entry {@link BibEntry} to display | ||
* @return layout container displaying the entry | ||
*/ | ||
public static Node getEntryNode(BibEntry entry) { | ||
Node entryType = getIcon(entry.getType()).getGraphicNode(); | ||
entryType.getStyleClass().add("type"); | ||
Label authors = new Label(entry.getFieldOrAliasLatexFree(StandardField.AUTHOR).orElse("")); | ||
authors.getStyleClass().add("authors"); | ||
authors.setWrapText(true); | ||
Label title = new Label(entry.getFieldOrAliasLatexFree(StandardField.TITLE).orElse("")); | ||
title.getStyleClass().add("title"); | ||
title.setWrapText(true); | ||
Label year = new Label(entry.getFieldOrAliasLatexFree(StandardField.YEAR).orElse("")); | ||
year.getStyleClass().add("year"); | ||
Label journal = new Label(entry.getFieldOrAliasLatexFree(StandardField.JOURNAL).orElse("")); | ||
journal.getStyleClass().add("journal"); | ||
|
||
VBox entryContainer = new VBox( | ||
new HBox(10, entryType, title), | ||
new HBox(5, year, journal), | ||
authors | ||
); | ||
entry.getFieldOrAliasLatexFree(StandardField.ABSTRACT).ifPresent(summaryText -> { | ||
TextFlowLimited summary = new TextFlowLimited(new Text(summaryText)); | ||
summary.getStyleClass().add("summary"); | ||
entryContainer.getChildren().add(summary); | ||
}); | ||
|
||
entryContainer.getStyleClass().add("bibEntry"); | ||
return entryContainer; | ||
} | ||
|
||
/** | ||
* Gets the correct Icon for a given {@link EntryType} | ||
* | ||
* @param type {@link EntryType} to get Icon for | ||
* @return Icon corresponding to {@link EntryType} | ||
*/ | ||
private static IconTheme.JabRefIcons getIcon(EntryType type) { | ||
EnumSet<StandardEntryType> crossRefTypes = EnumSet.of(StandardEntryType.InBook, | ||
StandardEntryType.InProceedings, StandardEntryType.InCollection); | ||
if (type == StandardEntryType.Book) { | ||
return IconTheme.JabRefIcons.BOOK; | ||
} else if (crossRefTypes.contains(type)) { | ||
return IconTheme.JabRefIcons.OPEN_LINK; | ||
} | ||
return IconTheme.JabRefIcons.ARTICLE; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.jabref.gui.entryeditor.citationrelationtab; | ||
|
||
import org.jabref.model.entry.BibEntry; | ||
|
||
/** | ||
* Class to hold a BibEntry and a boolean value whether it is already in the current database or not. | ||
*/ | ||
public class CitationRelationItem { | ||
private final BibEntry entry; | ||
private final boolean isLocal; | ||
|
||
public CitationRelationItem(BibEntry entry, boolean isLocal) { | ||
this.entry = entry; | ||
this.isLocal = isLocal; | ||
} | ||
|
||
public BibEntry getEntry() { | ||
return entry; | ||
} | ||
|
||
public boolean isLocal() { | ||
return isLocal; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.addEntryButton { | ||
-fx-font-size: 2em; | ||
} | ||
|
||
.addEntryButton:selected { | ||
-fx-background-color: transparent; | ||
-fx-fill: -jr-selected; | ||
} | ||
|
||
.entry-container { | ||
-fx-padding: 0.5em 0em 0.5em 0em; | ||
} | ||
|
||
.list-cell:default { | ||
-fx-padding: 0.5em 0.1em 0.5em 0em; | ||
} | ||
|
||
.list-cell:selected { | ||
-fx-background-color: derive(-jr-selected, 60%); | ||
} |
Oops, something went wrong.