From b14337ab1d26b5379b14d1a47f91f3762aa478d1 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 5 Mar 2017 22:30:12 +0100 Subject: [PATCH] Fixes displaying of Mr DLib recommendations (and some other stylistic improvements) --- .../jabref/gui/entryeditor/EntryEditor.java | 2 +- .../EntryEditorTabRelatedArticles.java | 26 +++++++------------ .../importer/fetcher/MrDLibFetcherTest.java | 23 +++++++++++++++- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index a6fc2a3b5d9..65fb10fda4f 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -1148,7 +1148,7 @@ public void stateChanged(ChangeEvent event) { } // When the tab "Related articles" gets selected, the request to get the recommendations is started. - if (activeTab instanceof EntryEditorTabRelatedArticles) { + if (activeTab == relatedArticlePanel) { relatedArticlesTab.focus(); } }); diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditorTabRelatedArticles.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditorTabRelatedArticles.java index 3999ce89033..a29173b0adb 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditorTabRelatedArticles.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditorTabRelatedArticles.java @@ -48,7 +48,7 @@ public List getRelatedArticles() { /** * Takes the selected entry, runs a request to Mr. DLib and returns the recommendations as a JEditorPane - * @param The entry selected by the user + * @param selectedEntry The entry selected by the user */ public EntryEditorTabRelatedArticles(BibEntry selectedEntry) { this.selectedEntry = selectedEntry; @@ -60,8 +60,9 @@ public EntryEditorTabRelatedArticles(BibEntry selectedEntry) { /** - * Takes a List of HTML snippets and sets it in the JEditorPane - * @param list of HTML Strings + * Takes a List of HTML snippets stored in the field "html_representation" of a list of bibentries and sets it in the JEditorPane + * + * @param list of bib entries having a field html_representation */ public void setHtmlText(List list) { StringBuilder htmlContent = new StringBuilder(); @@ -71,13 +72,11 @@ public void setHtmlText(List list) { htmlContent.append("
    "); - for (BibEntry bibEntry : list) { - if (bibEntry != null) { - htmlContent.append("
  • "); - bibEntry.getField("html_representation").ifPresent(htmlContent::append); - htmlContent.append("
  • "); - } - } + list.stream() + .map(bibEntry -> bibEntry.getField("html_representation")) + .filter(Optional::isPresent) + .map(o -> "
  • " + o.get() + "
  • ") + .forEach(html -> htmlContent.append(html)); htmlContent.append("
"); htmlContent.append("
"); htmlContent.append( @@ -100,12 +99,7 @@ private void setDefaultContent() { htmlContent.append(Localization.lang("Loading_Recommendations_for")); htmlContent.append(": "); htmlContent.append(""); - Optional title = selectedEntry.getLatexFreeField(FieldName.TITLE); - if(title.isPresent()) { - htmlContent.append(title.get()); - } else { - htmlContent.append(""); - } + htmlContent.append(selectedEntry.getLatexFreeField(FieldName.TITLE).orElseGet(() -> "")); htmlContent.append("
"); htmlContent.append( ""); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/MrDLibFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/MrDLibFetcherTest.java index 97bf1716907..2a21728b905 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/MrDLibFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/MrDLibFetcherTest.java @@ -23,12 +23,33 @@ public class MrDLibFetcherTest { @Before public void setUp() { fetcher = new MrDLibFetcher("", ""); + } + + @Test + public void testPerformSearch() throws FetcherException { bibEntry = new BibEntry(); bibEntry.setField(FieldName.TITLE, "lernen"); + List bibEntrys = fetcher.performSearch(bibEntry); + assertFalse(bibEntrys.isEmpty()); } @Test - public void testPerformSearch() throws FetcherException { + public void testPerformSearchForHornecker2006() throws FetcherException { + BibEntry bibEntry = new BibEntry(); + bibEntry.setCiteKey("Hornecker:2006:GGT:1124772.1124838"); + bibEntry.setField(FieldName.ADDRESS, "New York, NY, USA"); + bibEntry.setField(FieldName.AUTHOR, "Hornecker, Eva and Buur, Jacob"); + bibEntry.setField(FieldName.BOOKTITLE, "Proceedings of the SIGCHI Conference on Human Factors in Computing Systems"); + bibEntry.setField(FieldName.DOI, "10.1145/1124772.1124838"); + bibEntry.setField(FieldName.ISBN, "1-59593-372-7"); + bibEntry.setField(FieldName.KEYWORDS, "CSCW,analysis,collaboration,design,framework,social interaction,tangible interaction,tangible interface"); + bibEntry.setField(FieldName.PAGES, "437--446"); + bibEntry.setField(FieldName.PUBLISHER, "ACM"); + bibEntry.setField(FieldName.SERIES, "CHI '06"); + bibEntry.setField(FieldName.TITLE, "{Getting a Grip on Tangible Interaction: A Framework on Physical Space and Social Interaction}"); + bibEntry.setField(FieldName.URL, "http://doi.acm.org/10.1145/1124772.1124838"); + bibEntry.setField(FieldName.YEAR, "2006"); + List bibEntrys = fetcher.performSearch(bibEntry); assertFalse(bibEntrys.isEmpty()); }