Skip to content

Commit

Permalink
Merge pull request #4981 from dimmonn/fixes_4963
Browse files Browse the repository at this point in the history
Duplicate check on import should be run in background Task #4963
  • Loading branch information
Siedlerchr authored Jun 8, 2019
2 parents 2e808c2 + a6fc6f3 commit 08388b6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
15 changes: 9 additions & 6 deletions src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
})
Expand Down
42 changes: 25 additions & 17 deletions src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,7 +51,7 @@ public ImportEntriesViewModel(BackgroundTask<List<BibEntry>> task, TaskExecutor
this.message.bind(task.messageProperty());

task.onSuccess(entriesToImport -> entries.addAll(entriesToImport))
.executeWith(taskExecutor);
.executeWith(taskExecutor);
}

public String getMessage() {
Expand All @@ -75,24 +76,32 @@ public void importEntries(List<BibEntry> 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<BibEntry> entriesToImport) {
ImportHandler importHandler = new ImportHandler(
dialogService,
database,
Expand All @@ -104,7 +113,6 @@ public void importEntries(List<BibEntry> entriesToImport) {
undoManager,
stateManager);
importHandler.importEntries(entriesToImport);

dialogService.notify(Localization.lang("Number of entries successfully imported") + ": " + entriesToImport.size());
}

Expand Down

0 comments on commit 08388b6

Please sign in to comment.