validation.registerValidator(area, Validator.createEmptyValidator("The stack trace may not be empty")); button.disableProperty().bind(validation.invalidProperty());
private void registerBasicValidators() { Validator<String> noWhitespaceName = Validator.createRegexValidator("Name cannot contain whitespace", "\\S*+", Severity.ERROR); Validator<String> emptyName = Validator.createEmptyValidator("Name required"); Validator<String> uniqueName = (c, val) -> { long sameNameDescriptors = backingDescriptorList.getOrElse(FXCollections.emptyObservableList()) .stream() .map(PropertyDescriptorSpec::getName) .filter(getName()::equals) .count(); return new ValidationResult().addErrorIf(c, "The name must be unique", sameNameDescriptors > 1); }; validationSupport.registerValidator(nameField, Validator.combine(noWhitespaceName, emptyName, uniqueName)); Validator<String> noWhitespaceDescription = Validator.createRegexValidator("Message cannot be whitespace", "(\\s*+\\S.*)?", Severity.ERROR); Validator<String> emptyDescription = Validator.createEmptyValidator("Message required"); validationSupport.registerValidator(descriptionField, Validator.combine(noWhitespaceDescription, emptyDescription)); }
/** * Combines the given validators into a single Validator instance. * @param validators the validators to combine * @return a Validator instance */ @SafeVarargs static <T> Validator<T> combine(Validator<T>... validators) { return (control, value) -> Stream.of(validators) .map(validator -> validator.apply(control, value)) .collect(Collectors.reducing(new ValidationResult(), ValidationResult::combine)); }
/** * Factory method to create a validator, which checks if value exists in the provided collection. * Error is created if not found * @param message text of a error to be created if value is not found * @param values * @return new validator */ public static <T> Validator<T> createEqualsValidator(final String message, final Collection<T> values) { return createEqualsValidator(message, Severity.ERROR, values); }
/** * Factory method to create a validator, which evaluates the value validity with a given predicate. * Error is created if the evaluation is <code>false</code>. * @param message text of a message to be created if value is invalid * @param predicate the predicate to be used for the value validity evaluation. * @return new validator */ static <T> Validator<T> createPredicateValidator(Predicate<T> predicate, String message) { return createPredicateValidator(predicate, message, Severity.ERROR); }
Platform.runLater(() -> validationResults.put(c, validator.apply(c, value))); };
/** * Factory method to create a validator, which checks if value exists. * Error is created if not if value does not exist * @param message of a error to be created if value is invalid * @return new validator */ public static <T> Validator<T> createEmptyValidator(final String message) { return createEmptyValidator(message, Severity.ERROR); }
/** * Setup of the validation of the UI controls. */ private void setupValidation() { validationSupport.registerValidator(tfName, Validator.createEmptyValidator(context.getResources().getString("st.dlg.sporttype.error.no_name"))); }
/** * Setup of the validation of the UI controls. */ private void setupValidation() { // => due to a ControlsFX bug the validation setup must be executed after the dialog has been shown // (see https://bitbucket.org/controlsfx/controlsfx/issues/539/multiple-dialog-fields-with-validation ) Platform.runLater(() -> { validationSupport.registerValidator(dpStart, Validator.createEmptyValidator(context.getResources().getString("st.dlg.filter.error.date"))); validationSupport.registerValidator(dpEnd, Validator.createEmptyValidator(context.getResources().getString("st.dlg.filter.error.date"))); }); }
private NameTextField(ProjectFolder folder) { Objects.requireNonNull(folder); new ValidationSupport().registerValidator(nameTextField, Validator.createEmptyValidator(RESOURCE_BUNDLE.getString("MandatoryName"))); nameTextField.setText(null); fileAlreadyExistsLabel.setTextFill(Color.RED); folderUnique = name -> name == null || !folder.getChild(name).isPresent(); nameTextField.textProperty().addListener((observable, oldName, newName) -> uniqueName.setValue(folderUnique.test(newName))); nameTextField.disabledProperty().addListener((observable, oldName, newName) -> uniqueName.setValue(newName)); uniqueName.addListener((observable, oldUnique, newUnique) -> { if (newUnique || nameTextField.isDisabled()) { fileAlreadyExistsLabel.setText(null); } else { fileAlreadyExistsLabel.setText(MessageFormat.format(RESOURCE_BUNDLE.getString("FileAlreadyExistsInThisFolder"), nameTextField.getText())); } }); }
@Override protected void setupDialogControls() { // setup binding between view model and the UI controls dpDate.valueProperty().bindBidirectional(noteViewModel.date); // use text formatter for time values => makes sure that the value is also valid final TextFormatter<LocalTime> timeTextFormatter = new TextFormatter<>(new TimeToStringConverter()); timeTextFormatter.valueProperty().bindBidirectional(noteViewModel.time); tfTime.setTextFormatter(timeTextFormatter); taText.textProperty().bindBidirectional(noteViewModel.comment); FxWorkarounds.fixDatePickerTextEntry(dpDate); // setup validation of the UI controls // => due to a ControlsFX bug the validation setup must be executed after the dialog has been shown // (see https://bitbucket.org/controlsfx/controlsfx/issues/539/multiple-dialog-fields-with-validation ) Platform.runLater(() -> { validationSupport.registerValidator(dpDate, // Validator.createEmptyValidator(context.getResources().getString("st.dlg.note.error.date"))); validationSupport.registerValidator(tfTime, // Validator.createEmptyValidator(context.getResources().getString("st.dlg.note.error.time"))); validationSupport.registerValidator(taText, // Validator.createEmptyValidator(context.getResources().getString("st.dlg.note.error.no_text"))); }); }
Platform.runLater( () -> { String requiredFormat = "'%s' is required"; //$NON-NLS-1$ validationSupport.registerValidator(txUserName, Validator.createEmptyValidator( String.format( requiredFormat, userNameCation ))); validationSupport.registerValidator(txPassword, Validator.createEmptyValidator(String.format( requiredFormat, passwordCaption )));
); if (mandatory) { new ValidationSupport().registerValidator(textField, Validator.createEmptyValidator(RESOURCE_BUNDLE.getString("Mandatory"))); textField.setText(null);
protected AbstractSecurityAnalysisRunnerPane(T node, Scene scene, GseContext context) { this.node = Objects.requireNonNull(node); Project project = node.getProject(); caseSelectionPane = new ProjectNodeSelectionPane<>(project, RESOURCE_BUNDLE.getString("Case"), true, scene.getWindow(), context, ProjectFile.class, ProjectCase.class); contingencyStoreSelectionPane = new ProjectNodeSelectionPane<>(project, RESOURCE_BUNDLE.getString("ContingencyStore"), true, scene.getWindow(), context, ProjectFile.class, ContingenciesProvider.class); setVgap(5); setHgap(5); setPrefWidth(450); setPrefHeight(150); ColumnConstraints column0 = new ColumnConstraints(); ColumnConstraints column1 = new ColumnConstraints(); column1.setHgrow(Priority.ALWAYS); getColumnConstraints().addAll(column0, column1); add(new Label(RESOURCE_BUNDLE.getString("Name") + ":"), 0, 0); add(nameTextField, 1, 0, 2, 1); add(caseSelectionPane.getLabel(), 0, 1); add(caseSelectionPane.getTextField(), 1, 1); add(caseSelectionPane.getButton(), 2, 1); add(contingencyStoreSelectionPane.getLabel(), 0, 2); add(contingencyStoreSelectionPane.getTextField(), 1, 2); add(contingencyStoreSelectionPane.getButton(), 2, 2); new ValidationSupport().registerValidator(nameTextField, Validator.createEmptyValidator(RESOURCE_BUNDLE.getString("MandatoryName"))); }
Validator.createEmptyValidator(context.getResources().getString("st.dlg.exercise.error.date"))); Validator.createEmptyValidator(context.getResources().getString("st.dlg.exercise.error.time"))); Validator.createEmptyValidator(context.getResources().getString("st.dlg.exercise.error.no_sport_type"))); Validator.createEmptyValidator(context.getResources().getString("st.dlg.exercise.error.no_sport_subtype"))); Validator.createEmptyValidator(context.getResources().getString("st.dlg.exercise.error.no_intensity")));
@Override protected void setupDialogControls() { laWeightUnit.setText(context.getFormatUtils().getWeightUnitName()); // setup binding between view model and the UI controls dpDate.valueProperty().bindBidirectional(weightViewModel.date); // use text formatter for time values => makes sure that the value is also valid final TextFormatter<LocalTime> timeTextFormatter = new TextFormatter<>(new TimeToStringConverter()); timeTextFormatter.valueProperty().bindBidirectional(weightViewModel.time); tfTime.setTextFormatter(timeTextFormatter); tfValue.textProperty().bindBidirectional(weightViewModel.value, new NumberStringConverter()); taComment.textProperty().bindBidirectional(weightViewModel.comment); FxWorkarounds.fixDatePickerTextEntry(dpDate); // setup validation of the UI controls // => due to a ControlsFX bug the validation setup must be executed after the dialog has been shown // (see https://bitbucket.org/controlsfx/controlsfx/issues/539/multiple-dialog-fields-with-validation ) Platform.runLater(() -> { validationSupport.registerValidator(dpDate, Validator.createEmptyValidator(context.getResources().getString("st.dlg.weight.error.date"))); validationSupport.registerValidator(tfTime, // Validator.createEmptyValidator(context.getResources().getString("st.dlg.weight.error.time"))); validationSupport.registerValidator(tfValue, true, (Control control, String newValue) -> ValidationResult .fromErrorIf(tfValue, context.getResources().getString("st.dlg.weight.error.weight"), !ValidationUtils.isValueDoubleBetween(newValue, 0.1d, 1000))); }); }