Skip to content

Commit

Permalink
format code of validator
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-mauky committed Jun 10, 2015
1 parent 766a9b3 commit 1ecaeb4
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void initialize() {
phoneNumberInput.textProperty().bindBidirectional(viewModel.phoneNumberProperty());
emailInput.textProperty().bindBidirectional(viewModel.emailProperty());
birthdayInput.valueProperty().bindBidirectional(viewModel.birthdayProperty());

validationVisualizer.initVisualization(viewModel.firstnameValidation(), firstnameInput, true);
validationVisualizer.initVisualization(viewModel.lastnameValidation(), lastnameInput, true);
validationVisualizer.initVisualization(viewModel.birthdayValidation(), birthdayInput);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ public class ContactFormViewModel implements ViewModel {

private Validator phoneValidator = new PhoneValidator(phoneNumberProperty(), "The phone number is invalid!");
private Validator mobileValidator = new PhoneValidator(mobileNumberProperty(), "The mobile number is invalid!");

private CompositeValidator formValidator = new CompositeValidator();

public ContactFormViewModel() {
firstnameValidator = new FunctionBasedValidator<>(
firstnameProperty(),
firstName -> firstName != null && !firstName.trim().isEmpty(),
ValidationMessage.error("Firstname may not be empty"));


lastnameValidator = new FunctionBasedValidator<>(lastnameProperty(), lastName -> {
if(lastName == null || lastName.isEmpty()) {
return ValidationMessage.error("Lastname may not be empty");
} else if(lastName.trim().isEmpty()) {
return ValidationMessage.error("Lastname may not only contain whitespaces");
}

return null;
});


firstnameValidator = new FunctionBasedValidator<>(
firstnameProperty(),
firstName -> firstName != null && !firstName.trim().isEmpty(),
ValidationMessage.error("Firstname may not be empty"));
lastnameValidator = new FunctionBasedValidator<>(lastnameProperty(), lastName -> {
if (lastName == null || lastName.isEmpty()) {
return ValidationMessage.error("Lastname may not be empty");
} else if (lastName.trim().isEmpty()) {
return ValidationMessage.error("Lastname may not only contain whitespaces");
}
return null;
});
formValidator.addValidators(
firstnameValidator,
lastnameValidator,
Expand All @@ -56,20 +56,20 @@ public ContactFormViewModel() {
public void resetForm() {
contactWrapper.reset();
}

public void initWithContact(Contact contact) {
this.contactWrapper.set(contact);
this.contactWrapper.reload();
}

public Contact getContact() {

if(contactWrapper.get() == null) {
if (contactWrapper.get() == null) {
contactWrapper.set(new Contact());
}

contactWrapper.commit();

return contactWrapper.get();
}

Expand All @@ -84,11 +84,11 @@ public ValidationStatus lastnameValidation() {
public ValidationStatus birthdayValidation() {
return birthdayValidator.getValidationStatus();
}

public ValidationStatus emailValidation() {
return emailValidator.getValidationStatus();
}

public ValidationStatus emailValidation() {
return emailValidator.getValidationStatus();
}
public ValidationStatus phoneValidation() {
return phoneValidator.getValidationStatus();
}
Expand Down Expand Up @@ -132,8 +132,8 @@ public StringProperty mobileNumberProperty() {
public StringProperty phoneNumberProperty() {
return contactWrapper.field("phoneNumber", Contact::getPhoneNumber, Contact::setPhoneNumber);
}

public BooleanExpression validProperty() {
return formValidator.getValidationStatus().validProperty();
}
public BooleanExpression validProperty() {
return formValidator.getValidationStatus().validProperty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @author manuel.mauky
*/
public class CrossFieldExampleApp extends Application {

public static void main(String... args) {
launch(args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author manuel.mauky
*/
public class RegisterFormView implements FxmlView<RegisterFormViewModel> {

@FXML
public PasswordField pwInput;
@FXML
Expand All @@ -24,10 +24,10 @@ public class RegisterFormView implements FxmlView<RegisterFormViewModel> {
public Label message;
@FXML
public Button okButton;

@InjectViewModel
private RegisterFormViewModel viewModel;


public void initialize() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class RegisterFormViewModel implements ViewModel {

private StringProperty password = new SimpleStringProperty();
private StringProperty passwordRepeat = new SimpleStringProperty();


private ObservableRuleBasedValidator passwordValidator = new ObservableRuleBasedValidator();

Expand All @@ -30,33 +30,33 @@ public RegisterFormViewModel() {
passwordValidator.addRule(rule2, ValidationMessage.error("Please enter the password a second time"));
passwordValidator.addRule(rule3, ValidationMessage.error("Both passwords need to be the same"));
}

public ValidationStatus getValidation() {
return passwordValidator.getValidationStatus();
}

public String getPassword() {
return password.get();
}

public StringProperty passwordProperty() {
return password;
}

public void setPassword(String password) {
this.password.set(password);
}

public String getPasswordRepeat() {
return passwordRepeat.get();
}

public StringProperty passwordRepeatProperty() {
return passwordRepeat;
}

public void setPasswordRepeat(String passwordRepeat) {
this.passwordRepeat.set(passwordRepeat);
}

}

0 comments on commit 1ecaeb4

Please sign in to comment.