diff --git a/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java b/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java index ae5352deade..40ad459433b 100644 --- a/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java @@ -20,6 +20,7 @@ import javafx.scene.layout.VBox; import javafx.scene.text.Text; +import org.jabref.Globals; import org.jabref.gui.DialogService; import org.jabref.gui.StateManager; import org.jabref.gui.icon.IconTheme; @@ -108,12 +109,14 @@ private void initialize() { container.getStyleClass().add("entry-container"); BindingsHelper.includePseudoClassWhen(container, entrySelected, addToggle.selectedProperty()); - if (viewModel.hasDuplicate(entry)) { - Button duplicateButton = IconTheme.JabRefIcons.DUPLICATE.asButton(); - duplicateButton.setTooltip(new Tooltip(Localization.lang("Possible duplicate of existing entry. Click to resolve."))); - duplicateButton.setOnAction(event -> viewModel.resolveDuplicate(entry)); - container.getChildren().add(1, duplicateButton); - } + BackgroundTask.wrap(() -> viewModel.hasDuplicate(entry)).onSuccess(duplicateFound -> { + if (duplicateFound) { + Button duplicateButton = IconTheme.JabRefIcons.DUPLICATE.asButton(); + duplicateButton.setTooltip(new Tooltip(Localization.lang("Possible duplicate of existing entry. Click to resolve."))); + duplicateButton.setOnAction(event -> viewModel.resolveDuplicate(entry)); + container.getChildren().add(1, duplicateButton); + } + }).executeWith(Globals.TASK_EXECUTOR); return container; }) diff --git a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java index 6f0b2fad4ad..b7fec8440c9 100644 --- a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java +++ b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java @@ -10,6 +10,7 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; +import org.jabref.Globals; import org.jabref.gui.AbstractViewModel; import org.jabref.gui.DialogService; import org.jabref.gui.StateManager; @@ -50,7 +51,7 @@ public ImportEntriesViewModel(BackgroundTask> task, TaskExecutor this.message.bind(task.messageProperty()); task.onSuccess(entriesToImport -> entries.addAll(entriesToImport)) - .executeWith(taskExecutor); + .executeWith(taskExecutor); } public String getMessage() { @@ -75,24 +76,32 @@ public void importEntries(List entriesToImport) { // Check if we are supposed to warn about duplicates. // If so, then see if there are duplicates, and warn if yes. if (preferences.shouldWarnAboutDuplicatesForImport()) { - boolean containsDuplicate = entriesToImport.stream() - .anyMatch(this::hasDuplicate); - - if (containsDuplicate) { - boolean continueImport = dialogService.showConfirmationDialogWithOptOutAndWait(Localization.lang("Duplicates found"), - Localization.lang("There are possible duplicates (marked with an icon) that haven't been resolved. Continue?"), - Localization.lang("Continue with import"), - Localization.lang("Cancel import"), - Localization.lang("Disable this confirmation dialog"), - optOut -> preferences.setShouldWarnAboutDuplicatesForImport(!optOut)); - - if (!continueImport) { - dialogService.notify(Localization.lang("Import canceled")); - return; + BackgroundTask.wrap(() -> entriesToImport.stream() + .anyMatch(this::hasDuplicate)).onSuccess(duplicateFound -> { + if (duplicateFound) { + boolean continueImport = dialogService.showConfirmationDialogWithOptOutAndWait(Localization.lang("Duplicates found"), + Localization.lang("There are possible duplicates (marked with an icon) that haven't been resolved. Continue?"), + Localization.lang("Continue with import"), + Localization.lang("Cancel import"), + Localization.lang("Disable this confirmation dialog"), + optOut -> preferences.setShouldWarnAboutDuplicatesForImport(!optOut)); + + if (!continueImport) { + dialogService.notify(Localization.lang("Import canceled")); + } else { + buildImportHandlerThenImportEntries(entriesToImport); + } + } else { + buildImportHandlerThenImportEntries(entriesToImport); } - } + }).executeWith(Globals.TASK_EXECUTOR); + } else { + buildImportHandlerThenImportEntries(entriesToImport); } + } + + private void buildImportHandlerThenImportEntries(List entriesToImport) { ImportHandler importHandler = new ImportHandler( dialogService, database, @@ -104,7 +113,6 @@ public void importEntries(List entriesToImport) { undoManager, stateManager); importHandler.importEntries(entriesToImport); - dialogService.notify(Localization.lang("Number of entries successfully imported") + ": " + entriesToImport.size()); }