Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Schindl2016-04-12 15:00:10 -0400
committerTom Schindl2016-04-12 15:00:10 -0400
commit4eb90468aac331755f4efb68b76200966d32c09a (patch)
treed24afc56d257baaf22d3b2a328bf798c3e8d44c2
parentc1790b2b84c3f1fd8079d21b8080efb0b4b7471a (diff)
downloadorg.eclipse.efxclipse-4eb90468aac331755f4efb68b76200966d32c09a.tar.gz
org.eclipse.efxclipse-4eb90468aac331755f4efb68b76200966d32c09a.tar.xz
org.eclipse.efxclipse-4eb90468aac331755f4efb68b76200966d32c09a.zip
Bug 491535 - Add a validation story who is application to mvvm
-rw-r--r--demos/org.eclipse.fx.ui.controls.sample/src/org/eclipse/fx/ui/controls/sample/ValidationSample.java81
-rw-r--r--demos/org.eclipse.fx.ui.controls.sample/src/org/eclipse/fx/ui/controls/sample/ValidationVMSample.java87
2 files changed, 87 insertions, 81 deletions
diff --git a/demos/org.eclipse.fx.ui.controls.sample/src/org/eclipse/fx/ui/controls/sample/ValidationSample.java b/demos/org.eclipse.fx.ui.controls.sample/src/org/eclipse/fx/ui/controls/sample/ValidationSample.java
deleted file mode 100644
index c3c80047a..000000000
--- a/demos/org.eclipse.fx.ui.controls.sample/src/org/eclipse/fx/ui/controls/sample/ValidationSample.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package org.eclipse.fx.ui.controls.sample;
-
-import org.eclipse.fx.core.Status;
-import org.eclipse.fx.core.Status.State;
-import org.eclipse.fx.ui.controls.form.DefaultForm;
-import org.eclipse.fx.ui.controls.form.StatusNode;
-import org.eclipse.fx.ui.panes.GridData;
-import org.eclipse.fx.ui.panes.GridData.Alignment;
-import org.eclipse.fx.ui.panes.GridLayoutPane;
-import org.eclipse.fx.ui.controls.form.Form.BindingConfiguration;
-
-import javafx.application.Application;
-import javafx.beans.property.SimpleStringProperty;
-import javafx.beans.property.StringProperty;
-import javafx.scene.Scene;
-import javafx.scene.control.Label;
-import javafx.scene.control.TextField;
-import javafx.stage.Stage;
-
-public class ValidationSample extends Application {
-
- static class VM {
- private StringProperty firstname = new SimpleStringProperty(this, "firstname");
- private StringProperty lastname = new SimpleStringProperty(this, "lastname");
-
- public VM(String firstname, String lastname) {
- this.firstname.set(firstname);
- this.lastname.set(lastname);
- }
- }
-
- public static void main(String[] args) {
- launch(args);
- }
-
- @Override
- public void start(Stage primaryStage) throws Exception {
- GridLayoutPane p = new GridLayoutPane();
- p.setNumColumns(2);
-
- DefaultForm form = new DefaultForm();
- Label title = new Label("My Form");
- title.setGraphic(new StatusNode(form.validationStatusProperty()));
- title.setStyle("-fx-font-size: 2em; -fx-font-weight: bold;");
-
- GridLayoutPane.setConstraint(title, new GridData(Alignment.FILL,Alignment.CENTER,true,false,2,1));
- p.getChildren().add(title);
-
- VM vm = new VM("Tom", "Schindl");
-
- {
- Label l = new Label("Vorname");
- p.getChildren().add(l);
-
- TextField field = new TextField();
- p.getChildren().add(form.builder("firstname",field.textProperty(), vm.firstname, BindingConfiguration.VALIDATE_TO_OPPOSITE)
- .decoratedNode(field)
- .decoratedNodeMutator(new GridData(GridData.FILL_HORIZONTAL), GridLayoutPane::setConstraint)
- .validator( s -> s.isEmpty() ? Status.status(State.ERROR, -1, "Vorname muß befüllt sein", null) : Status.ok())
- .build()
- .nodeWithStatus());
- }
-
- {
- Label l = new Label("Nachname");
- p.getChildren().add(l);
-
- TextField field = new TextField();
- p.getChildren().add(form.builder("lastname",field.textProperty(), vm.lastname, BindingConfiguration.VALIDATE_TO_OPPOSITE)
- .decoratedNode(field)
- .decoratedNodeMutator(new GridData(GridData.FILL_HORIZONTAL), GridLayoutPane::setConstraint)
- .validator( s -> s.isEmpty() ? Status.status(State.ERROR, -1, "Nachname muß befüllt sein", null) : Status.ok())
- .build()
- .nodeWithStatus());
- }
-
- primaryStage.setScene(new Scene(p,800,600));
- primaryStage.show();
- }
-
-}
diff --git a/demos/org.eclipse.fx.ui.controls.sample/src/org/eclipse/fx/ui/controls/sample/ValidationVMSample.java b/demos/org.eclipse.fx.ui.controls.sample/src/org/eclipse/fx/ui/controls/sample/ValidationVMSample.java
new file mode 100644
index 000000000..c6b297c7f
--- /dev/null
+++ b/demos/org.eclipse.fx.ui.controls.sample/src/org/eclipse/fx/ui/controls/sample/ValidationVMSample.java
@@ -0,0 +1,87 @@
+package org.eclipse.fx.ui.controls.sample;
+
+import org.eclipse.fx.core.Status;
+import org.eclipse.fx.core.Status.State;
+import org.eclipse.fx.core.property.StatusAggregator;
+import org.eclipse.fx.core.property.ValidatedSimpleStringProperty;
+import org.eclipse.fx.core.property.ValidatedStringProperty;
+import org.eclipse.fx.ui.controls.form.DecoratedNodeBuilder;
+import org.eclipse.fx.ui.controls.form.StatusNode;
+import org.eclipse.fx.ui.panes.GridData;
+import org.eclipse.fx.ui.panes.GridData.Alignment;
+import org.eclipse.fx.ui.panes.GridLayoutPane;
+
+import javafx.application.Application;
+import javafx.beans.property.SimpleStringProperty;
+import javafx.scene.Scene;
+import javafx.scene.control.Label;
+import javafx.scene.control.TextField;
+import javafx.stage.Stage;
+
+public class ValidationVMSample extends Application {
+
+ static class VM {
+ private final ValidatedStringProperty firstname;
+ private final ValidatedStringProperty lastname;
+ private final StatusAggregator aggregator;
+
+ public VM(String firstname, String lastname) {
+ this.firstname = new ValidatedSimpleStringProperty(new SimpleStringProperty(this, "firstname",firstname));
+ this.firstname.validator(s -> s.isEmpty() ? Status.status(State.ERROR, -1, "Vorname muß befüllt sein", null) : Status.ok());
+
+ this.lastname = new ValidatedSimpleStringProperty(new SimpleStringProperty(this, "lastname", lastname));
+ this.lastname.validator(s -> s.isEmpty() ? Status.status(State.ERROR, -1, "Nachname muß befüllt sein", null) : Status.ok());
+
+ this.aggregator = new StatusAggregator(this.firstname,this.lastname);
+ }
+ }
+
+ public static void main(String[] args) {
+ launch(args);
+ }
+
+ @Override
+ public void start(Stage primaryStage) throws Exception {
+ GridLayoutPane p = new GridLayoutPane();
+ p.setNumColumns(2);
+
+ VM vm = new VM("Tom", "Schindl");
+
+ Label title = new Label("My Form");
+ title.setGraphic(new StatusNode(vm.aggregator.statusProperty()));
+ title.setStyle("-fx-font-size: 2em; -fx-font-weight: bold;");
+
+ GridLayoutPane.setConstraint(title, new GridData(Alignment.FILL,Alignment.CENTER,true,false,2,1));
+ p.getChildren().add(title);
+
+
+ {
+ Label l = new Label("Vorname");
+ p.getChildren().add(l);
+
+ TextField field = new TextField();
+ field.textProperty().bindBidirectional(vm.firstname.bindProperty());
+
+ p.getChildren().add(DecoratedNodeBuilder
+ .create(field, vm.firstname)
+ .decoratedNodeMutator(new GridData(GridData.FILL_HORIZONTAL), GridLayoutPane::setConstraint)
+ .build());
+ }
+
+ {
+ Label l = new Label("Nachname");
+ p.getChildren().add(l);
+
+ TextField field = new TextField();
+ field.textProperty().bindBidirectional(vm.lastname.bindProperty());
+
+ p.getChildren().add(DecoratedNodeBuilder
+ .create(field, vm.lastname)
+ .decoratedNodeMutator(new GridData(GridData.FILL_HORIZONTAL), GridLayoutPane::setConstraint)
+ .build());
+ }
+
+ primaryStage.setScene(new Scene(p,800,600));
+ primaryStage.show();
+ }
+}

Back to the top