Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable the generate button if the ID field is empty #6371

Merged
merged 4 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ 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)
- We fixed an issue where the blue and red text colors in the Merge entries dialog were not quite visible [#6334](https://github.com/JabRef/jabref/issues/6334)


### Removed

- Ampersands are no longer escaped by default in the `bib` file. If you want to keep the current behaviour, you can use the new "Escape Ampersands" formatter as a save action. [#5869](https://github.com/JabRef/jabref/issues/5869)
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/jabref/gui/EntryTypeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand All @@ -59,6 +61,7 @@ public class EntryTypeView extends BaseDialog<EntryType> {

private EntryType type;
private EntryTypeViewModel viewModel;
private final ControlsFxVisualizer visualizer = new ControlsFxVisualizer();

public EntryTypeView(BasePanel basePanel, DialogService dialogService, JabRefPreferences preferences) {
this.basePanel = basePanel;
Expand All @@ -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) {
Expand Down Expand Up @@ -112,6 +115,7 @@ private void addEntriesToPane(FlowPane pane, Collection<? extends BibEntryType>

@FXML
public void initialize() {
visualizer.setDecoration(new IconValidationDecorator());
viewModel = new EntryTypeViewModel(prefs, basePanel, dialogService);

idBasedFetchers.itemsProperty().bind(viewModel.fetcherItemsProperty());
Expand Down Expand Up @@ -160,7 +164,10 @@ public void initialize() {
}
}

Platform.runLater(() -> idTextField.requestFocus());
Platform.runLater(() -> {
idTextField.requestFocus();
visualizer.initVisualization(viewModel.idFieldValidationStatus(), idTextField, true);
});
}

public EntryType getChoice() {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/jabref/gui/EntryTypeViewModel.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -44,6 +49,7 @@ public class EntryTypeViewModel {
private Task<Optional<BibEntry>> 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;
Expand All @@ -52,6 +58,9 @@ public EntryTypeViewModel(JabRefPreferences preferences, BasePanel basePanel, Di
fetchers.addAll(WebFetchers.getIdBasedFetchers(preferences.getImportFormatPreferences()));
selectedItemProperty.setValue(getLastSelectedFetcher());

Predicate<String> notEmpty = input -> (input != null) && !input.trim().isEmpty();
Copy link
Member

@tobiasdiez tobiasdiez Apr 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be replaced by StringUtil:isNotBlank

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

idFieldValidator = new FunctionBasedValidator<>(idText, notEmpty, ValidationMessage.error(Localization.lang("Required field \"%0\" is empty.", Localization.lang("ID"))));

}

public BooleanProperty searchSuccesfulProperty() {
Expand All @@ -66,6 +75,8 @@ public ObjectProperty<IdBasedFetcher> selectedItemProperty() {
return selectedItemProperty;
}

public ValidationStatus idFieldValidationStatus() { return idFieldValidator.getValidationStatus(); }

public StringProperty idTextProperty() {
return idText;
}
Expand Down