-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add password validations to UnlockView
Adapted validation controls from JFoenix
- Loading branch information
Showing
11 changed files
with
472 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
desktop/src/main/java/bisq/desktop/components/controls/validator/RequiredFieldValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package bisq.desktop.components.controls.validator; | ||
|
||
import javafx.scene.control.TextInputControl; | ||
|
||
public class RequiredFieldValidator extends ValidatorBase { | ||
|
||
public RequiredFieldValidator(String message) { | ||
super(message); | ||
} | ||
|
||
@Override | ||
protected void eval() { | ||
TextInputControl textField = (TextInputControl) srcControl.get(); | ||
hasErrors.set(textField.getText() == null || textField.getText().isEmpty()); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
desktop/src/main/java/bisq/desktop/components/controls/validator/TextMinLengthValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package bisq.desktop.components.controls.validator; | ||
|
||
import javafx.scene.control.TextInputControl; | ||
|
||
public class TextMinLengthValidator extends ValidatorBase { | ||
|
||
private static final int DEFAULT_MIN_LENGTH = 8; | ||
private final int minLength; | ||
|
||
public TextMinLengthValidator(String message, int minLength) { | ||
super(message); | ||
this.minLength = minLength; | ||
} | ||
|
||
public TextMinLengthValidator(String message) { | ||
this(message, DEFAULT_MIN_LENGTH); | ||
} | ||
|
||
@Override | ||
protected void eval() { | ||
var textField = (TextInputControl) srcControl.get(); | ||
hasErrors.set(textField.getText().length() < minLength); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
desktop/src/main/java/bisq/desktop/components/controls/validator/ValidationControl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package bisq.desktop.components.controls.validator; | ||
|
||
import javafx.beans.property.ReadOnlyObjectProperty; | ||
import javafx.beans.property.ReadOnlyObjectWrapper; | ||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
import javafx.scene.control.Control; | ||
|
||
public class ValidationControl { | ||
|
||
private final ReadOnlyObjectWrapper<ValidatorBase> activeValidator = new ReadOnlyObjectWrapper<>(); | ||
|
||
private final Control control; | ||
|
||
public ValidationControl(Control control) { | ||
this.control = control; | ||
} | ||
|
||
public ValidatorBase getActiveValidator() { | ||
return activeValidator.get(); | ||
} | ||
|
||
public ReadOnlyObjectProperty<ValidatorBase> activeValidatorProperty() { | ||
return this.activeValidator.getReadOnlyProperty(); | ||
} | ||
|
||
ReadOnlyObjectWrapper<ValidatorBase> activeValidatorWritableProperty() { | ||
return this.activeValidator; | ||
} | ||
|
||
/** | ||
* list of validators that will validate the text value upon calling | ||
* {{@link #validate()} | ||
*/ | ||
private final ObservableList<ValidatorBase> validators = FXCollections.observableArrayList(); | ||
|
||
public ObservableList<ValidatorBase> getValidators() { | ||
return validators; | ||
} | ||
|
||
public void setValidators(ValidatorBase... validators) { | ||
this.validators.addAll(validators); | ||
} | ||
|
||
/** | ||
* validates the text value using the list of validators provided by the user | ||
* {{@link #setValidators(ValidatorBase...)} | ||
* | ||
* @return true if the value is valid else false | ||
*/ | ||
public boolean validate() { | ||
for (ValidatorBase validator : validators) { | ||
validator.setSrcControl(control); | ||
validator.validate(); | ||
if (validator.getHasErrors()) { | ||
activeValidator.set(validator); | ||
return false; | ||
} | ||
} | ||
activeValidator.set(null); | ||
return true; | ||
} | ||
|
||
public void resetValidation() { | ||
control.pseudoClassStateChanged(ValidatorBase.PSEUDO_CLASS_ERROR, false); | ||
activeValidator.set(null); | ||
} | ||
} |
Oops, something went wrong.