mirror of
https://github.com/frosch95/SmartCSV.fx.git
synced 2026-04-11 13:38:23 +02:00
handle defaults
This commit is contained in:
@@ -289,15 +289,13 @@ public class ValidationEditorController extends FXMLController {
|
|||||||
case STRING:
|
case STRING:
|
||||||
updateFormatComboBox(getStringFormats());
|
updateFormatComboBox(getStringFormats());
|
||||||
break;
|
break;
|
||||||
case NUMBER:
|
|
||||||
updateFormatComboBox(getNumberFormats());
|
|
||||||
break;
|
|
||||||
case DATE:
|
case DATE:
|
||||||
case DATETIME:
|
case DATETIME:
|
||||||
case TIME:
|
case TIME:
|
||||||
updateFormatComboBox(getDateFormats());
|
updateFormatComboBox(getDateFormats());
|
||||||
break;
|
break;
|
||||||
case INTEGER:
|
case INTEGER:
|
||||||
|
case NUMBER:
|
||||||
default:
|
default:
|
||||||
// format: no options
|
// format: no options
|
||||||
formatComboBox.setDisable(true);
|
formatComboBox.setDisable(true);
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ package ninja.javafx.smartcsv.validation;
|
|||||||
|
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import ninja.javafx.smartcsv.FileReader;
|
import ninja.javafx.smartcsv.FileReader;
|
||||||
|
import ninja.javafx.smartcsv.validation.configuration.FieldConfiguration;
|
||||||
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
|
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -43,6 +44,30 @@ public class ValidationFileReader implements FileReader<ValidationConfiguration>
|
|||||||
@Override
|
@Override
|
||||||
public void read(File file) throws IOException {
|
public void read(File file) throws IOException {
|
||||||
config = new GsonBuilder().create().fromJson(new java.io.FileReader(file), ValidationConfiguration.class);
|
config = new GsonBuilder().create().fromJson(new java.io.FileReader(file), ValidationConfiguration.class);
|
||||||
|
setDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setDefaults() {
|
||||||
|
for (FieldConfiguration fieldConfiguration: config.getFieldConfigurations()) {
|
||||||
|
if (fieldConfiguration.getType() == null) {
|
||||||
|
fieldConfiguration.setType(FieldConfiguration.Type.STRING);
|
||||||
|
}
|
||||||
|
if (fieldConfiguration.getType() == FieldConfiguration.Type.DATE) {
|
||||||
|
if (fieldConfiguration.getFormat() == null) {
|
||||||
|
fieldConfiguration.setFormat("yyyy-MM-dd");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fieldConfiguration.getType() == FieldConfiguration.Type.DATETIME) {
|
||||||
|
if (fieldConfiguration.getFormat() == null) {
|
||||||
|
fieldConfiguration.setFormat("yyyy-MM-ddThh:mm:ssZ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fieldConfiguration.getType() == FieldConfiguration.Type.TIME) {
|
||||||
|
if (fieldConfiguration.getFormat() == null) {
|
||||||
|
fieldConfiguration.setFormat("hh:mm:ss");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValidationConfiguration getContent() {
|
public ValidationConfiguration getContent() {
|
||||||
|
|||||||
@@ -40,19 +40,6 @@ public class FieldConfiguration {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum NumberFormat {
|
|
||||||
@SerializedName("decimalChar") DECIMAL_CHAR,
|
|
||||||
@SerializedName("groupChar") GROUP_CHAR,
|
|
||||||
@SerializedName("currency") CURRENCY
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getNumberFormats() {
|
|
||||||
return Stream.of(NumberFormat.values())
|
|
||||||
.map(NumberFormat::name)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public enum DateFormat {
|
public enum DateFormat {
|
||||||
@SerializedName("default") DEFAULT,
|
@SerializedName("default") DEFAULT,
|
||||||
@SerializedName("any") ANY,
|
@SerializedName("any") ANY,
|
||||||
|
|||||||
Reference in New Issue
Block a user