mirror of
https://github.com/frosch95/SmartCSV.fx.git
synced 2026-04-11 13:38:23 +02:00
read constraints into an object instead of some map structure and change form init of validation editor
This commit is contained in:
@@ -26,15 +26,13 @@
|
|||||||
|
|
||||||
package ninja.javafx.smartcsv.fx.validation;
|
package ninja.javafx.smartcsv.fx.validation;
|
||||||
|
|
||||||
import javafx.beans.binding.Bindings;
|
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.beans.property.StringProperty;
|
import javafx.beans.property.StringProperty;
|
||||||
import javafx.beans.value.ChangeListener;
|
|
||||||
import javafx.beans.value.ObservableValue;
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.control.SpinnerValueFactory.IntegerSpinnerValueFactory;
|
import javafx.scene.control.SpinnerValueFactory.IntegerSpinnerValueFactory;
|
||||||
import ninja.javafx.smartcsv.fx.FXMLController;
|
import ninja.javafx.smartcsv.fx.FXMLController;
|
||||||
|
import ninja.javafx.smartcsv.validation.ConstraintsConfiguration;
|
||||||
import ninja.javafx.smartcsv.validation.FieldConfiguration;
|
import ninja.javafx.smartcsv.validation.FieldConfiguration;
|
||||||
import ninja.javafx.smartcsv.validation.ValidationConfiguration;
|
import ninja.javafx.smartcsv.validation.ValidationConfiguration;
|
||||||
import org.fxmisc.richtext.CodeArea;
|
import org.fxmisc.richtext.CodeArea;
|
||||||
@@ -52,10 +50,8 @@ import java.util.ResourceBundle;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
|
||||||
import static java.util.stream.Collectors.joining;
|
import static java.util.stream.Collectors.joining;
|
||||||
import static javafx.beans.binding.Bindings.when;
|
import static javafx.beans.binding.Bindings.when;
|
||||||
import static ninja.javafx.smartcsv.validation.ValidationFormatHelper.doubleToInteger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* controller for editing column validations
|
* controller for editing column validations
|
||||||
@@ -82,7 +78,7 @@ public class ValidationEditorController extends FXMLController {
|
|||||||
"transient", "true", "try", "void", "volatile", "while"
|
"transient", "true", "try", "void", "volatile", "while"
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final String KEYWORD_PATTERN = "\\b(" + String.join("|", KEYWORDS) + ")\\b";
|
private static final String KEYWORD_PATTERN = "\\b(" + String.join("|", (CharSequence[]) KEYWORDS) + ")\\b";
|
||||||
private static final String PAREN_PATTERN = "\\(|\\)";
|
private static final String PAREN_PATTERN = "\\(|\\)";
|
||||||
private static final String BRACE_PATTERN = "\\{|\\}";
|
private static final String BRACE_PATTERN = "\\{|\\}";
|
||||||
private static final String BRACKET_PATTERN = "\\[|\\]";
|
private static final String BRACKET_PATTERN = "\\[|\\]";
|
||||||
@@ -157,6 +153,7 @@ public class ValidationEditorController extends FXMLController {
|
|||||||
FieldConfiguration.Type.DATE,
|
FieldConfiguration.Type.DATE,
|
||||||
FieldConfiguration.Type.DATETIME,
|
FieldConfiguration.Type.DATETIME,
|
||||||
FieldConfiguration.Type.TIME);
|
FieldConfiguration.Type.TIME);
|
||||||
|
typeComboBox.setValue(FieldConfiguration.Type.STRING);
|
||||||
|
|
||||||
initMinMaxSpinner();
|
initMinMaxSpinner();
|
||||||
|
|
||||||
@@ -288,45 +285,49 @@ public class ValidationEditorController extends FXMLController {
|
|||||||
|
|
||||||
private void updateForm() {
|
private void updateForm() {
|
||||||
|
|
||||||
updateCheckBox(
|
FieldConfiguration config = validationConfiguration.getFieldConfiguration(getSelectedColumn());
|
||||||
(Boolean)validationConfiguration.getFieldConfiguration(getSelectedColumn()).getConstraints().get("required"),
|
|
||||||
enableNotEmptyRule
|
if (config.getType() != null) {
|
||||||
|
typeComboBox.setValue(config.getType());
|
||||||
|
} else {
|
||||||
|
typeComboBox.setValue(FieldConfiguration.Type.STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateCodeAreaControl(
|
||||||
|
groovyRuleTextArea,
|
||||||
|
config.getGroovy(),
|
||||||
|
enableGroovyRule
|
||||||
);
|
);
|
||||||
|
|
||||||
updateCheckBox(
|
ConstraintsConfiguration constraints = config.getConstraints();
|
||||||
(Boolean)validationConfiguration.getFieldConfiguration(getSelectedColumn()).getConstraints().get("unique"),
|
updateCheckBox(constraints != null ? constraints.getRequired() : false, enableNotEmptyRule);
|
||||||
enableUniqueRule
|
updateCheckBox(constraints != null ? constraints.getUnique() : false, enableUniqueRule);
|
||||||
);
|
|
||||||
|
|
||||||
updateSpinner(
|
updateSpinner(
|
||||||
minLengthSpinner,
|
minLengthSpinner,
|
||||||
doubleToInteger((Double)validationConfiguration.getFieldConfiguration(getSelectedColumn()).getConstraints().get("minLength")),
|
constraints != null ? constraints.getMinLength() : null,
|
||||||
enableMinLengthRule
|
enableMinLengthRule
|
||||||
);
|
);
|
||||||
|
|
||||||
updateSpinner(
|
updateSpinner(
|
||||||
maxLengthSpinner,
|
maxLengthSpinner,
|
||||||
doubleToInteger((Double)validationConfiguration.getFieldConfiguration(getSelectedColumn()).getConstraints().get("maxLength")),
|
constraints != null ? constraints.getMaxLength() : null,
|
||||||
enableMaxLengthRule
|
enableMaxLengthRule
|
||||||
);
|
);
|
||||||
|
|
||||||
updateTextInputControl(
|
updateTextInputControl(
|
||||||
regexpRuleTextField,
|
regexpRuleTextField,
|
||||||
(String)validationConfiguration.getFieldConfiguration(getSelectedColumn()).getConstraints().get("pattern"),
|
constraints != null ? constraints.getPattern() : null,
|
||||||
enableRegexpRule
|
enableRegexpRule
|
||||||
);
|
);
|
||||||
|
|
||||||
updateTextInputControl(
|
updateTextInputControl(
|
||||||
valueOfRuleTextField,
|
valueOfRuleTextField,
|
||||||
(String)validationConfiguration.getFieldConfiguration(getSelectedColumn()).getConstraints().get("enum"),
|
constraints != null ? constraints.getEnumeration() : null,
|
||||||
enableValueOfRule
|
enableValueOfRule
|
||||||
);
|
);
|
||||||
|
|
||||||
updateCodeAreaControl(
|
|
||||||
groovyRuleTextArea,
|
|
||||||
(String)validationConfiguration.getFieldConfiguration(getSelectedColumn()).getConstraints().get("groovy"),
|
|
||||||
enableGroovyRule
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCheckBox(Boolean value, CheckBox ruleEnabled) {
|
private void updateCheckBox(Boolean value, CheckBox ruleEnabled) {
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package ninja.javafx.smartcsv.validation;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by PC on 04.09.2016.
|
||||||
|
*/
|
||||||
|
public class ConstraintsConfiguration {
|
||||||
|
private Boolean required;
|
||||||
|
private Boolean unique;
|
||||||
|
private Integer minLength;
|
||||||
|
private Integer maxLength;
|
||||||
|
|
||||||
|
private String pattern;
|
||||||
|
|
||||||
|
@SerializedName("enum")
|
||||||
|
private List<String> enumeration;
|
||||||
|
|
||||||
|
public Boolean getRequired() {
|
||||||
|
return required;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequired(Boolean required) {
|
||||||
|
this.required = required;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getUnique() {
|
||||||
|
return unique;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUnique(Boolean unique) {
|
||||||
|
this.unique = unique;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getMinLength() {
|
||||||
|
return minLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinLength(Integer minLength) {
|
||||||
|
this.minLength = minLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getMaxLength() {
|
||||||
|
return maxLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxLength(Integer maxLength) {
|
||||||
|
this.maxLength = maxLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPattern() {
|
||||||
|
return pattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPattern(String pattern) {
|
||||||
|
this.pattern = pattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getEnumeration() {
|
||||||
|
return enumeration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnumeration(List<String> enumeration) {
|
||||||
|
this.enumeration = enumeration;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,9 +2,6 @@ package ninja.javafx.smartcsv.validation;
|
|||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abi
|
* @author abi
|
||||||
*/
|
*/
|
||||||
@@ -25,7 +22,9 @@ public class FieldConfiguration {
|
|||||||
private String description;
|
private String description;
|
||||||
private String format;
|
private String format;
|
||||||
private Object missingValue;
|
private Object missingValue;
|
||||||
private Map<String, Object> constraints;
|
private ConstraintsConfiguration constraints;
|
||||||
|
private String groovy;
|
||||||
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
@@ -75,11 +74,20 @@ public class FieldConfiguration {
|
|||||||
this.missingValue = missingValue;
|
this.missingValue = missingValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> getConstraints() {
|
public ConstraintsConfiguration getConstraints() {
|
||||||
return constraints;
|
return constraints;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConstraints(Map<String, Object> constraints) {
|
public void setConstraints(ConstraintsConfiguration constraints) {
|
||||||
this.constraints = constraints;
|
this.constraints = constraints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getGroovy() {
|
||||||
|
return groovy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroovy(String groovy) {
|
||||||
|
this.groovy = groovy;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,38 +182,41 @@ public class Validator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (column.getConstraints() != null) {
|
String groovy = column.getGroovy();
|
||||||
Boolean notEmptyRule = (Boolean)column.getConstraints().get("required");
|
|
||||||
if (notEmptyRule != null && notEmptyRule) {
|
|
||||||
add(column.getName(), new NotEmptyValidation());
|
|
||||||
}
|
|
||||||
|
|
||||||
Boolean uniqueRule = (Boolean)column.getConstraints().get("unique");
|
|
||||||
if (uniqueRule != null && uniqueRule) {
|
|
||||||
add(column.getName(), new UniqueValidation(columnValueProvider, column.getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer minLength = doubleToInteger((Double)column.getConstraints().get("minLength"));
|
|
||||||
if (minLength != null) {
|
|
||||||
add(column.getName(), new MinLengthValidation(minLength));
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer maxLength = doubleToInteger((Double)column.getConstraints().get("maxLength"));
|
|
||||||
if (maxLength != null) {
|
|
||||||
add(column.getName(), new MaxLengthValidation(maxLength));
|
|
||||||
}
|
|
||||||
|
|
||||||
String regexp = (String)column.getConstraints().get("pattern");
|
|
||||||
if (regexp != null && !regexp.trim().isEmpty()) {
|
|
||||||
add(column.getName(), new RegExpValidation(regexp));
|
|
||||||
}
|
|
||||||
|
|
||||||
String groovy = (String)column.getConstraints().get("groovy");
|
|
||||||
if (groovy != null && !groovy.trim().isEmpty()) {
|
if (groovy != null && !groovy.trim().isEmpty()) {
|
||||||
add(column.getName(), new GroovyValidation(groovy));
|
add(column.getName(), new GroovyValidation(groovy));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> valueOfRule = (List<String>)column.getConstraints().get("enum");
|
ConstraintsConfiguration constraints = column.getConstraints();
|
||||||
|
if (constraints != null) {
|
||||||
|
Boolean notEmptyRule = constraints.getRequired();
|
||||||
|
if (notEmptyRule != null && notEmptyRule) {
|
||||||
|
add(column.getName(), new NotEmptyValidation());
|
||||||
|
}
|
||||||
|
|
||||||
|
Boolean uniqueRule = constraints.getUnique();
|
||||||
|
if (uniqueRule != null && uniqueRule) {
|
||||||
|
add(column.getName(), new UniqueValidation(columnValueProvider, column.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer minLength = constraints.getMinLength();
|
||||||
|
if (minLength != null) {
|
||||||
|
add(column.getName(), new MinLengthValidation(minLength));
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer maxLength = constraints.getMaxLength();
|
||||||
|
if (maxLength != null) {
|
||||||
|
add(column.getName(), new MaxLengthValidation(maxLength));
|
||||||
|
}
|
||||||
|
|
||||||
|
String regexp = constraints.getPattern();
|
||||||
|
if (regexp != null && !regexp.trim().isEmpty()) {
|
||||||
|
add(column.getName(), new RegExpValidation(regexp));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
List<String> valueOfRule = constraints.getEnumeration();
|
||||||
if (valueOfRule != null && !valueOfRule.isEmpty()) {
|
if (valueOfRule != null && !valueOfRule.isEmpty()) {
|
||||||
add(column.getName(), new ValueOfValidation(valueOfRule));
|
add(column.getName(), new ValueOfValidation(valueOfRule));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
<?import javafx.scene.layout.RowConstraints?>
|
<?import javafx.scene.layout.RowConstraints?>
|
||||||
<?import org.fxmisc.richtext.CodeArea?>
|
<?import org.fxmisc.richtext.CodeArea?>
|
||||||
|
|
||||||
<GridPane hgap="20.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefWidth="800.0" vgap="6.0" xmlns="http://javafx.com/javafx/8.0.101" xmlns:fx="http://javafx.com/fxml/1">
|
<GridPane hgap="20.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
|
||||||
|
prefWidth="800.0" vgap="6.0" xmlns="http://javafx.com/javafx/8.0.101" xmlns:fx="http://javafx.com/fxml/1">
|
||||||
<columnConstraints>
|
<columnConstraints>
|
||||||
<ColumnConstraints halignment="LEFT" hgrow="NEVER"/>
|
<ColumnConstraints halignment="LEFT" hgrow="NEVER"/>
|
||||||
<ColumnConstraints halignment="LEFT" hgrow="ALWAYS"/>
|
<ColumnConstraints halignment="LEFT" hgrow="ALWAYS"/>
|
||||||
@@ -33,26 +34,38 @@
|
|||||||
</rowConstraints>
|
</rowConstraints>
|
||||||
<children>
|
<children>
|
||||||
<Label text="%validation.rule.type" GridPane.columnSpan="2" GridPane.halignment="LEFT" GridPane.hgrow="ALWAYS"/>
|
<Label text="%validation.rule.type" GridPane.columnSpan="2" GridPane.halignment="LEFT" GridPane.hgrow="ALWAYS"/>
|
||||||
<Label text="%validation.rule.format" GridPane.columnSpan="2" GridPane.halignment="LEFT" GridPane.hgrow="ALWAYS" GridPane.rowIndex="1" />
|
<Label text="%validation.rule.format" GridPane.columnSpan="2" GridPane.halignment="LEFT" GridPane.hgrow="ALWAYS"
|
||||||
<ComboBox fx:id="typeComboBox" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.halignment="LEFT" GridPane.hgrow="ALWAYS" />
|
GridPane.rowIndex="1"/>
|
||||||
<CheckBox fx:id="enableNotEmptyRule" mnemonicParsing="false" text="%validation.rule.label.not_empty" GridPane.rowIndex="3" />
|
<ComboBox fx:id="typeComboBox" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1"
|
||||||
<CheckBox fx:id="enableUniqueRule" mnemonicParsing="false" text="%validation.rule.label.unique" GridPane.columnIndex="2" GridPane.rowIndex="3" />
|
GridPane.columnSpan="3" GridPane.halignment="LEFT" GridPane.hgrow="ALWAYS"/>
|
||||||
<CheckBox fx:id="enableMinLengthRule" mnemonicParsing="false" text="%validation.rule.label.minlength" GridPane.rowIndex="4" />
|
<CheckBox fx:id="enableNotEmptyRule" mnemonicParsing="false" text="%validation.rule.label.not_empty"
|
||||||
|
GridPane.rowIndex="3"/>
|
||||||
|
<CheckBox fx:id="enableUniqueRule" mnemonicParsing="false" text="%validation.rule.label.unique"
|
||||||
|
GridPane.columnIndex="2" GridPane.rowIndex="3"/>
|
||||||
|
<CheckBox fx:id="enableMinLengthRule" mnemonicParsing="false" text="%validation.rule.label.minlength"
|
||||||
|
GridPane.rowIndex="4"/>
|
||||||
<Spinner fx:id="minLengthSpinner" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
|
<Spinner fx:id="minLengthSpinner" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
|
||||||
<CheckBox fx:id="enableMaxLengthRule" mnemonicParsing="false" text="%validation.rule.label.maxlength" GridPane.columnIndex="2" GridPane.rowIndex="4" />
|
<CheckBox fx:id="enableMaxLengthRule" mnemonicParsing="false" text="%validation.rule.label.maxlength"
|
||||||
|
GridPane.columnIndex="2" GridPane.rowIndex="4"/>
|
||||||
<Spinner fx:id="maxLengthSpinner" GridPane.columnIndex="3" GridPane.rowIndex="4"/>
|
<Spinner fx:id="maxLengthSpinner" GridPane.columnIndex="3" GridPane.rowIndex="4"/>
|
||||||
<CheckBox fx:id="enableRegexpRule" mnemonicParsing="false" text="%validation.rule.label.regexp" GridPane.rowIndex="5" />
|
<CheckBox fx:id="enableRegexpRule" mnemonicParsing="false" text="%validation.rule.label.regexp"
|
||||||
|
GridPane.rowIndex="5"/>
|
||||||
<TextField fx:id="regexpRuleTextField" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="5"/>
|
<TextField fx:id="regexpRuleTextField" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="5"/>
|
||||||
<CheckBox fx:id="enableValueOfRule" mnemonicParsing="false" text="%validation.rule.label.value_of" GridPane.rowIndex="6" />
|
<CheckBox fx:id="enableValueOfRule" mnemonicParsing="false" text="%validation.rule.label.value_of"
|
||||||
|
GridPane.rowIndex="6"/>
|
||||||
<TextField fx:id="valueOfRuleTextField" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="6"/>
|
<TextField fx:id="valueOfRuleTextField" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="6"/>
|
||||||
<CheckBox fx:id="enableGroovyRule" mnemonicParsing="false" text="%validation.rule.label.groovy" GridPane.rowIndex="7">
|
<CheckBox fx:id="enableGroovyRule" mnemonicParsing="false" text="%validation.rule.label.groovy"
|
||||||
|
GridPane.rowIndex="7">
|
||||||
<GridPane.margin>
|
<GridPane.margin>
|
||||||
<Insets top="8.0"/>
|
<Insets top="8.0"/>
|
||||||
</GridPane.margin></CheckBox>
|
</GridPane.margin>
|
||||||
<CodeArea fx:id="groovyRuleTextArea" minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="7">
|
</CheckBox>
|
||||||
|
<CodeArea fx:id="groovyRuleTextArea" minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0"
|
||||||
|
GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="7">
|
||||||
<GridPane.margin>
|
<GridPane.margin>
|
||||||
<Insets top="8.0"/>
|
<Insets top="8.0"/>
|
||||||
</GridPane.margin></CodeArea>
|
</GridPane.margin>
|
||||||
|
</CodeArea>
|
||||||
<Separator prefWidth="200.0" GridPane.columnSpan="4" GridPane.rowIndex="2"/>
|
<Separator prefWidth="200.0" GridPane.columnSpan="4" GridPane.rowIndex="2"/>
|
||||||
</children>
|
</children>
|
||||||
<padding>
|
<padding>
|
||||||
|
|||||||
Reference in New Issue
Block a user