From f86ce7c33880ffa73f46e037be8ea10fa59c9c7e Mon Sep 17 00:00:00 2001 From: dpolishc Date: Sat, 18 May 2019 20:52:07 +0200 Subject: [PATCH 1/9] Duplicate check on import should be run in background Task #4963 --- .../gui/importer/ImportEntriesDialog.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java b/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java index ae5352deade..0beb12ad8c6 100644 --- a/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java @@ -1,6 +1,7 @@ package org.jabref.gui.importer; import java.util.List; +import java.util.concurrent.Callable; import javax.inject.Inject; import javax.swing.undo.UndoManager; @@ -20,6 +21,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 +110,15 @@ 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); - } + Callable hasDuplicateEntryTask = () -> viewModel.hasDuplicate(entry); + BackgroundTask.wrap(hasDuplicateEntryTask).onSuccess(e -> { + if (e) { + 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; }) From ebefc8581a7c900bbb2c96a335af17f6fcbe280f Mon Sep 17 00:00:00 2001 From: dpolishc Date: Mon, 20 May 2019 07:26:07 +0200 Subject: [PATCH 2/9] fixup! fixup! Too big error message #4963 (updating controlsfx, setting maxWidth and reverting off the temporary fix) --- .../gui/importer/ImportEntriesDialog.java | 3 +- .../gui/importer/ImportEntriesViewModel.java | 35 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java b/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java index 0beb12ad8c6..0aaeb427217 100644 --- a/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java @@ -110,8 +110,7 @@ private void initialize() { container.getStyleClass().add("entry-container"); BindingsHelper.includePseudoClassWhen(container, entrySelected, addToggle.selectedProperty()); - Callable hasDuplicateEntryTask = () -> viewModel.hasDuplicate(entry); - BackgroundTask.wrap(hasDuplicateEntryTask).onSuccess(e -> { + BackgroundTask.wrap(() -> viewModel.hasDuplicate(entry)).onSuccess(e -> { if (e) { Button duplicateButton = IconTheme.JabRefIcons.DUPLICATE.asButton(); duplicateButton.setTooltip(new Tooltip(Localization.lang("Possible duplicate of existing entry. Click to resolve."))); diff --git a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java index 6f0b2fad4ad..218038a349d 100644 --- a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java +++ b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java @@ -9,7 +9,7 @@ import javafx.beans.property.StringProperty; 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; @@ -25,6 +25,10 @@ import org.jabref.model.util.FileUpdateMonitor; import org.jabref.preferences.PreferencesService; +import javax.swing.undo.UndoManager; +import java.util.List; +import java.util.Optional; + public class ImportEntriesViewModel extends AbstractViewModel { private final BackgroundTask> task; @@ -75,22 +79,21 @@ 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(e -> { + if (e) { + 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")); + } } - } + }).executeWith(Globals.TASK_EXECUTOR); } ImportHandler importHandler = new ImportHandler( From 6ec9ee8ed83080d71639426b8fe7da8783e6425f Mon Sep 17 00:00:00 2001 From: dpolishc Date: Mon, 20 May 2019 07:56:43 +0200 Subject: [PATCH 3/9] Duplicate check on import should be run in background Task #4963 (adding background task for view model) --- .../java/org/jabref/gui/importer/ImportEntriesDialog.java | 1 - .../org/jabref/gui/importer/ImportEntriesViewModel.java | 8 ++------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java b/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java index 0aaeb427217..af0264f0229 100644 --- a/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java @@ -1,7 +1,6 @@ package org.jabref.gui.importer; import java.util.List; -import java.util.concurrent.Callable; import javax.inject.Inject; import javax.swing.undo.UndoManager; diff --git a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java index 218038a349d..df85f6bdc48 100644 --- a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java +++ b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java @@ -1,14 +1,10 @@ package org.jabref.gui.importer; -import java.util.List; -import java.util.Optional; - -import javax.swing.undo.UndoManager; - import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; + import org.jabref.Globals; import org.jabref.gui.AbstractViewModel; import org.jabref.gui.DialogService; @@ -54,7 +50,7 @@ public ImportEntriesViewModel(BackgroundTask> task, TaskExecutor this.message.bind(task.messageProperty()); task.onSuccess(entriesToImport -> entries.addAll(entriesToImport)) - .executeWith(taskExecutor); + .executeWith(taskExecutor); } public String getMessage() { From c27f6e637d677c4b8a428d38fed3d434f714711c Mon Sep 17 00:00:00 2001 From: dpolishc Date: Mon, 20 May 2019 08:03:00 +0200 Subject: [PATCH 4/9] Duplicate check on import should be run in background Task #4963 (checkstyle fix) --- .../org/jabref/gui/importer/ImportEntriesViewModel.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java index df85f6bdc48..dc8d533338d 100644 --- a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java +++ b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java @@ -1,5 +1,10 @@ package org.jabref.gui.importer; +import java.util.List; +import java.util.Optional; + +import javax.swing.undo.UndoManager; + import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.collections.FXCollections; @@ -21,10 +26,6 @@ import org.jabref.model.util.FileUpdateMonitor; import org.jabref.preferences.PreferencesService; -import javax.swing.undo.UndoManager; -import java.util.List; -import java.util.Optional; - public class ImportEntriesViewModel extends AbstractViewModel { private final BackgroundTask> task; From bb5b2a92ccf1c77f11258edd9b23e461ac4b9c64 Mon Sep 17 00:00:00 2001 From: dpolishc Date: Tue, 21 May 2019 21:28:22 +0200 Subject: [PATCH 5/9] Duplicate check on import should be run in background Task #4963 --- .../gui/importer/ImportEntriesViewModel.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java index dc8d533338d..b4372d4cba5 100644 --- a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java +++ b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java @@ -88,24 +88,24 @@ public void importEntries(List entriesToImport) { if (!continueImport) { dialogService.notify(Localization.lang("Import canceled")); + } else { + ImportHandler importHandler = new ImportHandler( + dialogService, + database, + ExternalFileTypes.getInstance(), + preferences.getFilePreferences(), + preferences.getImportFormatPreferences(), + preferences.getUpdateFieldPreferences(), + fileUpdateMonitor, + undoManager, + stateManager); + importHandler.importEntries(entriesToImport); + dialogService.notify(Localization.lang("Number of entries successfully imported") + ": " + entriesToImport.size()); } } }).executeWith(Globals.TASK_EXECUTOR); } - ImportHandler importHandler = new ImportHandler( - dialogService, - database, - ExternalFileTypes.getInstance(), - preferences.getFilePreferences(), - preferences.getImportFormatPreferences(), - preferences.getUpdateFieldPreferences(), - fileUpdateMonitor, - undoManager, - stateManager); - importHandler.importEntries(entriesToImport); - - dialogService.notify(Localization.lang("Number of entries successfully imported") + ": " + entriesToImport.size()); } /** From f7c0551d47d1278a3e1d04c9ec92aab39904dffa Mon Sep 17 00:00:00 2001 From: dpolishc Date: Sun, 26 May 2019 21:40:55 +0200 Subject: [PATCH 6/9] Duplicate check on import should be run in background Task #4963 --- .../gui/importer/ImportEntriesViewModel.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java index b4372d4cba5..40706fdc070 100644 --- a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java +++ b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java @@ -89,25 +89,33 @@ public void importEntries(List entriesToImport) { if (!continueImport) { dialogService.notify(Localization.lang("Import canceled")); } else { - ImportHandler importHandler = new ImportHandler( - dialogService, - database, - ExternalFileTypes.getInstance(), - preferences.getFilePreferences(), - preferences.getImportFormatPreferences(), - preferences.getUpdateFieldPreferences(), - fileUpdateMonitor, - undoManager, - stateManager); - importHandler.importEntries(entriesToImport); + buildImportHandlerThenImportEntries(entriesToImport); dialogService.notify(Localization.lang("Number of entries successfully imported") + ": " + entriesToImport.size()); } + } else { + buildImportHandlerThenImportEntries(entriesToImport); } }).executeWith(Globals.TASK_EXECUTOR); + } else { + buildImportHandlerThenImportEntries(entriesToImport); } } + private void buildImportHandlerThenImportEntries(List entriesToImport) { + ImportHandler importHandler = new ImportHandler( + dialogService, + database, + ExternalFileTypes.getInstance(), + preferences.getFilePreferences(), + preferences.getImportFormatPreferences(), + preferences.getUpdateFieldPreferences(), + fileUpdateMonitor, + undoManager, + stateManager); + importHandler.importEntries(entriesToImport); + } + /** * Checks if there are duplicates to the given entry in the list of entries to be imported. * From 300eae70c935ee5a2ca26ec096e8af725a8d93c3 Mon Sep 17 00:00:00 2001 From: dpolishc Date: Mon, 27 May 2019 19:14:10 +0200 Subject: [PATCH 7/9] Duplicate check on import should be run in background Task (changing var name) --- .../java/org/jabref/gui/importer/ImportEntriesViewModel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java index 40706fdc070..5f94d08c85a 100644 --- a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java +++ b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java @@ -77,8 +77,8 @@ public void importEntries(List entriesToImport) { // If so, then see if there are duplicates, and warn if yes. if (preferences.shouldWarnAboutDuplicatesForImport()) { BackgroundTask.wrap(() -> entriesToImport.stream() - .anyMatch(this::hasDuplicate)).onSuccess(e -> { - if (e) { + .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"), From 006a443776ec58cac174d7d6aac98d61dfe4b87f Mon Sep 17 00:00:00 2001 From: dpolishc Date: Sun, 2 Jun 2019 16:00:00 +0200 Subject: [PATCH 8/9] Duplicate check on import should be run in background Task #4963 --- .../java/org/jabref/gui/importer/ImportEntriesViewModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java index 5f94d08c85a..b7fec8440c9 100644 --- a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java +++ b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java @@ -90,7 +90,6 @@ public void importEntries(List entriesToImport) { dialogService.notify(Localization.lang("Import canceled")); } else { buildImportHandlerThenImportEntries(entriesToImport); - dialogService.notify(Localization.lang("Number of entries successfully imported") + ": " + entriesToImport.size()); } } else { buildImportHandlerThenImportEntries(entriesToImport); @@ -114,6 +113,7 @@ private void buildImportHandlerThenImportEntries(List entriesToImport) undoManager, stateManager); importHandler.importEntries(entriesToImport); + dialogService.notify(Localization.lang("Number of entries successfully imported") + ": " + entriesToImport.size()); } /** From a6fc6f3d90f0b497357c3610f64de73cef4ef81d Mon Sep 17 00:00:00 2001 From: dpolishc Date: Sun, 2 Jun 2019 22:06:08 +0200 Subject: [PATCH 9/9] Duplicate check on import should be run in background #4963 --- .../java/org/jabref/gui/importer/ImportEntriesDialog.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java b/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java index af0264f0229..40ad459433b 100644 --- a/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java @@ -109,8 +109,8 @@ private void initialize() { container.getStyleClass().add("entry-container"); BindingsHelper.includePseudoClassWhen(container, entrySelected, addToggle.selectedProperty()); - BackgroundTask.wrap(() -> viewModel.hasDuplicate(entry)).onSuccess(e -> { - if (e) { + 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));