-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #602 from sialcasa/600_validation_visualizer_base_…
…protected_css #600 make ValidationVisualizerBase methods protected
- Loading branch information
Showing
10 changed files
with
189 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
language: java | ||
dist: trusty | ||
|
||
sudo: false | ||
|
||
|
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
44 changes: 44 additions & 0 deletions
44
...lidation/src/test/java/de/saxsys/mvvmfx/utils/validation/cssvisualizer/CssVisualizer.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,44 @@ | ||
package de.saxsys.mvvmfx.utils.validation.cssvisualizer; | ||
|
||
import de.saxsys.mvvmfx.utils.validation.ValidationMessage; | ||
import de.saxsys.mvvmfx.utils.validation.visualization.ValidationVisualizerBase; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import javafx.scene.control.Control; | ||
|
||
public class CssVisualizer extends ValidationVisualizerBase { | ||
|
||
private final String errorStyleClass; | ||
private final String validStyleClass; | ||
private final String requiredStyleClass; | ||
|
||
public CssVisualizer(String errorStyleClass, String validStyleClass, String requiredStyleClass) { | ||
this.errorStyleClass = errorStyleClass; | ||
this.validStyleClass = validStyleClass; | ||
this.requiredStyleClass = requiredStyleClass; | ||
} | ||
|
||
@Override | ||
protected void applyRequiredVisualization(Control control, boolean required) { | ||
addIfAbsent(control.getStyleClass(), requiredStyleClass); | ||
} | ||
|
||
@Override | ||
public void applyVisualization(Control control, Optional<ValidationMessage> messageOptional, boolean required) { | ||
if (messageOptional.isPresent()) { | ||
control.getStyleClass().remove(validStyleClass); | ||
addIfAbsent(control.getStyleClass(), errorStyleClass); | ||
} else { | ||
control.getStyleClass().remove(errorStyleClass); | ||
addIfAbsent(control.getStyleClass(), validStyleClass); | ||
} | ||
} | ||
|
||
private static <T> void addIfAbsent(List<T> list, T element) { | ||
if (!list.contains(element)) { | ||
list.add(element); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...rc/test/java/de/saxsys/mvvmfx/utils/validation/cssvisualizer/CssVisualizerExampleApp.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,23 @@ | ||
package de.saxsys.mvvmfx.utils.validation.cssvisualizer; | ||
|
||
import de.saxsys.mvvmfx.FluentViewLoader; | ||
import javafx.application.Application; | ||
import javafx.scene.Parent; | ||
import javafx.scene.Scene; | ||
import javafx.stage.Stage; | ||
|
||
public class CssVisualizerExampleApp extends Application { | ||
|
||
public static void main(String[] args) { | ||
launch(args); | ||
} | ||
|
||
@Override | ||
public void start(Stage primaryStage) throws Exception { | ||
|
||
Parent parent = FluentViewLoader.fxmlView(CssVisualizerView.class).load().getView(); | ||
|
||
primaryStage.setScene(new Scene(parent)); | ||
primaryStage.show(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...tion/src/test/java/de/saxsys/mvvmfx/utils/validation/cssvisualizer/CssVisualizerView.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 de.saxsys.mvvmfx.utils.validation.cssvisualizer; | ||
|
||
import de.saxsys.mvvmfx.FxmlView; | ||
import de.saxsys.mvvmfx.InjectViewModel; | ||
import de.saxsys.mvvmfx.utils.validation.visualization.ValidationVisualizer; | ||
import javafx.fxml.FXML; | ||
import javafx.scene.control.TextField; | ||
|
||
public class CssVisualizerView implements FxmlView<CssVisualizerViewModel> { | ||
|
||
@FXML | ||
private TextField email; | ||
|
||
@InjectViewModel | ||
private CssVisualizerViewModel viewModel; | ||
|
||
private ValidationVisualizer visualizer = new CssVisualizer("error", "valid", "required"); | ||
|
||
public void initialize() { | ||
email.textProperty().bindBidirectional(viewModel.emailAddressProperty()); | ||
|
||
visualizer.initVisualization(viewModel.getValidationStatus(), email, true); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...src/test/java/de/saxsys/mvvmfx/utils/validation/cssvisualizer/CssVisualizerViewModel.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,36 @@ | ||
package de.saxsys.mvvmfx.utils.validation.cssvisualizer; | ||
|
||
import de.saxsys.mvvmfx.ViewModel; | ||
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 java.util.function.Function; | ||
import java.util.regex.Pattern; | ||
|
||
import javafx.beans.property.SimpleStringProperty; | ||
import javafx.beans.property.StringProperty; | ||
|
||
public class CssVisualizerViewModel implements ViewModel { | ||
private static final Pattern EMAIL_REGEX = Pattern | ||
.compile("^$|[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"); | ||
|
||
private StringProperty emailAddress = new SimpleStringProperty(""); | ||
|
||
private Validator validator = new FunctionBasedValidator<String>(emailAddress, input -> { | ||
if (input == null || input.trim().isEmpty() || !EMAIL_REGEX.matcher(input).matches()) { | ||
return ValidationMessage.error("Invalid EMail address"); | ||
} else { | ||
return null; | ||
} | ||
}); | ||
|
||
public ValidationStatus getValidationStatus() { | ||
return validator.getValidationStatus(); | ||
} | ||
|
||
public StringProperty emailAddressProperty() { | ||
return emailAddress; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...alidation/src/test/java/de/saxsys/mvvmfx/utils/validation/cssvisualizer/package-info.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,5 @@ | ||
/** | ||
* This package contains an example for a simple custom visualizer that uses CSS styling. It's not intended to be an | ||
* official visualizer but just a starting point for people to implement their own visualizers. | ||
*/ | ||
package de.saxsys.mvvmfx.utils.validation.cssvisualizer; |
18 changes: 18 additions & 0 deletions
18
...src/test/resources/de/saxsys/mvvmfx/utils/validation/cssvisualizer/CssVisualizerView.fxml
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,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.geometry.Insets?> | ||
<?import javafx.scene.control.Label?> | ||
<?import javafx.scene.control.TextField?> | ||
<?import javafx.scene.layout.VBox?> | ||
|
||
|
||
<VBox stylesheets="@style.css" spacing="10.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.saxsys.mvvmfx.utils.validation.cssvisualizer.CssVisualizerView"> | ||
|
||
<children> | ||
<Label text="Email:" /> | ||
<TextField fx:id="email" /> | ||
</children> | ||
<padding> | ||
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" /> | ||
</padding> | ||
</VBox> |
12 changes: 12 additions & 0 deletions
12
...x-validation/src/test/resources/de/saxsys/mvvmfx/utils/validation/cssvisualizer/style.css
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,12 @@ | ||
|
||
.error { | ||
-fx-border-color: red; | ||
} | ||
|
||
.valid { | ||
-fx-border-color: green; | ||
} | ||
|
||
.required { | ||
-fx-background-color: yellow; | ||
} |