Skip to content

Commit

Permalink
Fixes displaying of Mr DLib recommendations (#2616)
Browse files Browse the repository at this point in the history
(and some other stylistic improvements)
  • Loading branch information
koppor authored and Siedlerchr committed Mar 6, 2017
1 parent ba24c12 commit f259b97
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public List<BibEntry> 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;
Expand All @@ -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<BibEntry> list) {
StringBuilder htmlContent = new StringBuilder();
Expand All @@ -71,13 +72,11 @@ public void setHtmlText(List<BibEntry> list) {
htmlContent.append("<ul style='list-style-image:(");
htmlContent.append(url);
htmlContent.append(")'>");
for (BibEntry bibEntry : list) {
if (bibEntry != null) {
htmlContent.append("<li style='margin: 5px'>");
bibEntry.getField("html_representation").ifPresent(htmlContent::append);
htmlContent.append("</li>");
}
}
list.stream()
.map(bibEntry -> bibEntry.getField("html_representation"))
.filter(Optional::isPresent)
.map(o -> "<li style='margin: 5px'>" + o.get() + "</li>")
.forEach(html -> htmlContent.append(html));
htmlContent.append("</ul>");
htmlContent.append("<br><div style='margin-left: 5px'>");
htmlContent.append(
Expand All @@ -100,12 +99,7 @@ private void setDefaultContent() {
htmlContent.append(Localization.lang("Loading_Recommendations_for"));
htmlContent.append(": ");
htmlContent.append("<b>");
Optional<String> title = selectedEntry.getLatexFreeField(FieldName.TITLE);
if(title.isPresent()) {
htmlContent.append(title.get());
} else {
htmlContent.append("");
}
htmlContent.append(selectedEntry.getLatexFreeField(FieldName.TITLE).orElseGet(() -> ""));
htmlContent.append("<div>");
htmlContent.append(
"<a href='http://mr-dlib.org/information-for-users/information-about-mr-dlib-for-jabref-users/#'>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<BibEntry> 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<BibEntry> bibEntrys = fetcher.performSearch(bibEntry);
assertFalse(bibEntrys.isEmpty());
}
Expand Down

0 comments on commit f259b97

Please sign in to comment.