Skip to content

Commit 7219e36

Browse files
Disable the generate button if the ID field is empty (#6371)
* Disable the generate button if the id field is empty * Add changelog entry * Replace empty string predicate Co-authored-by: Christoph <[email protected]>
1 parent d10e56f commit 7219e36

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
9494
- 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)
9595
- We fixed an issue where JabRef's icon was missing in the Export to clipboard Dialog. [#6286](https://github.com/JabRef/jabref/issues/6286)
9696
- 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)
97+
- We fixed an issue where adding the addition of a new entry was not completely validated [#6370](https://github.com/JabRef/jabref/issues/6370)
9798
- 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)
9899

100+
99101
### Removed
100102

101103
- 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)

src/main/java/org/jabref/gui/EntryTypeView.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.jabref.Globals;
2020
import org.jabref.gui.util.BaseDialog;
2121
import org.jabref.gui.util.ControlHelper;
22+
import org.jabref.gui.util.IconValidationDecorator;
2223
import org.jabref.gui.util.ViewModelListCellFactory;
2324
import org.jabref.logic.importer.IdBasedFetcher;
2425
import org.jabref.logic.l10n.Localization;
@@ -33,6 +34,7 @@
3334
import org.jabref.preferences.JabRefPreferences;
3435

3536
import com.airhacks.afterburner.views.ViewLoader;
37+
import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer;
3638
import org.fxmisc.easybind.EasyBind;
3739

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

6062
private EntryType type;
6163
private EntryTypeViewModel viewModel;
64+
private final ControlsFxVisualizer visualizer = new ControlsFxVisualizer();
6265

6366
public EntryTypeView(BasePanel basePanel, DialogService dialogService, JabRefPreferences preferences) {
6467
this.basePanel = basePanel;
@@ -80,7 +83,7 @@ public EntryTypeView(BasePanel basePanel, DialogService dialogService, JabRefPre
8083
Button btnGenerate = (Button) this.getDialogPane().lookupButton(generateButton);
8184

8285
btnGenerate.textProperty().bind(EasyBind.map(viewModel.searchingProperty(), searching -> (searching) ? Localization.lang("Searching...") : Localization.lang("Generate")));
83-
btnGenerate.disableProperty().bind(viewModel.searchingProperty());
86+
btnGenerate.disableProperty().bind(viewModel.idFieldValidationStatus().validProperty().not().or(viewModel.searchingProperty()));
8487

8588
EasyBind.subscribe(viewModel.searchSuccesfulProperty(), value -> {
8689
if (value) {
@@ -112,6 +115,7 @@ private void addEntriesToPane(FlowPane pane, Collection<? extends BibEntryType>
112115

113116
@FXML
114117
public void initialize() {
118+
visualizer.setDecoration(new IconValidationDecorator());
115119
viewModel = new EntryTypeViewModel(prefs, basePanel, dialogService);
116120

117121
idBasedFetchers.itemsProperty().bind(viewModel.fetcherItemsProperty());
@@ -160,7 +164,10 @@ public void initialize() {
160164
}
161165
}
162166

163-
Platform.runLater(() -> idTextField.requestFocus());
167+
Platform.runLater(() -> {
168+
idTextField.requestFocus();
169+
visualizer.initVisualization(viewModel.idFieldValidationStatus(), idTextField, true);
170+
});
164171
}
165172

166173
public EntryType getChoice() {

src/main/java/org/jabref/gui/EntryTypeViewModel.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
import org.jabref.model.strings.StringUtil;
2828
import org.jabref.preferences.JabRefPreferences;
2929

30+
import de.saxsys.mvvmfx.utils.validation.FunctionBasedValidator;
31+
import de.saxsys.mvvmfx.utils.validation.ValidationMessage;
32+
import de.saxsys.mvvmfx.utils.validation.ValidationStatus;
33+
import de.saxsys.mvvmfx.utils.validation.Validator;
3034
import org.slf4j.Logger;
3135
import org.slf4j.LoggerFactory;
3236

@@ -44,14 +48,15 @@ public class EntryTypeViewModel {
4448
private Task<Optional<BibEntry>> fetcherWorker = new FetcherWorker();
4549
private final BasePanel basePanel;
4650
private final DialogService dialogService;
51+
private final Validator idFieldValidator;
4752

4853
public EntryTypeViewModel(JabRefPreferences preferences, BasePanel basePanel, DialogService dialogService) {
4954
this.basePanel = basePanel;
5055
this.prefs = preferences;
5156
this.dialogService = dialogService;
5257
fetchers.addAll(WebFetchers.getIdBasedFetchers(preferences.getImportFormatPreferences()));
5358
selectedItemProperty.setValue(getLastSelectedFetcher());
54-
59+
idFieldValidator = new FunctionBasedValidator<>(idText, StringUtil::isNotBlank, ValidationMessage.error(Localization.lang("Required field \"%0\" is empty.", Localization.lang("ID"))));
5560
}
5661

5762
public BooleanProperty searchSuccesfulProperty() {
@@ -66,6 +71,8 @@ public ObjectProperty<IdBasedFetcher> selectedItemProperty() {
6671
return selectedItemProperty;
6772
}
6873

74+
public ValidationStatus idFieldValidationStatus() { return idFieldValidator.getValidationStatus(); }
75+
6976
public StringProperty idTextProperty() {
7077
return idText;
7178
}

0 commit comments

Comments
 (0)