Skip to content

Commit

Permalink
Disable the generate button if the ID field is empty (#6371)
Browse files Browse the repository at this point in the history
* Disable the generate button if the id field is empty

* Add changelog entry

* Replace empty string predicate

Co-authored-by: Christoph <siedlerkiller@gmail.com>
  • Loading branch information
MootezSaaD and Siedlerchr authored Apr 29, 2020
1 parent d10e56f commit 7219e36
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
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
9 changes: 8 additions & 1 deletion src/main/java/org/jabref/gui/EntryTypeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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,14 +48,15 @@ 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;
this.prefs = preferences;
this.dialogService = dialogService;
fetchers.addAll(WebFetchers.getIdBasedFetchers(preferences.getImportFormatPreferences()));
selectedItemProperty.setValue(getLastSelectedFetcher());

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

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

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

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

0 comments on commit 7219e36

Please sign in to comment.