editor should support new config ... first steps

This commit is contained in:
2016-09-01 22:05:31 +02:00
committed by Andreas Billmann
parent 6f635f5e75
commit 04a54da798
8 changed files with 109 additions and 132 deletions

View File

@@ -55,6 +55,7 @@ import java.util.regex.Pattern;
import static java.util.Arrays.asList; 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
@@ -110,9 +111,6 @@ public class ValidationEditorController extends FXMLController {
@FXML @FXML
private Spinner<Integer> maxLengthSpinner; private Spinner<Integer> maxLengthSpinner;
@FXML
private TextField dateformatRuleTextField;
@FXML @FXML
private TextField regexpRuleTextField; private TextField regexpRuleTextField;
@@ -131,9 +129,6 @@ public class ValidationEditorController extends FXMLController {
@FXML @FXML
private CheckBox enableMaxLengthRule; private CheckBox enableMaxLengthRule;
@FXML
private CheckBox enableDateRule;
@FXML @FXML
private CheckBox enableRegexpRule; private CheckBox enableRegexpRule;
@@ -167,7 +162,6 @@ public class ValidationEditorController extends FXMLController {
initSpinner(minLengthSpinner, enableMinLengthRule); initSpinner(minLengthSpinner, enableMinLengthRule);
initSpinner(maxLengthSpinner, enableMaxLengthRule); initSpinner(maxLengthSpinner, enableMaxLengthRule);
initTextInputControl(dateformatRuleTextField, enableDateRule);
initTextInputControl(regexpRuleTextField, enableRegexpRule); initTextInputControl(regexpRuleTextField, enableRegexpRule);
initTextInputControl(valueOfRuleTextField, enableValueOfRule); initTextInputControl(valueOfRuleTextField, enableValueOfRule);
initCodeAreaControl(groovyRuleTextArea, enableGroovyRule); initCodeAreaControl(groovyRuleTextArea, enableGroovyRule);
@@ -294,66 +288,45 @@ public class ValidationEditorController extends FXMLController {
private void updateForm() { private void updateForm() {
// updateCheckBox( updateCheckBox(
// validationConfiguration.getNotEmptyRuleFor(getSelectedColumn()), (Boolean)validationConfiguration.getFieldConfiguration(getSelectedColumn()).getConstraints().get("required"),
// enableNotEmptyRule enableNotEmptyRule
// ); );
//
// updateCheckBox( updateCheckBox(
// validationConfiguration.getIntegerRuleFor(getSelectedColumn()), (Boolean)validationConfiguration.getFieldConfiguration(getSelectedColumn()).getConstraints().get("unique"),
// enableIntegerRule enableUniqueRule
// ); );
//
// updateCheckBox( updateSpinner(
// validationConfiguration.getDoubleRuleFor(getSelectedColumn()), minLengthSpinner,
// enableDoubleRule doubleToInteger((Double)validationConfiguration.getFieldConfiguration(getSelectedColumn()).getConstraints().get("minLength")),
// ); enableMinLengthRule
// );
// updateCheckBox(
// validationConfiguration.getAlphanumericRuleFor(getSelectedColumn()), updateSpinner(
// enableAlphanumericRule maxLengthSpinner,
// ); doubleToInteger((Double)validationConfiguration.getFieldConfiguration(getSelectedColumn()).getConstraints().get("maxLength")),
// enableMaxLengthRule
// updateCheckBox( );
// validationConfiguration.getUniqueRuleFor(getSelectedColumn()),
// enableUniqueRule updateTextInputControl(
// ); regexpRuleTextField,
// (String)validationConfiguration.getFieldConfiguration(getSelectedColumn()).getConstraints().get("pattern"),
// updateSpinner( enableRegexpRule
// minLengthSpinner, );
// validationConfiguration.getMinLengthRuleFor(getSelectedColumn()),
// enableMinLengthRule updateTextInputControl(
// ); valueOfRuleTextField,
// (String)validationConfiguration.getFieldConfiguration(getSelectedColumn()).getConstraints().get("enum"),
// updateSpinner( enableValueOfRule
// maxLengthSpinner, );
// validationConfiguration.getMaxLengthRuleFor(getSelectedColumn()),
// enableMaxLengthRule updateCodeAreaControl(
// ); groovyRuleTextArea,
// (String)validationConfiguration.getFieldConfiguration(getSelectedColumn()).getConstraints().get("groovy"),
// updateTextInputControl( enableGroovyRule
// dateformatRuleTextField, );
// validationConfiguration.getDateRuleFor(getSelectedColumn()),
// enableDateRule
// );
//
// updateTextInputControl(
// regexpRuleTextField,
// validationConfiguration.getRegexpRuleFor(getSelectedColumn()),
// enableRegexpRule
// );
//
// updateTextInputControl(
// valueOfRuleTextField,
// validationConfiguration.getValueOfRuleFor(getSelectedColumn()),
// enableValueOfRule
// );
//
// updateCodeAreaControl(
// groovyRuleTextArea,
// validationConfiguration.getGroovyRuleFor(getSelectedColumn()),
// enableGroovyRule
// );
} }
private void updateCheckBox(Boolean value, CheckBox ruleEnabled) { private void updateCheckBox(Boolean value, CheckBox ruleEnabled) {

View File

@@ -47,6 +47,15 @@ public class ValidationConfiguration {
this.fieldConfigurations = fieldConfigurations; this.fieldConfigurations = fieldConfigurations;
} }
public FieldConfiguration getFieldConfiguration(String column) {
for (FieldConfiguration fieldConfiguration: fieldConfigurations) {
if (fieldConfiguration.getName().equals(column)) {
return fieldConfiguration;
}
}
return null;
}
public String[] headerNames() { public String[] headerNames() {
if (fieldConfigurations != null) { if (fieldConfigurations != null) {
List<String> headerNames = new ArrayList<>(); List<String> headerNames = new ArrayList<>();

View File

@@ -3,7 +3,7 @@ package ninja.javafx.smartcsv.validation;
/** /**
* @author abi * @author abi
*/ */
public class DateFormatHelper { public class ValidationFormatHelper {
public static String dateFormat(String format, String defaultFormat) { public static String dateFormat(String format, String defaultFormat) {
@@ -35,4 +35,9 @@ public class DateFormatHelper {
} }
return defaultFormat; return defaultFormat;
} }
public static Integer doubleToInteger(Double value) {
if (value == null) return null;
return (int)Math.round(value);
}
} }

View File

@@ -32,7 +32,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static ninja.javafx.smartcsv.validation.DateFormatHelper.dateFormat; import static ninja.javafx.smartcsv.validation.ValidationFormatHelper.dateFormat;
import static ninja.javafx.smartcsv.validation.ValidationFormatHelper.doubleToInteger;
/** /**
* This class checks all the validations defined in the * This class checks all the validations defined in the
@@ -252,8 +253,5 @@ public class Validator {
return result; return result;
} }
private Integer doubleToInteger(Double value) {
if (value == null) return null;
return (int)Math.round(value);
}
} }

View File

@@ -1,16 +1,16 @@
.list-view { .table-view .list-view {
-fx-background-color: -fx-background; -fx-background-color: -fx-background;
-fx-padding: 1; -fx-padding: 1;
} }
.list-cell { .table-view .list-cell {
-fx-padding: 1.0em 1.0em 1.0em 1.0em; -fx-padding: 1.0em 1.0em 1.0em 1.0em;
} }
.list-cell:odd { .table-view .list-cell:odd {
-fx-background: -fx-control-inner-background-alt; -fx-background: -fx-control-inner-background-alt;
} }
.list-cell:even { .table-view .list-cell:even {
-fx-background: -fx-control-inner-background; -fx-background: -fx-control-inner-background;
} }

View File

@@ -74,6 +74,8 @@ validation.rules.active = active
validation.rules.name = rule validation.rules.name = rule
validation.rules.value = value validation.rules.value = value
validation.rule.label.unique = Unique in column validation.rule.label.unique = Unique in column
validation.rule.format = Format:
validation.rule.type = Type:
dialog.validation.rules.title = Validation rules dialog.validation.rules.title = Validation rules
dialog.validation.rules.header = Validation rules of column "{0}" dialog.validation.rules.header = Validation rules of column "{0}"

View File

@@ -83,6 +83,8 @@ validation.rules.active = Aktiv
validation.rules.name = Regel validation.rules.name = Regel
validation.rules.value = Wert validation.rules.value = Wert
validation.rule.label.unique = Einmalig in Spalte validation.rule.label.unique = Einmalig in Spalte
validation.rule.format = Format:
validation.rule.type = Typ:
dialog.validation.rules.title = Pr\u00fcfregeln dialog.validation.rules.title = Pr\u00fcfregeln
dialog.validation.rules.header = Pr\u00fcfregeln f\u00fcr die Spalte "{0}" dialog.validation.rules.header = Pr\u00fcfregeln f\u00fcr die Spalte "{0}"

View File

@@ -5,6 +5,7 @@
<?import javafx.scene.control.CheckBox?> <?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.ComboBox?> <?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.Spinner?> <?import javafx.scene.control.Spinner?>
<?import javafx.scene.control.TextField?> <?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?> <?import javafx.scene.layout.ColumnConstraints?>
@@ -12,64 +13,51 @@
<?import javafx.scene.layout.RowConstraints?> <?import javafx.scene.layout.RowConstraints?>
<?import org.fxmisc.richtext.CodeArea?> <?import org.fxmisc.richtext.CodeArea?>
<GridPane hgap="10.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefWidth="600.0" vgap="10.0" xmlns="http://javafx.com/javafx/8.0.76-ea" 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="CENTER" hgrow="NEVER" maxWidth="50.0" prefWidth="50.0" /> <ColumnConstraints halignment="LEFT" hgrow="NEVER" />
<ColumnConstraints hgrow="NEVER" /> <ColumnConstraints halignment="LEFT" hgrow="ALWAYS" />
<ColumnConstraints hgrow="ALWAYS" /> <ColumnConstraints halignment="LEFT" hgrow="NEVER" />
</columnConstraints> <ColumnConstraints halignment="LEFT" hgrow="ALWAYS" />
<rowConstraints> </columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" valignment="CENTER" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" valignment="CENTER" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" valignment="CENTER" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" valignment="TOP" vgrow="ALWAYS" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> </rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <children>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <Label text="%validation.rule.type" GridPane.columnSpan="2" GridPane.halignment="LEFT" GridPane.hgrow="ALWAYS" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <Label text="%validation.rule.format" GridPane.columnSpan="2" GridPane.halignment="LEFT" GridPane.hgrow="ALWAYS" GridPane.rowIndex="1" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <ComboBox fx:id="typeComboBox" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.halignment="LEFT" GridPane.hgrow="ALWAYS" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <CheckBox fx:id="enableNotEmptyRule" mnemonicParsing="false" text="%validation.rule.label.not_empty" GridPane.rowIndex="3" />
</rowConstraints> <CheckBox fx:id="enableUniqueRule" mnemonicParsing="false" text="%validation.rule.label.unique" GridPane.columnIndex="2" GridPane.rowIndex="3" />
<children> <CheckBox fx:id="enableMinLengthRule" mnemonicParsing="false" text="%validation.rule.label.minlength" GridPane.rowIndex="4" />
<Label text="%validation.rule.label.not_empty" GridPane.columnIndex="1" GridPane.rowIndex="4" /> <Spinner fx:id="minLengthSpinner" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Label text="%validation.rule.label.minlength" GridPane.columnIndex="1" GridPane.rowIndex="6" /> <CheckBox fx:id="enableMaxLengthRule" mnemonicParsing="false" text="%validation.rule.label.maxlength" GridPane.columnIndex="2" GridPane.rowIndex="4" />
<Label text="%validation.rule.label.maxlength" GridPane.columnIndex="1" GridPane.rowIndex="7" /> <Spinner fx:id="maxLengthSpinner" GridPane.columnIndex="3" GridPane.rowIndex="4" />
<Label text="%validation.rule.label.dateformat" GridPane.columnIndex="1" GridPane.rowIndex="8" /> <CheckBox fx:id="enableRegexpRule" mnemonicParsing="false" text="%validation.rule.label.regexp" GridPane.rowIndex="5" />
<Label text="%validation.rule.label.regexp" GridPane.columnIndex="1" GridPane.rowIndex="9" /> <TextField fx:id="regexpRuleTextField" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="5" />
<Label text="%validation.rule.label.value_of" GridPane.columnIndex="1" GridPane.rowIndex="10" /> <CheckBox fx:id="enableValueOfRule" mnemonicParsing="false" text="%validation.rule.label.value_of" GridPane.rowIndex="6" />
<Label text="%validation.rule.label.groovy" GridPane.columnIndex="1" GridPane.rowIndex="11" /> <TextField fx:id="valueOfRuleTextField" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="6" />
<Label text="%validation.rule.label.unique" GridPane.columnIndex="1" GridPane.rowIndex="5" /> <CheckBox fx:id="enableGroovyRule" mnemonicParsing="false" text="%validation.rule.label.groovy" GridPane.rowIndex="7">
<CheckBox fx:id="enableNotEmptyRule" mnemonicParsing="false" GridPane.rowIndex="4" />
<CheckBox fx:id="enableUniqueRule" mnemonicParsing="false" GridPane.rowIndex="5" />
<CheckBox fx:id="enableMinLengthRule" mnemonicParsing="false" GridPane.rowIndex="6" />
<Spinner fx:id="minLengthSpinner" GridPane.columnIndex="2" GridPane.rowIndex="6" />
<CheckBox fx:id="enableMaxLengthRule" mnemonicParsing="false" GridPane.rowIndex="7" />
<Spinner fx:id="maxLengthSpinner" GridPane.columnIndex="2" GridPane.rowIndex="7" />
<CheckBox fx:id="enableDateRule" mnemonicParsing="false" GridPane.rowIndex="8" />
<TextField fx:id="dateformatRuleTextField" GridPane.columnIndex="2" GridPane.rowIndex="8" />
<CheckBox fx:id="enableRegexpRule" mnemonicParsing="false" GridPane.rowIndex="9" />
<TextField fx:id="regexpRuleTextField" GridPane.columnIndex="2" GridPane.rowIndex="9" />
<CheckBox fx:id="enableValueOfRule" mnemonicParsing="false" GridPane.rowIndex="10" />
<TextField fx:id="valueOfRuleTextField" GridPane.columnIndex="2" GridPane.rowIndex="10" />
<CheckBox fx:id="enableGroovyRule" mnemonicParsing="false" GridPane.rowIndex="11" />
<CodeArea fx:id="groovyRuleTextArea" prefHeight="300.0" prefWidth="200.0" GridPane.columnIndex="2" GridPane.rowIndex="11" GridPane.rowSpan="2" />
<Label style="-fx-font-weight: bold;" text="%validation.rules.active" GridPane.rowIndex="3" />
<Label style="-fx-font-weight: bold;" text="%validation.rules.name" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label style="-fx-font-weight: bold;" text="%validation.rules.value" GridPane.columnIndex="2" GridPane.rowIndex="3" />
<Label text="Label" GridPane.columnSpan="2" GridPane.halignment="LEFT" GridPane.hgrow="ALWAYS" GridPane.rowIndex="1" />
<Label text="Label" GridPane.columnSpan="2" GridPane.halignment="LEFT" GridPane.hgrow="ALWAYS" />
<ComboBox fx:id="typeComboBox" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.columnIndex="2" GridPane.halignment="LEFT" GridPane.hgrow="ALWAYS" GridPane.vgrow="NEVER">
<GridPane.margin> <GridPane.margin>
<Insets /> <Insets top="8.0" />
</GridPane.margin></ComboBox> </GridPane.margin></CheckBox>
<CodeArea fx:id="groovyRuleTextArea" minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="7">
</children> <GridPane.margin>
<padding> <Insets top="8.0" />
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" /> </GridPane.margin></CodeArea>
</padding> <Separator prefWidth="200.0" GridPane.columnSpan="4" GridPane.rowIndex="2" />
</children>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<stylesheets> <stylesheets>
<URL value="@/ninja/javafx/smartcsv/fx/smartcsv.css" /> <URL value="@/ninja/javafx/smartcsv/fx/smartcsv.css" />
</stylesheets> </stylesheets>