change editor to the new config

The editor should handle the new configuration
This commit is contained in:
2016-09-01 08:12:26 +02:00
committed by Andreas Billmann
parent 0c391e292e
commit 742f129ea9
5 changed files with 43 additions and 52 deletions

View File

@@ -35,6 +35,7 @@ import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.control.SpinnerValueFactory.IntegerSpinnerValueFactory;
import ninja.javafx.smartcsv.fx.FXMLController;
import ninja.javafx.smartcsv.validation.FieldConfiguration;
import ninja.javafx.smartcsv.validation.ValidationConfiguration;
import org.fxmisc.richtext.CodeArea;
import org.fxmisc.richtext.LineNumberFactory;
@@ -100,20 +101,8 @@ public class ValidationEditorController extends FXMLController {
+ "|(?<COMMENT>" + COMMENT_PATTERN + ")"
);
// @FXML
// private CheckBox notEmptyRuleCheckBox;
//
// @FXML
// private CheckBox integerRuleCheckBox;
//
// @FXML
// private CheckBox doublerRuleCheckBox;
//
// @FXML
// private CheckBox alphanumericRuleCheckBox;
//
// @FXML
// private CheckBox uniqueRuleCheckBox;
@FXML
private ComboBox<FieldConfiguration.Type> typeComboBox;
@FXML
private Spinner<Integer> minLengthSpinner;
@@ -136,15 +125,6 @@ public class ValidationEditorController extends FXMLController {
@FXML
private CheckBox enableNotEmptyRule;
@FXML
private CheckBox enableIntegerRule;
@FXML
private CheckBox enableDoubleRule;
@FXML
private CheckBox enableAlphanumericRule;
@FXML
private CheckBox enableMinLengthRule;
@@ -176,6 +156,13 @@ public class ValidationEditorController extends FXMLController {
@Override
public void initialize(URL location, ResourceBundle resources) {
typeComboBox.getItems().addAll(FieldConfiguration.Type.STRING,
FieldConfiguration.Type.INTEGER,
FieldConfiguration.Type.NUMBER,
FieldConfiguration.Type.DATE,
FieldConfiguration.Type.DATETIME,
FieldConfiguration.Type.TIME);
initMinMaxSpinner();
initSpinner(minLengthSpinner, enableMinLengthRule);
@@ -185,7 +172,6 @@ public class ValidationEditorController extends FXMLController {
initTextInputControl(valueOfRuleTextField, enableValueOfRule);
initCodeAreaControl(groovyRuleTextArea, enableGroovyRule);
listenToExcludingRuleCombinations();
selectedColumn.addListener(observable -> {
updateForm();
@@ -296,13 +282,6 @@ public class ValidationEditorController extends FXMLController {
}
private void listenToExcludingRuleCombinations() {
addDependencyListener(enableIntegerRule, enableDoubleRule, enableAlphanumericRule, enableDateRule);
addDependencyListener(enableDoubleRule, enableIntegerRule, enableAlphanumericRule, enableDateRule);
addDependencyListener(enableAlphanumericRule, enableIntegerRule, enableDoubleRule, enableDateRule);
addDependencyListener(enableDateRule, enableIntegerRule, enableDoubleRule, enableAlphanumericRule);
}
private void addDependencyListener(CheckBox rule, CheckBox... dependentRules) {
rule.selectedProperty().addListener((observable, oldValue, newValue) -> {
if (newValue) {

View File

@@ -1,5 +1,7 @@
package ninja.javafx.smartcsv.validation;
import com.google.gson.annotations.SerializedName;
import java.util.List;
import java.util.Map;
@@ -8,9 +10,18 @@ import java.util.Map;
*/
public class FieldConfiguration {
public enum Type {
@SerializedName("string") STRING,
@SerializedName("integer") INTEGER,
@SerializedName("number") NUMBER,
@SerializedName("date") DATE,
@SerializedName("datetime") DATETIME,
@SerializedName("time") TIME
}
private String name;
private String title;
private String type;
private Type type;
private String description;
private String format;
private Object missingValue;
@@ -32,11 +43,11 @@ public class FieldConfiguration {
this.title = title;
}
public String getType() {
public Type getType() {
return type;
}
public void setType(String type) {
public void setType(Type type) {
this.type = type;
}

View File

@@ -30,7 +30,7 @@ package ninja.javafx.smartcsv.validation;
*/
public interface Validation {
enum Type { NOT_EMPTY, UNIQUE, DOUBLE, INTEGER, MIN_LENGTH, MAX_LENGTH, DATE, ALPHANUMERIC, REGEXP, VALUE_OF, GROOVY }
enum Type { NOT_EMPTY, UNIQUE, DOUBLE, INTEGER, MIN_LENGTH, MAX_LENGTH, DATE, REGEXP, VALUE_OF, GROOVY }
void check(int row, String value, ValidationError error);
Type getType();
boolean canBeChecked(String value);

View File

@@ -157,25 +157,25 @@ public class Validator {
private void initializeColumnWithRules(FieldConfiguration column) {
if (column.getType() != null) {
if (column.getType().equals("number")) {
if (column.getType() == FieldConfiguration.Type.NUMBER) {
add(column.getName(), new DoubleValidation());
}
if (column.getType().equals("integer")) {
if (column.getType() == FieldConfiguration.Type.INTEGER) {
add(column.getName(), new IntegerValidation());
}
if (column.getType().equals("date")) {
if (column.getType() == FieldConfiguration.Type.DATE) {
String format = dateFormat(column.getFormat(), "YYYY-MM-DD");
add(column.getName(), new DateValidation(format));
}
if (column.getType().equals("datetime")) {
if (column.getType() == FieldConfiguration.Type.DATETIME) {
String format = dateFormat(column.getFormat(), "YYYY-MM-DDThh:mm:ssZ");
add(column.getName(), new DateValidation(format));
}
if (column.getType().equals("time")) {
if (column.getType() == FieldConfiguration.Type.TIME) {
String format = dateFormat(column.getFormat(), "hh:mm:ss");
add(column.getName(), new DateValidation(format));
}