Skip to content

Commit 51236a3

Browse files
authored
Merge pull request JabRef#10416 from JabRef/fixFXThread
Fix fetcher worker execution on background thread
2 parents bc8fb3f + 51655ef commit 51236a3

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/main/java/org/jabref/gui/EntryTypeView.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ public EntryTypeView(LibraryTab libraryTab, DialogService dialogService, Prefere
9292
btnGenerate.textProperty().bind(EasyBind.map(viewModel.searchingProperty(), searching -> searching ? Localization.lang("Searching...") : Localization.lang("Generate")));
9393
btnGenerate.disableProperty().bind(viewModel.idFieldValidationStatus().validProperty().not().or(viewModel.searchingProperty()));
9494

95-
EasyBind.subscribe(viewModel.searchSuccesfulProperty(), value -> {
96-
if (value) {
95+
EasyBind.subscribe(viewModel.searchSuccesfulProperty(), isSuccessful -> {
96+
if (isSuccessful) {
9797
setEntryTypeForReturnAndClose(Optional.empty());
9898
}
9999
});
100100
}
101101

102-
private void addEntriesToPane(FlowPane pane, Collection<? extends BibEntryType> entries) {
103-
for (BibEntryType entryType : entries) {
102+
private void addEntriesToPane(FlowPane pane, Collection<? extends BibEntryType> entryTypes) {
103+
for (BibEntryType entryType : entryTypes) {
104104
Button entryButton = new Button(entryType.getType().getDisplayName());
105105
entryButton.setUserData(entryType);
106106
entryButton.setOnAction(event -> setEntryTypeForReturnAndClose(Optional.of(entryType)));

src/main/java/org/jabref/gui/EntryTypeViewModel.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ private class FetcherWorker extends Task<Optional<BibEntry>> {
131131

132132
@Override
133133
protected Optional<BibEntry> call() throws FetcherException {
134-
searchingProperty().setValue(true);
135134
storeSelectedFetcher();
136135
fetcher = selectedItemProperty().getValue();
137136
searchID = idText.getValue();
@@ -143,9 +142,10 @@ protected Optional<BibEntry> call() throws FetcherException {
143142
}
144143

145144
public void runFetcherWorker() {
146-
searchSuccesfulProperty.set(false);
147-
fetcherWorker.run();
145+
fetcherWorker.setOnRunning(event -> searchingProperty().setValue(true));
146+
148147
fetcherWorker.setOnFailed(event -> {
148+
searchSuccesfulProperty.set(false);
149149
Throwable exception = fetcherWorker.getException();
150150
String fetcherExceptionMessage = exception.getMessage();
151151
String fetcher = selectedItemProperty().getValue().getName();
@@ -159,7 +159,7 @@ public void runFetcherWorker() {
159159
dialogService.showInformationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Error message %0", fetcherExceptionMessage));
160160
}
161161

162-
LOGGER.error(String.format("Exception during fetching when using fetcher '%s' with entry id '%s'.", fetcher, searchId), exception);
162+
LOGGER.error("Exception during fetching when using fetcher '{}' with entry id '{}'.", fetcher, searchId, exception);
163163

164164
searchingProperty.set(false);
165165
fetcherWorker = new FetcherWorker();
@@ -204,10 +204,11 @@ public void runFetcherWorker() {
204204
searchSuccesfulProperty.set(true);
205205
}
206206
}
207-
fetcherWorker = new FetcherWorker();
208207

209208
focusAndSelectAllProperty.set(true);
210-
searchingProperty().setValue(false);
209+
searchingProperty().set(false);
210+
fetcherWorker = new FetcherWorker();
211211
});
212+
taskExecutor.execute(fetcherWorker);
212213
}
213214
}

0 commit comments

Comments
 (0)