Skip to content
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

Fixes displaying of Mr DLib recommendations #2616

Merged
merged 1 commit into from
Mar 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. I really wonder why this previously didn't work. But well, if it works now, then it's fine...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EntryEditorTabRelatedArticles was AFAIK used as child. activeTab was a JPanel.

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