From 8fd865ef9e39fadce38dfff8e4e73b5ab9bdec88 Mon Sep 17 00:00:00 2001 From: Mootez Date: Tue, 28 Apr 2020 10:47:56 +0100 Subject: [PATCH 1/3] Disable the generate button if the id field is empty --- src/main/java/org/jabref/gui/EntryTypeView.java | 11 +++++++++-- src/main/java/org/jabref/gui/EntryTypeViewModel.java | 11 +++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/EntryTypeView.java b/src/main/java/org/jabref/gui/EntryTypeView.java index 657fe4b20f0..e4f0d11a9c7 100644 --- a/src/main/java/org/jabref/gui/EntryTypeView.java +++ b/src/main/java/org/jabref/gui/EntryTypeView.java @@ -19,6 +19,7 @@ import org.jabref.Globals; import org.jabref.gui.util.BaseDialog; import org.jabref.gui.util.ControlHelper; +import org.jabref.gui.util.IconValidationDecorator; import org.jabref.gui.util.ViewModelListCellFactory; import org.jabref.logic.importer.IdBasedFetcher; import org.jabref.logic.l10n.Localization; @@ -33,6 +34,7 @@ import org.jabref.preferences.JabRefPreferences; import com.airhacks.afterburner.views.ViewLoader; +import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer; import org.fxmisc.easybind.EasyBind; /** @@ -59,6 +61,7 @@ public class EntryTypeView extends BaseDialog { private EntryType type; private EntryTypeViewModel viewModel; + private final ControlsFxVisualizer visualizer = new ControlsFxVisualizer(); public EntryTypeView(BasePanel basePanel, DialogService dialogService, JabRefPreferences preferences) { this.basePanel = basePanel; @@ -80,7 +83,7 @@ public EntryTypeView(BasePanel basePanel, DialogService dialogService, JabRefPre Button btnGenerate = (Button) this.getDialogPane().lookupButton(generateButton); btnGenerate.textProperty().bind(EasyBind.map(viewModel.searchingProperty(), searching -> (searching) ? Localization.lang("Searching...") : Localization.lang("Generate"))); - btnGenerate.disableProperty().bind(viewModel.searchingProperty()); + btnGenerate.disableProperty().bind(viewModel.idFieldValidationStatus().validProperty().not().or(viewModel.searchingProperty())); EasyBind.subscribe(viewModel.searchSuccesfulProperty(), value -> { if (value) { @@ -112,6 +115,7 @@ private void addEntriesToPane(FlowPane pane, Collection @FXML public void initialize() { + visualizer.setDecoration(new IconValidationDecorator()); viewModel = new EntryTypeViewModel(prefs, basePanel, dialogService); idBasedFetchers.itemsProperty().bind(viewModel.fetcherItemsProperty()); @@ -160,7 +164,10 @@ public void initialize() { } } - Platform.runLater(() -> idTextField.requestFocus()); + Platform.runLater(() -> { + idTextField.requestFocus(); + visualizer.initVisualization(viewModel.idFieldValidationStatus(), idTextField, true); + }); } public EntryType getChoice() { diff --git a/src/main/java/org/jabref/gui/EntryTypeViewModel.java b/src/main/java/org/jabref/gui/EntryTypeViewModel.java index 62344a16889..2019f25e600 100644 --- a/src/main/java/org/jabref/gui/EntryTypeViewModel.java +++ b/src/main/java/org/jabref/gui/EntryTypeViewModel.java @@ -1,6 +1,7 @@ package org.jabref.gui; import java.util.Optional; +import java.util.function.Predicate; import javafx.beans.property.BooleanProperty; import javafx.beans.property.ListProperty; @@ -27,6 +28,10 @@ import org.jabref.model.strings.StringUtil; import org.jabref.preferences.JabRefPreferences; +import de.saxsys.mvvmfx.utils.validation.FunctionBasedValidator; +import de.saxsys.mvvmfx.utils.validation.ValidationMessage; +import de.saxsys.mvvmfx.utils.validation.ValidationStatus; +import de.saxsys.mvvmfx.utils.validation.Validator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,6 +49,7 @@ public class EntryTypeViewModel { private Task> fetcherWorker = new FetcherWorker(); private final BasePanel basePanel; private final DialogService dialogService; + private final Validator idFieldValidator; public EntryTypeViewModel(JabRefPreferences preferences, BasePanel basePanel, DialogService dialogService) { this.basePanel = basePanel; @@ -52,6 +58,9 @@ public EntryTypeViewModel(JabRefPreferences preferences, BasePanel basePanel, Di fetchers.addAll(WebFetchers.getIdBasedFetchers(preferences.getImportFormatPreferences())); selectedItemProperty.setValue(getLastSelectedFetcher()); + Predicate notEmpty = input -> (input != null) && !input.trim().isEmpty(); + idFieldValidator = new FunctionBasedValidator<>(idText, notEmpty, ValidationMessage.error(Localization.lang("Required field \"%0\" is empty.", Localization.lang("ID")))); + } public BooleanProperty searchSuccesfulProperty() { @@ -66,6 +75,8 @@ public ObjectProperty selectedItemProperty() { return selectedItemProperty; } + public ValidationStatus idFieldValidationStatus() { return idFieldValidator.getValidationStatus(); } + public StringProperty idTextProperty() { return idText; } From b7555edd40b264c695e4e6646e3752daa9377cdb Mon Sep 17 00:00:00 2001 From: Mootez Date: Tue, 28 Apr 2020 12:19:50 +0100 Subject: [PATCH 2/3] Add changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66e4e2f17e1..1e7baaccacd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -91,7 +91,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where an exception was thrown when adding a save action without a selected formatter in the library properties [#6069](https://github.com/JabRef/jabref/issues/6069) - We fixed an issue where JabRef's icon was missing in the Export to clipboard Dialog. [#6286](https://github.com/JabRef/jabref/issues/6286) - We fixed an issue when an "Abstract field" was duplicating text, when importing from RIS file (Neurons) [#6065](https://github.com/JabRef/jabref/issues/6065) - +- We fixed an issue where adding the addition of a new entry was not completely validated [#6370](https://github.com/JabRef/jabref/issues/6370) ### Removed From 8ee1bffcaf1a4ca1ca0ca0e93d0509b61540f02d Mon Sep 17 00:00:00 2001 From: Mootez Date: Wed, 29 Apr 2020 15:13:49 +0100 Subject: [PATCH 3/3] Replace empty string predicate --- src/main/java/org/jabref/gui/EntryTypeViewModel.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/org/jabref/gui/EntryTypeViewModel.java b/src/main/java/org/jabref/gui/EntryTypeViewModel.java index 2019f25e600..c3284a74a90 100644 --- a/src/main/java/org/jabref/gui/EntryTypeViewModel.java +++ b/src/main/java/org/jabref/gui/EntryTypeViewModel.java @@ -1,7 +1,6 @@ package org.jabref.gui; import java.util.Optional; -import java.util.function.Predicate; import javafx.beans.property.BooleanProperty; import javafx.beans.property.ListProperty; @@ -57,10 +56,7 @@ public EntryTypeViewModel(JabRefPreferences preferences, BasePanel basePanel, Di this.dialogService = dialogService; fetchers.addAll(WebFetchers.getIdBasedFetchers(preferences.getImportFormatPreferences())); selectedItemProperty.setValue(getLastSelectedFetcher()); - - Predicate notEmpty = input -> (input != null) && !input.trim().isEmpty(); - idFieldValidator = new FunctionBasedValidator<>(idText, notEmpty, ValidationMessage.error(Localization.lang("Required field \"%0\" is empty.", Localization.lang("ID")))); - + idFieldValidator = new FunctionBasedValidator<>(idText, StringUtil::isNotBlank, ValidationMessage.error(Localization.lang("Required field \"%0\" is empty.", Localization.lang("ID")))); } public BooleanProperty searchSuccesfulProperty() {