-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Fix JavaFX thread exception when fetching new infos #4354
Changes from 2 commits
c735987
62b9984
75b6b7d
b15bfbc
937623e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,22 @@ | |
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.jabref.Globals; | ||
import org.jabref.JabRefGUI; | ||
import org.jabref.gui.BasePanel; | ||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.util.BackgroundTask; | ||
import org.jabref.logic.importer.IdBasedFetcher; | ||
import org.jabref.logic.importer.WebFetchers; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.FieldName; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Class for fetching and merging information based on a specific field | ||
* | ||
|
@@ -17,7 +26,12 @@ public class FetchAndMergeEntry { | |
|
||
// A list of all field which are supported | ||
public static List<String> SUPPORTED_FIELDS = Arrays.asList(FieldName.DOI, FieldName.EPRINT, FieldName.ISBN); | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(FetchAndMergeEntry.class); | ||
|
||
private final BasePanel panel; | ||
private DialogService dialogService; | ||
|
||
/** | ||
* Convenience constructor for a single field | ||
* | ||
|
@@ -41,11 +55,41 @@ public FetchAndMergeEntry(BibEntry entry, String field) { | |
* @param fields - List of fields to get information from, one at a time in given order | ||
*/ | ||
public FetchAndMergeEntry(BibEntry entry, BasePanel panel, List<String> fields) { | ||
this.dialogService = panel.frame().getDialogService(); | ||
this.panel = panel; | ||
|
||
// TODO: Don't run this method as part of the constructor | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you resolve this TODO? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I was just too lazy to do it ;-). Fixed now. |
||
fetchAndMerge(entry, fields); | ||
} | ||
|
||
public void fetchAndMerge(BibEntry entry, List<String> fields) { | ||
for (String field : fields) { | ||
if (entry.hasField(field)) { | ||
new FetchAndMergeWorker(panel, entry, field).execute(); | ||
Optional<String> fieldContent = entry.getField(field); | ||
if (fieldContent.isPresent()) { | ||
BackgroundTask.wrap(() -> { | ||
Optional<IdBasedFetcher> fetcher = WebFetchers.getIdBasedFetcherForField(field, Globals.prefs.getImportFormatPreferences()); | ||
if (fetcher.isPresent()) { | ||
return fetcher.get().performSearchById(fieldContent.get()); | ||
} else { | ||
return Optional.<BibEntry>empty(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normally you don't need the genericc type in return Optional.empty There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was also surprised but it leads to compiler errors without it. |
||
} | ||
}) | ||
.onSuccess(fetchedEntry -> { | ||
String type = FieldName.getDisplayName(field); | ||
if (fetchedEntry.isPresent()) { | ||
MergeFetchedEntryDialog dialog = new MergeFetchedEntryDialog(panel, entry, fetchedEntry.get(), type); | ||
dialog.setVisible(true); | ||
} else { | ||
panel.frame().setStatus(Localization.lang("Cannot get info based on given %0: %1", type, fieldContent.get())); | ||
} | ||
}) | ||
.onFailure(exception -> { | ||
LOGGER.error("Error while fetching bibliographic information", exception); | ||
dialogService.showErrorDialogAndWait(exception); | ||
}) | ||
.executeWith(Globals.TASK_EXECUTOR); | ||
} else { | ||
panel.frame().setStatus(Localization.lang("No %0 found", FieldName.getDisplayName(field))); | ||
dialogService.notify(Localization.lang("No %0 found", FieldName.getDisplayName(field))); | ||
} | ||
} | ||
} | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use {} for parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not possible if the last argument should be treated as an exception.