50 Commits
0.6 ... 0.9.3

Author SHA1 Message Date
Andreas Billmann
cf9203549b Merge pull request #17 from aoetk/fileencoding
Add the setting changes encoding for CSV file to the preference dialog
2019-10-22 22:36:26 +02:00
AOE Takashi
02b102cfb2 Add the setting changes encoding for CSV file to the preference dialog
(cherry picked from commit 11210b6d8b4584621ef02e7356854ffa9f7f2647)
2019-10-19 23:16:09 +09:00
8e0e1c41c3 update the README.md with the 0.9.2 download link 2019-10-03 21:18:16 +02:00
3ce9ae8edd fixed the main javafx application problem 2019-10-03 21:08:29 +02:00
7c12b7506f upgrade to javafx 13 2019-10-03 18:03:01 +02:00
6fc62006fa upgrade to javafx 12 2019-07-08 20:11:50 +02:00
fdc4f99fd5 updated dependencies 2018-07-08 14:01:13 +02:00
e29d60b9b8 upgraded gradle wrapper 2018-07-08 13:42:43 +02:00
0a4e86c160 fixed the markdown 2018-04-22 09:27:20 +02:00
c07dde8e19 updated the version number and link to the distribution 2018-04-22 09:25:50 +02:00
9b0e3707b7 updated libs and removed fxlauncher as it is not used by customers 2018-04-22 09:18:01 +02:00
a1f6c24bae updatet libraries to the newest versions 2017-03-22 12:00:35 +01:00
c1a671504e added fxlauncher to about dialog 2016-10-06 21:27:09 +02:00
7c3f140491 Merge remote-tracking branch 'remotes/origin/fxlauncher' 2016-10-06 21:07:42 +02:00
16373a033a change updating text in fxlauncher 2016-10-06 21:07:01 +02:00
e9e71b5474 gradle task to rename the fxlauncher.jar and launcher without own ui 2016-10-06 15:33:00 +02:00
48c657b648 fxlauncher without customization 2016-10-06 14:01:52 +02:00
8bd90b47e1 renamed license file 2016-10-06 07:09:50 +02:00
44f36759a6 thx for contribution: Hasan Kara 2016-10-05 15:43:36 +02:00
Andreas Billmann
326e4d954b Merge pull request #14 from haisi/master
Fix typo
2016-10-05 15:35:56 +02:00
Hasan Kara
96446e4e75 Fix typo 2016-10-05 14:51:05 +02:00
Andreas Billmann
5eaf021632 fixed broken tests 2016-09-23 11:14:45 +02:00
Andreas Billmann
ef376d6c61 set constraints when created 2016-09-22 22:09:56 +02:00
Andreas Billmann
2676b523d3 clear groovy field if there is some text in it 2016-09-22 21:49:30 +02:00
Andreas Billmann
7e34ff8c59 fixed NPE when string has no format 2016-09-22 21:35:40 +02:00
Andreas Billmann
a37a84bd09 Merge remote-tracking branch 'remotes/origin/json_table_schema' 2016-09-22 20:48:57 +02:00
Andreas Billmann
5100c668ab version 0.8 based on JSON Table Schema 2016-09-22 20:46:30 +02:00
Andreas Billmann
90bda028ec finding enum based on external value should use external value as compare value 2016-09-18 15:26:59 +02:00
Andreas Billmann
5e31f834ac fixed the imports of the new validation classes 2016-09-18 15:18:48 +02:00
Andreas Billmann
d689423c61 added 2016 to the license text 2016-09-18 14:58:38 +02:00
Andreas Billmann
9e8d71ca1d implemented string format validations 2016-09-18 14:58:37 +02:00
Andreas Billmann
70855e614a the editor can handle the support subset of JSON Table Schema 2016-09-18 14:58:37 +02:00
4354afdf1d handle defaults 2016-09-18 14:58:36 +02:00
4002219dfe reorganize validation package 2016-09-18 14:58:35 +02:00
7723906935 write values back to config 2016-09-18 14:58:34 +02:00
5694273c51 read constraints into an object instead of some map structure and change form init of validation editor 2016-09-18 14:58:33 +02:00
04a54da798 editor should support new config ... first steps 2016-09-18 14:58:32 +02:00
6f635f5e75 ignore log file 2016-09-18 14:58:31 +02:00
742f129ea9 change editor to the new config
The editor should handle the new configuration
2016-09-18 14:58:31 +02:00
0c391e292e first quick implementation of to support json table schema 2016-09-18 14:58:30 +02:00
cd0ca0ed11 set preferences on csv file reader and writer after load and changing through dialog 2016-09-14 19:23:36 +02:00
e799f0ac45 min and max value spinner are dependent 2016-08-11 13:25:15 +02:00
3664a4e8a7 the most senseless combination of rules are not possible any more 2016-08-11 13:11:23 +02:00
e87eec2162 no need for 2 checkboxes when it is a boolean rule 2016-08-11 12:55:09 +02:00
3adfd566bc error export implemented and message on error side bar includes column name 2016-08-10 23:45:47 +02:00
e6742a4e30 error export implemented and message on error side bar includes column name 2016-08-10 23:41:47 +02:00
7472c66823 fixed uniqueness validation and renamed the abstract class when empty values are valid 2016-08-09 21:17:29 +02:00
c7873ef0ba unique validation has to work on the model to have the correct snapshot of the data 2016-08-09 20:59:29 +02:00
b79a20201e removed the special treatment of NotEmptyValidation 2016-08-09 20:59:29 +02:00
Andreas Billmann
3ebf78805c Update README.md 2016-08-08 17:23:02 +02:00
84 changed files with 2061 additions and 764 deletions

1
.gitignore vendored
View File

@@ -74,3 +74,4 @@ crashlytics.properties
crashlytics-build.properties
smartcsv.log

View File

@@ -1,7 +1,7 @@
The MIT License (MIT)
------------------------------------------------------------------------------------------------------------------------
Copyright (c) 2015 Andreas Billmann <andreas.billmann@javafx.ninja>
Copyright (c) 2015-2019 Andreas Billmann <andreas.billmann@javafx.ninja>

View File

@@ -1,29 +1,29 @@
# SmartCSV.fx
##Description
A simple JavaFX application to load, save and edit a CSV file and provide a JSON configuration for columns to check the values in the columns.
## Description
A simple JavaFX application to load, save and edit a CSV file and provide a [JSON Table Schema](http://specs.frictionlessdata.io/json-table-schema/) for columns to check the values in the columns.
##Motivation
## Motivation
At work I have the need to fix wrong CSV files from customers. It is hard to find the errors and fix them in a texteditor,
even in a "normal" CSV editor. So I decided to write this simple JavaFX application.
##Video
## Video
[![short video about the application](http://img.youtube.com/vi/eUh_WLx1OwI/0.jpg)](https://youtu.be/eUh_WLx1OwI)
##Links
## Links
[GitHub Page](http://frosch95.github.io/SmartCSV.fx/)
[Wiki & Documentation](https://github.com/frosch95/SmartCSV.fx/wiki)
binary distribution of the [latest release (0.5)](https://drive.google.com/file/d/0BwY9gBUvn5qmejllOTRwbEJYdDA/view?usp=sharing)
binary distribution of the [latest release (0.9.2)](https://github.com/frosch95/SmartCSV.fx/releases/download/0.9.2/SmartCSV.fx-0.9.2-SNAPSHOT.zip)
##Talks
## Talks
[Introduction](http://javafx.ninja/talks/introduction/)
##License
###The MIT License (MIT)
## License
### The MIT License (MIT)
Copyright (c) 2015 Andreas Billmann <andreas.billmann@javafx.ninja>
Copyright (c) 2015-2019 Andreas Billmann <andreas.billmann@javafx.ninja>

View File

@@ -1,38 +1,39 @@
group 'ninja.javafx'
version '0.6-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin:'application'
apply plugin: 'idea'
sourceCompatibility = 1.8
mainClassName = 'ninja.javafx.smartcsv.fx.SmartCSV'
plugins {
id 'idea'
id 'java'
id 'groovy'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
repositories {
mavenCentral()
jcenter()
}
javafx {
version = "13"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3'
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.4.7'
compile group: 'org.springframework', name:'spring-context', version: '4.3.1.RELEASE'
compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '3.0.0-beta-3'
compile group: 'org.springframework', name:'spring-context', version: '5.2.0.RELEASE'
compile group: 'net.sf.supercsv', name: 'super-csv', version: '2.4.0'
compile group: 'commons-validator', name: 'commons-validator', version: '1.5.1'
compile group: 'de.jensd', name: 'fontawesomefx-commons', version: '8.12'
compile group: 'de.jensd', name: 'fontawesomefx-fontawesome', version: '4.6.3'
compile group: 'de.jensd', name: 'fontawesomefx-materialdesignfont', version: '1.6.50'
compile group: 'de.jensd', name: 'fontawesomefx-materialicons', version: '2.2.0'
compile group: 'org.controlsfx', name: 'controlsfx', version: '8.40.11'
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.6.2'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.6.2'
compile group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.6.10'
compile group: 'commons-validator', name: 'commons-validator', version: '1.6'
compile group: 'de.jensd', name: 'fontawesomefx-commons', version: '11.0'
compile group: 'de.jensd', name: 'fontawesomefx-fontawesome', version: '4.7.0-11'
compile group: 'de.jensd', name: 'fontawesomefx-materialdesignfont', version: '1.7.22-11'
compile group: 'de.jensd', name: 'fontawesomefx-materialicons', version: '2.2.0-11'
compile group: 'org.controlsfx', name: 'controlsfx', version: '11.0.0'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.0'
compile group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.10.2'
}
task wrapper(type: Wrapper) {
gradleVersion = '2.14.1' //version required
}
group 'ninja.javafx'
version '0.9.2-SNAPSHOT'
mainClassName = 'ninja.javafx.smartcsv.Main'

Binary file not shown.

View File

@@ -1,6 +1,5 @@
#Sat Jul 23 09:35:51 CEST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip

100
gradlew vendored
View File

@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
##############################################################################
##
@@ -6,42 +6,6 @@
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
@@ -60,6 +24,46 @@ cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
@@ -85,7 +89,7 @@ location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
@@ -150,11 +154,19 @@ if $cygwin ; then
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
APP_ARGS=$(save "$@")
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"

12
gradlew.bat vendored
View File

@@ -8,14 +8,14 @@
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
@@ -49,7 +49,6 @@ goto fail
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
@@ -60,11 +59,6 @@ set _SKIP=2
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -0,0 +1,10 @@
package ninja.javafx.smartcsv;
import ninja.javafx.smartcsv.fx.SmartCSV;
public class Main {
public static void main(String[] args) {
// workaround for module problem
SmartCSV.main(args);
}
}

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -35,6 +35,8 @@ public class CSVConfigurable {
protected CsvPreference csvPreference;
protected String fileEncoding;
public CSVConfigurable() {
csvPreference = CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE;
}
@@ -42,4 +44,9 @@ public class CSVConfigurable {
public void setCsvPreference(CsvPreference csvPreference) {
this.csvPreference = csvPreference;
}
public void setFileEncoding(String fileEncoding) {
this.fileEncoding = fileEncoding;
}
}

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -34,6 +34,7 @@ import org.supercsv.io.ICsvMapReader;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Map;
/**
@@ -48,7 +49,8 @@ public class CSVFileReader extends CSVConfigurable implements FileReader<CSVMode
ICsvMapReader mapReader = null;
try {
mapReader = new CsvMapReader(new java.io.FileReader(file.getAbsoluteFile()), csvPreference);
mapReader = new CsvMapReader(new java.io.FileReader(file.getAbsoluteFile(), Charset.forName(fileEncoding)),
csvPreference);
model = new CSVModel();
// the header columns are used as the keys to the Map

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -34,6 +34,7 @@ import org.supercsv.io.ICsvMapWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Map;
import static java.util.stream.Collectors.toMap;
@@ -53,7 +54,8 @@ public class CSVFileWriter extends CSVConfigurable implements ninja.javafx.smart
public void write(File filename) throws IOException {
ICsvMapWriter mapWriter = null;
try {
mapWriter = new CsvMapWriter(new FileWriter(filename.getAbsolutePath()), csvPreference);
mapWriter = new CsvMapWriter(new FileWriter(filename.getAbsolutePath(), Charset.forName(fileEncoding)),
csvPreference);
mapWriter.writeHeader(model.getHeader());
for(CSVRow row: model.getRows()) {

View File

@@ -0,0 +1,71 @@
package ninja.javafx.smartcsv.export;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import ninja.javafx.smartcsv.fx.table.model.CSVModel;
import ninja.javafx.smartcsv.validation.ValidationError;
import java.io.File;
import java.io.StringWriter;
import java.nio.file.Files;
import java.util.ResourceBundle;
import static java.text.MessageFormat.format;
import static ninja.javafx.smartcsv.fx.util.I18nValidationUtil.getI18nValidatioMessage;
/**
* this class exports the error messages into a log file
*/
@org.springframework.stereotype.Service
public class ErrorExport extends Service {
private CSVModel model;
private File file;
private ResourceBundle resourceBundle;
private String csvFilename;
public void setCsvFilename(String csvFilename) {
this.csvFilename = csvFilename;
}
public void setResourceBundle(ResourceBundle resourceBundle) {
this.resourceBundle = resourceBundle;
}
public void setModel(CSVModel model) {
this.model = model;
}
public void setFile(File file) {
this.file = file;
}
@Override
protected Task createTask() {
return new Task() {
@Override
protected Void call() throws Exception {
try {
StringWriter log = new StringWriter();
log.append(
format(resourceBundle.getString("log.header.message"),
csvFilename,
Integer.toString(model.getValidationError().size()))).append("\n\n");
model.getValidationError().forEach(error ->
log.append(
format(resourceBundle.getString("log.message"),
error.getLineNumber().toString(),
error.getColumn(),
getI18nValidatioMessage(resourceBundle, error))).append("\n")
);
Files.write(file.toPath(), log.toString().getBytes());
} catch (Throwable ex) {
ex.printStackTrace();
}
return null;
}
};
}
}

View File

@@ -11,7 +11,7 @@ import java.io.File;
import java.io.IOException;
/**
* This class stores files and there state
* This class stores files and their state
* @author abi
*/
public class FileStorage<E> {
@@ -26,7 +26,7 @@ public class FileStorage<E> {
private BooleanProperty fileChanged = new SimpleBooleanProperty(true);
private ObjectProperty<File> file = new SimpleObjectProperty<>();
private ObjectProperty<E> content = new SimpleObjectProperty<E>();
private ObjectProperty<E> content = new SimpleObjectProperty<>();
public boolean isFileChanged() {
return fileChanged.get();

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +26,7 @@
package ninja.javafx.smartcsv.fx;
import javafx.beans.binding.Bindings;
import javafx.collections.ListChangeListener;
import javafx.collections.WeakListChangeListener;
import javafx.concurrent.WorkerStateEvent;
@@ -39,6 +40,7 @@ import javafx.scene.layout.BorderPane;
import javafx.stage.FileChooser;
import ninja.javafx.smartcsv.csv.CSVFileReader;
import ninja.javafx.smartcsv.csv.CSVFileWriter;
import ninja.javafx.smartcsv.export.ErrorExport;
import ninja.javafx.smartcsv.files.FileStorage;
import ninja.javafx.smartcsv.fx.about.AboutController;
import ninja.javafx.smartcsv.fx.list.ErrorSideBar;
@@ -52,9 +54,8 @@ import ninja.javafx.smartcsv.fx.table.model.CSVValue;
import ninja.javafx.smartcsv.fx.util.LoadFileService;
import ninja.javafx.smartcsv.fx.util.SaveFileService;
import ninja.javafx.smartcsv.fx.validation.ValidationEditorController;
import ninja.javafx.smartcsv.preferences.PreferencesFileReader;
import ninja.javafx.smartcsv.preferences.PreferencesFileWriter;
import ninja.javafx.smartcsv.validation.ValidationConfiguration;
import ninja.javafx.smartcsv.preferences.*;
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
import ninja.javafx.smartcsv.validation.ValidationError;
import ninja.javafx.smartcsv.validation.ValidationFileReader;
import ninja.javafx.smartcsv.validation.ValidationFileWriter;
@@ -66,6 +67,7 @@ import org.supercsv.prefs.CsvPreference;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.Optional;
import java.util.ResourceBundle;
@@ -91,10 +93,20 @@ public class SmartCSVController extends FXMLController {
".SmartCSV.fx" +
File.separator + "" +
"preferences.json");
private static final File ENCODING_FILE = new File(System.getProperty("user.home") +
File.separator +
".SmartCSV.fx" +
File.separator +
"encoding.json");
public static final String CSV_FILTER_TEXT = "CSV files (*.csv)";
public static final String CSV_FILTER_EXTENSION = "*.csv";
public static final String JSON_FILTER_TEXT = "JSON files (*.json)";
public static final String JSON_FILTER_EXTENSION = "*.json";
public static final String EXPORT_LOG_FILTER_TEXT = "Error log files (*.log)";
public static final String EXPORT_LOG_FILTER_EXTENSION = "*.log";
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// injections
@@ -115,6 +127,9 @@ public class SmartCSVController extends FXMLController {
@Autowired
private SaveFileService saveFileService;
@Autowired
private ErrorExport errorExport;
@FXML
private BorderPane applicationPane;
@@ -157,6 +172,9 @@ public class SmartCSVController extends FXMLController {
@FXML
private MenuItem gotoLineMenuItem;
@FXML
private MenuItem exportMenuItem;
@FXML
private Button saveButton;
@@ -181,6 +199,9 @@ public class SmartCSVController extends FXMLController {
@FXML
private Button addRowButton;
@FXML
private Button exportButton;
@FXML
private Label currentLineNumber;
@@ -193,10 +214,13 @@ public class SmartCSVController extends FXMLController {
private TableView<CSVRow> tableView;
private ErrorSideBar errorSideBar;
private ResourceBundle resourceBundle;
private CSVFileReader csvFileReader = new CSVFileReader();
private CSVFileWriter csvFileWriter = new CSVFileWriter();
private FileStorage<CSVModel> currentCsvFile = new FileStorage<>(new CSVFileReader(), new CSVFileWriter());
private FileStorage<CSVModel> currentCsvFile = new FileStorage<>(csvFileReader, csvFileWriter);
private FileStorage<ValidationConfiguration> currentConfigFile = new FileStorage<>(new ValidationFileReader(), new ValidationFileWriter());
private FileStorage<CsvPreference> csvPreferenceFile = new FileStorage<>(new PreferencesFileReader(), new PreferencesFileWriter());
private FileStorage<String> fileEncodingFile = new FileStorage<>(new EncodingFileReader(), new EncodingFileWriter());
private ListChangeListener<ValidationError> errorListListener = c -> tableView.refresh();
private WeakListChangeListener<ValidationError> weakErrorListListener = new WeakListChangeListener<>(errorListListener);
@@ -222,10 +246,25 @@ public class SmartCSVController extends FXMLController {
bindConfigFileName();
csvPreferenceFile.setFile(PREFERENCES_FILE);
fileEncodingFile.setFile(ENCODING_FILE);
loadCsvPreferencesFromFile();
}
private void loadEncodingFromFile() {
if (fileEncodingFile.getFile().exists()) {
useLoadFileService(fileEncodingFile, event -> setFileEncoding(fileEncodingFile.getContent()));
} else {
setFileEncoding(Charset.defaultCharset().name());
}
}
private void setFileEncoding(String content) {
preferencesController.setFileEncoding(content);
csvFileReader.setFileEncoding(content);
csvFileWriter.setFileEncoding(content);
}
private void setupErrorSideBar(ResourceBundle resourceBundle) {
errorSideBar = new ErrorSideBar(resourceBundle);
errorSideBar.selectedValidationErrorProperty().addListener((observable, oldValue, newValue) -> {
@@ -329,8 +368,29 @@ public class SmartCSVController extends FXMLController {
CsvPreference csvPreference = preferencesController.getCsvPreference();
setCsvPreference(csvPreference);
saveCsvPreferences(csvPreference);
String fileEncoding = CharsetHelper.getCharsetName(preferencesController.getFileEncoding());
setFileEncoding(fileEncoding);
saveFileEncoding(fileEncoding);
} else {
preferencesController.setCsvPreference(csvPreferenceFile.getContent());
preferencesController.setFileEncoding(fileEncodingFile.getContent());
}
}
private void saveFileEncoding(String fileEncoding) {
try {
createFileEncodingFile();
fileEncodingFile.setContent(fileEncoding);
useSaveFileService(fileEncodingFile);
} catch (IOException e) {
e.printStackTrace();
}
}
private void createFileEncodingFile() throws IOException {
if (!fileEncodingFile.getFile().exists()) {
createPreferencesFileFolder();
fileEncodingFile.getFile().createNewFile();
}
}
@@ -370,6 +430,26 @@ public class SmartCSVController extends FXMLController {
}
}
@FXML
public void export(ActionEvent actionEvent) {
final FileChooser fileChooser = new FileChooser();
//Set extension filter
final FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter(EXPORT_LOG_FILTER_TEXT, EXPORT_LOG_FILTER_EXTENSION);
fileChooser.getExtensionFilters().add(extFilter);
fileChooser.setTitle("Save");
//Show open file dialog
File file = fileChooser.showSaveDialog(applicationPane.getScene().getWindow());
if (file != null) {
errorExport.setCsvFilename(currentCsvFile.getFile().getName());
errorExport.setModel(currentCsvFile.getContent());
errorExport.setFile(file);
errorExport.setResourceBundle(resourceBundle);
errorExport.restart();
}
}
public boolean canExit() {
boolean canExit = true;
if (currentCsvFile.getContent() != null && currentCsvFile.isFileChanged()) {
@@ -389,6 +469,7 @@ public class SmartCSVController extends FXMLController {
public void showValidationEditor(String column) {
validationEditorController.setSelectedColumn(column);
validationEditorController.updateForm();
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setGraphic(null);
@@ -455,9 +536,13 @@ public class SmartCSVController extends FXMLController {
private void loadCsvPreferencesFromFile() {
if (csvPreferenceFile.getFile().exists()) {
useLoadFileService(csvPreferenceFile, event -> setCsvPreference(csvPreferenceFile.getContent()));
useLoadFileService(csvPreferenceFile, event -> {
setCsvPreference(csvPreferenceFile.getContent());
loadEncodingFromFile();
});
} else {
setCsvPreference(CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE);
loadEncodingFromFile();
}
}
@@ -486,6 +571,9 @@ public class SmartCSVController extends FXMLController {
private void setCsvPreference(CsvPreference csvPreference) {
preferencesController.setCsvPreference(csvPreference);
csvFileReader.setCsvPreference(csvPreference);
csvFileWriter.setCsvPreference(csvPreference);
}
private void loadFile(String filterText,
@@ -552,6 +640,8 @@ public class SmartCSVController extends FXMLController {
* Creates new table view and add the new content
*/
private void resetContent() {
resetExportButtons();
if (currentCsvFile.getContent() != null) {
currentCsvFile.getContent().getValidationError().addListener(weakErrorListListener);
currentCsvFile.getContent().setValidationConfiguration(currentConfigFile.getContent());
@@ -575,9 +665,22 @@ public class SmartCSVController extends FXMLController {
setRightAnchor(tableView, 0.0);
tableWrapper.getChildren().setAll(tableView);
errorSideBar.setModel(currentCsvFile.getContent());
binExportButtons();
}
}
private void binExportButtons() {
exportButton.disableProperty().bind(Bindings.isEmpty(currentCsvFile.getContent().getValidationError()));
exportMenuItem.disableProperty().bind(Bindings.isEmpty(currentCsvFile.getContent().getValidationError()));
}
private void resetExportButtons() {
exportButton.disableProperty().unbind();
exportMenuItem.disableProperty().unbind();
exportButton.disableProperty().setValue(true);
exportMenuItem.disableProperty().setValue(true);
}
/**
* Adds a column with the given name to the tableview
* @param header name of the column header

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -48,7 +48,7 @@ import java.util.ResourceBundle;
import static javafx.geometry.Pos.CENTER;
import static ninja.javafx.smartcsv.fx.util.ColorConstants.ERROR_COLOR;
import static ninja.javafx.smartcsv.fx.util.ColorConstants.OK_COLOR;
import static ninja.javafx.smartcsv.fx.util.I18nValidationUtil.getI18nValidatioMessage;
import static ninja.javafx.smartcsv.fx.util.I18nValidationUtil.getI18nValidatioMessageWithColumn;
/**
* clickable side bar with error markers
@@ -137,9 +137,7 @@ public class ErrorSideBar extends Region {
int rows = model.get().getRows().size();
double space = (double)heightWithoutStatusBlock() / rows;
for (ValidationError error : errorList) {
errorMarkerList.add(generateErrorMarker(space, error));
}
errorList.forEach(error -> errorMarkerList.add(generateErrorMarker(space, error)));
}
}
getChildren().setAll(errorMarkerList);
@@ -158,7 +156,7 @@ public class ErrorSideBar extends Region {
errorMarker.setStyle("-fx-background-color: " + ERROR_COLOR);
errorMarker.setOnMouseClicked(event -> selectedValidationError.setValue(error));
errorMarker.setOnMouseEntered(event -> {
popOver.setContentNode(popupContent(getI18nValidatioMessage(resourceBundle, error)));
popOver.setContentNode(popupContent(getI18nValidatioMessageWithColumn(resourceBundle, error)));
popOver.show(errorMarker, -16);
});
return errorMarker;

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -39,6 +39,7 @@ import org.springframework.stereotype.Component;
import org.supercsv.prefs.CsvPreference;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.ResourceBundle;
import java.util.function.UnaryOperator;
@@ -66,6 +67,9 @@ public class PreferencesController extends FXMLController {
@FXML
private ComboBox<String> quoteMode;
@FXML
private ComboBox<String> fileEncoding;
private String endOfLineSymbols;
private BooleanProperty valid = new SimpleBooleanProperty(true);
@@ -80,6 +84,7 @@ public class PreferencesController extends FXMLController {
@Override
public void initialize(URL location, ResourceBundle resources) {
quoteMode.getItems().addAll("normal", "always", "column");
fileEncoding.getItems().addAll(Charset.availableCharsets().keySet());
UnaryOperator<TextFormatter.Change> allowOnlyOneCharacter = change -> {
if (change.isContentChange()) {
@@ -117,6 +122,14 @@ public class PreferencesController extends FXMLController {
.build();
}
public void setFileEncoding(String fileEncoding) {
this.fileEncoding.setValue(fileEncoding);
}
public String getFileEncoding() {
return fileEncoding.getValue();
}
public boolean getValid() {
return valid.get();
}

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -29,7 +29,7 @@ package ninja.javafx.smartcsv.fx.table.model;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import ninja.javafx.smartcsv.validation.RevalidationService;
import ninja.javafx.smartcsv.validation.ValidationConfiguration;
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
import ninja.javafx.smartcsv.validation.ValidationError;
import ninja.javafx.smartcsv.validation.Validator;
import org.apache.logging.log4j.LogManager;
@@ -39,7 +39,7 @@ import org.apache.logging.log4j.Logger;
* The CSVModel is the client representation for the csv filepath.
* It holds the data in rows, stores the header and manages the validator.
*/
public final class CSVModel {
public final class CSVModel implements ColumnValueProvider {
private static final Logger logger = LogManager.getLogger(CSVModel.class);
@@ -55,7 +55,7 @@ public final class CSVModel {
* @param validationConfiguration the validator configuration for this data
*/
public void setValidationConfiguration(ValidationConfiguration validationConfiguration) {
this.validator = new Validator(validationConfiguration);
this.validator = new Validator(validationConfiguration, this);
revalidate();
}
@@ -145,11 +145,19 @@ public final class CSVModel {
public ValidationConfiguration createValidationConfiguration() {
ValidationConfiguration newValidationConfiguration = new ValidationConfiguration();
newValidationConfiguration.setHeaderNames(this.header);
this.validator = new Validator(newValidationConfiguration);
this.validator = new Validator(newValidationConfiguration, this);
this.revalidate();
return newValidationConfiguration;
}
@Override
public String getValue(int row, String column) {
return rows.get(row).getColumns().get(column).getValue().getValue();
}
@Override
public int getNumberOfRows() {
return rows.size();
}
}

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -0,0 +1,11 @@
package ninja.javafx.smartcsv.fx.table.model;
/**
* interface for easier access to values in a column
*/
public interface ColumnValueProvider {
String getValue(int row, String column);
int getNumberOfRows();
}

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -43,9 +43,8 @@ public class I18nValidationUtil {
public static String getI18nValidatioMessage(ResourceBundle resourceBundle, List<ValidationError> errors) {
StringWriter message = new StringWriter();
for (ValidationError validationError: errors) {
message.append(getI18nValidatioMessage(resourceBundle, validationError)).append("\n");
}
errors.forEach(error -> message.append(getI18nValidatioMessage(resourceBundle, error)).append("\n"));
if (message.toString().length() != 0) {
return cutOffLastLineBreak(message.toString());
@@ -54,11 +53,20 @@ public class I18nValidationUtil {
return "";
}
public static String getI18nValidatioMessageWithColumn(ResourceBundle resourceBundle, ValidationError error) {
return getI18nValidatioMessage(resourceBundle, error, resourceBundle.getString("column") + " " + error.getColumn() + " : ");
}
public static String getI18nValidatioMessage(ResourceBundle resourceBundle, ValidationError error) {
return getI18nValidatioMessage(resourceBundle, error, "");
}
private static String getI18nValidatioMessage(ResourceBundle resourceBundle, ValidationError error, String prefix) {
List<ValidationMessage> validationMessages = error.getMessages();
StringWriter message = new StringWriter();
for (ValidationMessage validationMessage: validationMessages) {
validationMessages.forEach(validationMessage -> {
message.append(prefix);
if (resourceBundle.containsKey(validationMessage.getKey())) {
String resourceText = resourceBundle.getString(validationMessage.getKey());
if (validationMessage.getParameters().length > 0) {
@@ -69,7 +77,7 @@ public class I18nValidationUtil {
} else {
message.append(validationMessage.getKey()).append("\n");
}
}
});
if (!validationMessages.isEmpty()) {
return cutOffLastLineBreak(message.toString());

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -0,0 +1,61 @@
/*
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.fx.validation;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.util.Callback;
import ninja.javafx.smartcsv.validation.configuration.StringFormat;
import java.util.ResourceBundle;
/**
* cell factory for string formats
*/
public class StringFormatEditorCellFactory implements Callback<ListView<StringFormat>, ListCell<StringFormat>> {
private ResourceBundle resourceBundle;
public StringFormatEditorCellFactory(ResourceBundle resourceBundle) {
this.resourceBundle = resourceBundle;
}
@Override
public ListCell<StringFormat> call(ListView<StringFormat> param) {
return new ListCell<StringFormat>(){
@Override
protected void updateItem(StringFormat item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setGraphic(null);
} else {
setText(resourceBundle.getString("format.type."+item));
}
}
} ;
}
}

View File

@@ -0,0 +1,54 @@
/*
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.fx.validation;
import javafx.util.StringConverter;
import ninja.javafx.smartcsv.validation.configuration.StringFormat;
import java.util.ResourceBundle;
/**
* converter for string formats
*/
public class StringFormatStringConverter extends StringConverter<StringFormat> {
private ResourceBundle resourceBundle;
public StringFormatStringConverter(ResourceBundle resourceBundle) {
this.resourceBundle = resourceBundle;
}
@Override
public String toString(StringFormat item) {
return resourceBundle.getString("format.type."+item);
}
@Override
public StringFormat fromString(String string) {
return StringFormat.fromExternalValue(string);
}
}

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -30,12 +30,13 @@ import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
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.ValidationConfiguration;
import ninja.javafx.smartcsv.validation.configuration.*;
import org.fxmisc.richtext.CodeArea;
import org.fxmisc.richtext.LineNumberFactory;
import org.fxmisc.richtext.StyleSpans;
import org.fxmisc.richtext.StyleSpansBuilder;
import org.fxmisc.richtext.model.StyleSpans;
import org.fxmisc.richtext.model.StyleSpansBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@@ -47,8 +48,11 @@ import java.util.ResourceBundle;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.lang.Boolean.FALSE;
import static java.util.Arrays.asList;
import static java.util.stream.Collectors.joining;
import static javafx.beans.binding.Bindings.when;
import static ninja.javafx.smartcsv.validation.configuration.Type.STRING;
/**
* controller for editing column validations
@@ -75,7 +79,7 @@ public class ValidationEditorController extends FXMLController {
"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 BRACE_PATTERN = "\\{|\\}";
private static final String BRACKET_PATTERN = "\\[|\\]";
@@ -96,19 +100,13 @@ public class ValidationEditorController extends FXMLController {
);
@FXML
private CheckBox notEmptyRuleCheckBox;
private ComboBox<Type> typeComboBox;
@FXML
private CheckBox integerRuleCheckBox;
private ComboBox<StringFormat> formatComboBox;
@FXML
private CheckBox doublerRuleCheckBox;
@FXML
private CheckBox alphanumericRuleCheckBox;
@FXML
private CheckBox uniqueRuleCheckBox;
private TextField formatTextField;
@FXML
private Spinner<Integer> minLengthSpinner;
@@ -116,9 +114,6 @@ public class ValidationEditorController extends FXMLController {
@FXML
private Spinner<Integer> maxLengthSpinner;
@FXML
private TextField dateformatRuleTextField;
@FXML
private TextField regexpRuleTextField;
@@ -131,24 +126,12 @@ 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;
@FXML
private CheckBox enableMaxLengthRule;
@FXML
private CheckBox enableDateRule;
@FXML
private CheckBox enableRegexpRule;
@@ -170,25 +153,13 @@ public class ValidationEditorController extends FXMLController {
@Override
public void initialize(URL location, ResourceBundle resources) {
minLengthSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, Integer.MAX_VALUE, 0));
maxLengthSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, Integer.MAX_VALUE, 0));
initCheckBox(notEmptyRuleCheckBox, enableNotEmptyRule);
initCheckBox(integerRuleCheckBox, enableIntegerRule);
initCheckBox(doublerRuleCheckBox, enableDoubleRule);
initCheckBox(alphanumericRuleCheckBox, enableAlphanumericRule);
initCheckBox(uniqueRuleCheckBox, enableUniqueRule);
initTypeAndFormatInput(resources);
initMinMaxSpinner();
initSpinner(minLengthSpinner, enableMinLengthRule);
initSpinner(maxLengthSpinner, enableMaxLengthRule);
initTextInputControl(dateformatRuleTextField, enableDateRule);
initTextInputControl(regexpRuleTextField, enableRegexpRule);
initTextInputControl(valueOfRuleTextField, enableValueOfRule);
initCodeAreaControl(groovyRuleTextArea, enableGroovyRule);
selectedColumn.addListener(observable -> {
updateForm();
});
}
public String getSelectedColumn() {
@@ -207,152 +178,236 @@ public class ValidationEditorController extends FXMLController {
this.validationConfiguration = validationConfiguration;
}
public void updateConfiguration() {
private void initTypeAndFormatInput(ResourceBundle resources) {
typeComboBox.getItems().addAll(STRING,
Type.INTEGER,
Type.NUMBER,
Type.DATE,
Type.DATETIME,
Type.TIME);
formatComboBox.setCellFactory(new StringFormatEditorCellFactory(resources));
formatComboBox.setConverter(new StringFormatStringConverter(resources));
formatComboBox.getItems().addAll(
StringFormat.DEFAULT,
StringFormat.EMAIL,
StringFormat.URI,
StringFormat.BINARY,
StringFormat.UUID
);
typeComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> changeFormat());
}
if (enableIntegerRule.isSelected()) {
validationConfiguration.setIntegerRuleFor(selectedColumn.getValue(), integerRuleCheckBox.isSelected());
} else {
validationConfiguration.setIntegerRuleFor(selectedColumn.getValue(), null);
private void updateFormatTextField() {
switch (typeComboBox.getValue()) {
case DATE:
case DATETIME:
case TIME:
formatTextField.setVisible(true);
formatTextField.setText(getCurrentFieldConfig().getFormat());
break;
default:
formatTextField.setVisible(false);
formatTextField.setText(null);
break;
}
}
if (enableNotEmptyRule.isSelected()) {
validationConfiguration.setNotEmptyRuleFor(selectedColumn.getValue(), notEmptyRuleCheckBox.isSelected());
} else {
validationConfiguration.setNotEmptyRuleFor(selectedColumn.getValue(), null);
private void updateFormatComboBox() {
switch (typeComboBox.getValue()) {
case STRING:
formatComboBox.setVisible(true);
formatComboBox.getSelectionModel().select(StringFormat.fromExternalValue(getCurrentFieldConfig().getFormat()));
break;
default:
formatComboBox.setVisible(false);
break;
}
}
if (enableUniqueRule.isSelected()) {
validationConfiguration.setUniqueRuleFor(selectedColumn.getValue(), uniqueRuleCheckBox.isSelected());
} else {
validationConfiguration.setUniqueRuleFor(selectedColumn.getValue(), null);
}
if (enableDoubleRule.isSelected()) {
validationConfiguration.setDoubleRuleFor(selectedColumn.getValue(), doublerRuleCheckBox.isSelected());
} else {
validationConfiguration.setDoubleRuleFor(selectedColumn.getValue(), null);
}
if (enableAlphanumericRule.isSelected()) {
validationConfiguration.setAlphanumericRuleFor(selectedColumn.getValue(), alphanumericRuleCheckBox.isSelected());
} else {
validationConfiguration.setAlphanumericRuleFor(selectedColumn.getValue(), null);
}
if (enableDateRule.isSelected()) {
validationConfiguration.setDateRuleFor(selectedColumn.getValue(), dateformatRuleTextField.getText());
} else {
validationConfiguration.setDateRuleFor(selectedColumn.getValue(), null);
}
if (enableGroovyRule.isSelected()) {
validationConfiguration.setGroovyRuleFor(selectedColumn.getValue(), groovyRuleTextArea.getText());
} else {
validationConfiguration.setGroovyRuleFor(selectedColumn.getValue(), null);
}
if (enableMinLengthRule.isSelected()) {
validationConfiguration.setMinLengthRuleFor(selectedColumn.getValue(), minLengthSpinner.getValue());
} else {
validationConfiguration.setMinLengthRuleFor(selectedColumn.getValue(), null);
}
if (enableMaxLengthRule.isSelected()) {
validationConfiguration.setMaxLengthRuleFor(selectedColumn.getValue(), maxLengthSpinner.getValue());
} else {
validationConfiguration.setMaxLengthRuleFor(selectedColumn.getValue(), null);
}
if (enableRegexpRule.isSelected()) {
validationConfiguration.setRegexpRuleFor(selectedColumn.getValue(), regexpRuleTextField.getText());
} else {
validationConfiguration.setRegexpRuleFor(selectedColumn.getValue(), null);
}
if (enableValueOfRule.isSelected()) {
validationConfiguration.setValueOfRuleFor(selectedColumn.getValue(), asList(valueOfRuleTextField.getText().split(", ")));
} else {
validationConfiguration.setValueOfRuleFor(selectedColumn.getValue(), null);
}
private void initMinMaxSpinner() {
IntegerSpinnerValueFactory minValueFactory = new IntegerSpinnerValueFactory(0, Integer.MAX_VALUE, 0);
minLengthSpinner.setValueFactory(minValueFactory);
IntegerSpinnerValueFactory maxValueFactory = new IntegerSpinnerValueFactory(0, Integer.MAX_VALUE, 0);
maxLengthSpinner.setValueFactory(maxValueFactory);
minValueFactory.maxProperty().bind(
when(enableMaxLengthRule.selectedProperty()).
then(maxLengthSpinner.valueProperty()).
otherwise(Integer.MAX_VALUE));
maxValueFactory.minProperty().bind(
when(enableMinLengthRule.selectedProperty()).
then(minLengthSpinner.valueProperty()).
otherwise(0));
}
private void updateForm() {
updateCheckBox(
notEmptyRuleCheckBox,
validationConfiguration.getNotEmptyRuleFor(getSelectedColumn()),
enableNotEmptyRule
private void changeFormat() {
switch (typeComboBox.getValue()) {
case STRING:
updateFormatComboBox();
break;
case DATE:
case DATETIME:
case TIME:
updateFormatTextField();
break;
case INTEGER:
case NUMBER:
default:
// format: no options
formatComboBox.setVisible(false);
formatTextField.setVisible(false);
break;
}
}
public void updateConfiguration() {
Field config = getCurrentFieldConfig();
config.setType(typeComboBox.getValue());
switch (typeComboBox.getValue()) {
case STRING:
config.setFormat(formatComboBox.getValue().getExternalValue());
break;
case DATE:
case DATETIME:
case TIME:
if (formatTextField.getText().trim().isEmpty()) {
config.setFormat(null);
} else {
// TODO: validate input
config.setFormat(formatTextField.getText());
}
break;
case INTEGER:
case NUMBER:
default:
// format: no options
config.setFormat(null);
break;
}
if (enableGroovyRule.isSelected()) {
config.setGroovy(groovyRuleTextArea.getText());
} else {
config.setGroovy(null);
}
Constraints constraints = config.getConstraints();
if (constraints == null) {
constraints = new Constraints();
config.setConstraints(constraints);
}
if (enableNotEmptyRule.isSelected()) {
constraints.setRequired(enableNotEmptyRule.isSelected());
} else {
constraints.setRequired(null);
}
if (enableUniqueRule.isSelected()) {
constraints.setUnique(enableUniqueRule.isSelected());
} else {
constraints.setUnique(null);
}
if (enableMinLengthRule.isSelected()) {
constraints.setMinLength(minLengthSpinner.getValue());
} else {
constraints.setMinLength(null);
}
if (enableMaxLengthRule.isSelected()) {
constraints.setMaxLength(maxLengthSpinner.getValue());
} else {
constraints.setMaxLength(null);
}
if (enableRegexpRule.isSelected()) {
constraints.setPattern(regexpRuleTextField.getText());
} else {
constraints.setPattern(null);
}
if (enableValueOfRule.isSelected()) {
constraints.setEnumeration(asList(valueOfRuleTextField.getText().split(", ")));
} else {
constraints.setEnumeration(null);
}
}
private Field getCurrentFieldConfig() {
return validationConfiguration.getFieldConfiguration(getSelectedColumn());
}
private void addDependencyListener(CheckBox rule, CheckBox... dependentRules) {
rule.selectedProperty().addListener((observable, oldValue, newValue) -> {
if (newValue) {
for (CheckBox dependentRule: dependentRules) {
dependentRule.selectedProperty().setValue(false);
}
}
});
}
public void updateForm() {
Field config = getCurrentFieldConfig();
if (config.getType() != null) {
typeComboBox.setValue(config.getType());
} else {
typeComboBox.setValue(STRING);
}
updateFormatComboBox();
updateFormatTextField();
updateCodeAreaControl(
groovyRuleTextArea,
config.getGroovy(),
enableGroovyRule
);
updateCheckBox(
integerRuleCheckBox,
validationConfiguration.getIntegerRuleFor(getSelectedColumn()),
enableIntegerRule
);
updateCheckBox(
doublerRuleCheckBox,
validationConfiguration.getDoubleRuleFor(getSelectedColumn()),
enableDoubleRule
);
updateCheckBox(
alphanumericRuleCheckBox,
validationConfiguration.getAlphanumericRuleFor(getSelectedColumn()),
enableAlphanumericRule
);
updateCheckBox(
uniqueRuleCheckBox,
validationConfiguration.getUniqueRuleFor(getSelectedColumn()),
enableUniqueRule
);
Constraints constraints = config.getConstraints();
updateCheckBox(constraints != null ? constraints.getRequired() : FALSE, enableNotEmptyRule);
updateCheckBox(constraints != null ? constraints.getUnique() : FALSE, enableUniqueRule);
updateSpinner(
minLengthSpinner,
validationConfiguration.getMinLengthRuleFor(getSelectedColumn()),
constraints != null ? constraints.getMinLength() : null,
enableMinLengthRule
);
updateSpinner(
maxLengthSpinner,
validationConfiguration.getMaxLengthRuleFor(getSelectedColumn()),
constraints != null ? constraints.getMaxLength() : null,
enableMaxLengthRule
);
updateTextInputControl(
dateformatRuleTextField,
validationConfiguration.getDateRuleFor(getSelectedColumn()),
enableDateRule
);
updateTextInputControl(
regexpRuleTextField,
validationConfiguration.getRegexpRuleFor(getSelectedColumn()),
constraints != null ? constraints.getPattern() : null,
enableRegexpRule
);
updateTextInputControl(
valueOfRuleTextField,
validationConfiguration.getValueOfRuleFor(getSelectedColumn()),
constraints != null ? constraints.getEnumeration() : null,
enableValueOfRule
);
updateCodeAreaControl(
groovyRuleTextArea,
validationConfiguration.getGroovyRuleFor(getSelectedColumn()),
enableGroovyRule
);
}
private void updateCheckBox(CheckBox rule, Boolean value, CheckBox ruleEnabled) {
private void updateCheckBox(Boolean value, CheckBox ruleEnabled) {
if (value == null) {
ruleEnabled.setSelected(false);
} else {
rule.setSelected(value);
ruleEnabled.setSelected(true);
ruleEnabled.setSelected(value);
}
}
@@ -388,19 +443,10 @@ public class ValidationEditorController extends FXMLController {
ruleEnabled.setSelected(false);
} else {
ruleEnabled.setSelected(true);
rule.replaceText(0, 0, value);
rule.replaceText(0, rule.getLength(), value);
}
}
private void initCheckBox(CheckBox rule, CheckBox ruleEnabled) {
rule.disableProperty().bind(ruleEnabled.selectedProperty().not());
ruleEnabled.selectedProperty().addListener((observable, oldValue, newValue) -> {
if (!newValue) {
rule.setSelected(false);
}
});
}
private void initSpinner(Spinner rule, CheckBox ruleEnabled) {
rule.disableProperty().bind(ruleEnabled.selectedProperty().not());
ruleEnabled.selectedProperty().addListener((observable, oldValue, newValue) -> {

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -24,23 +24,21 @@
*/
package ninja.javafx.smartcsv.validation;
package ninja.javafx.smartcsv.preferences;
import com.google.gson.annotations.SerializedName;
import java.nio.charset.Charset;
/**
* header configuration for the validation
* Helper class for getting charset's name
*/
public class HeaderConfiguration {
public class CharsetHelper {
@SerializedName("list")
private String[] names ;
public String[] getNames() {
return names;
public static String getCharsetName(String name) {
try {
return Charset.forName(name).name();
} catch (Exception e) {
return Charset.defaultCharset().name();
}
}
public void setNames(String[] names) {
this.names = names;
}
}

View File

@@ -0,0 +1,62 @@
/*
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.preferences;
import com.google.gson.GsonBuilder;
import ninja.javafx.smartcsv.FileReader;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
/**
* file reader for the file encoding
*/
public class EncodingFileReader implements FileReader<String> {
private String fileEncoding;
public EncodingFileReader() {
fileEncoding = Charset.defaultCharset().name();
}
@Override
public String getContent() {
return fileEncoding;
}
@Override
public void read(File filename) throws IOException {
Map settings = new GsonBuilder().create().fromJson(new java.io.FileReader(filename), HashMap.class);
if (settings != null) {
fileEncoding = CharsetHelper.getCharsetName(settings.get("fileEncoding").toString());
}
}
}

View File

@@ -0,0 +1,59 @@
/*
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.preferences;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import ninja.javafx.smartcsv.FileWriter;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
/**
* Save the file encoding to configuration file
*/
public class EncodingFileWriter implements FileWriter<String> {
private String fileEncoding;
@Override
public void setContent(String fileEncoding) {
this.fileEncoding = fileEncoding;
}
@Override
public void write(File filename) throws IOException {
Map<String, String> encodings = new HashMap<>();
encodings.put("fileEncoding", CharsetHelper.getCharsetName(fileEncoding));
Gson gson = new GsonBuilder().setPrettyPrinting().create();
Files.write(filename.toPath(), gson.toJson(encodings).getBytes());
}
}

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -1,176 +0,0 @@
/*
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation;
import com.google.gson.annotations.SerializedName;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* validation configuration
*/
public class ValidationConfiguration {
@SerializedName("headers")
private HeaderConfiguration headerConfiguration = new HeaderConfiguration();
@SerializedName("columns")
private Map<String, Map<String, Object>> columnConfigurations = new HashMap<>();
public String[] headerNames() {
if (noHeader()) return null;
return headerConfiguration.getNames();
}
public void setHeaderNames(String[] headerNames) {
headerConfiguration.setNames(headerNames);
}
public Boolean getUniqueRuleFor(String column) {
return (Boolean)getValue(column, "unique");
}
public Boolean getIntegerRuleFor(String column) {
return (Boolean)getValue(column, "integer");
}
public Boolean getDoubleRuleFor(String column) {
return (Boolean)getValue(column, "double");
}
public Boolean getNotEmptyRuleFor(String column) {
return (Boolean)getValue(column, "not empty");
}
public Integer getMinLengthRuleFor(String column) {
return doubleToInteger((Double)getValue(column, "minlength"));
}
public Integer getMaxLengthRuleFor(String column) {
Double value = (Double)getValue(column, "maxlength");
return value != null ? doubleToInteger(value) : null;
}
public String getDateRuleFor(String column) {
return (String)getValue(column, "date");
}
public Boolean getAlphanumericRuleFor(String column) {
return (Boolean)getValue(column, "alphanumeric");
}
public String getRegexpRuleFor(String column) {
return (String)getValue(column, "regexp");
}
public List<String> getValueOfRuleFor(String column) {
return (List<String>)getValue(column, "value of");
}
public String getGroovyRuleFor(String column) {
return (String)getValue(column, "groovy");
}
public void setIntegerRuleFor(String column, Boolean value) {
setValue(column, value, "integer");
}
public void setDoubleRuleFor(String column, Boolean value) {
setValue(column, value, "double");
}
public void setNotEmptyRuleFor(String column, Boolean value) {
setValue(column, value, "not empty");
}
public void setUniqueRuleFor(String column, Boolean value) {
setValue(column, value, "unique");
}
public void setMinLengthRuleFor(String column, Integer value) {
setValue(column, value == null ? null : value.doubleValue(), "minlength");
}
public void setMaxLengthRuleFor(String column, Integer value) {
setValue(column, value == null ? null : value.doubleValue(), "maxlength");
}
public void setDateRuleFor(String column, String value) {
setValue(column, value, "date");
}
public void setAlphanumericRuleFor(String column, Boolean value) {
setValue(column, value, "alphanumeric");
}
public void setRegexpRuleFor(String column, String value) {
setValue(column, value, "regexp");
}
public void setValueOfRuleFor(String column, List<String> value) {
setValue(column, value, "value of");
}
public void setGroovyRuleFor(String column, String value) {
setValue(column, value, "groovy");
}
private void setValue(String column, Object value, String key) {
if (!columnConfigurations.containsKey(column)) {
columnConfigurations.put(column, new HashMap<>());
}
if (value == null && columnConfigurations.get(column).containsKey(key)) {
columnConfigurations.get(column).remove(key);
} else {
columnConfigurations.get(column).put(key, value);
}
}
private Object getValue(String column, String key) {
if (columnConfigurations != null) {
Map rulesForColumn = columnConfigurations.get(column);
if (rulesForColumn != null) {
return columnConfigurations.get(column).get(key);
}
}
return null;
}
private boolean noHeader() {
return headerConfiguration == null;
}
private Integer doubleToInteger(Double value) {
if (value == null) return null;
return (int)Math.round(value);
}
}

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -38,6 +38,7 @@ public class ValidationError {
private List<ValidationMessage> messages = new ArrayList<>();
private Integer lineNumber;
private String column = "";
private ValidationError(Integer lineNumber) {
this.lineNumber = lineNumber;
@@ -51,10 +52,19 @@ public class ValidationError {
return new ValidationError(-1);
}
public ValidationError column(String column) {
this.column = column;
return this;
}
public Integer getLineNumber() {
return lineNumber;
}
public String getColumn() {
return column;
}
public List<ValidationMessage> getMessages() {
return messages;
}

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -28,10 +28,14 @@ package ninja.javafx.smartcsv.validation;
import com.google.gson.GsonBuilder;
import ninja.javafx.smartcsv.FileReader;
import ninja.javafx.smartcsv.validation.configuration.Field;
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
import java.io.File;
import java.io.IOException;
import static ninja.javafx.smartcsv.validation.configuration.Type.*;
/**
* This class loads the constraints as json config
*/
@@ -42,6 +46,30 @@ public class ValidationFileReader implements FileReader<ValidationConfiguration>
@Override
public void read(File file) throws IOException {
config = new GsonBuilder().create().fromJson(new java.io.FileReader(file), ValidationConfiguration.class);
setDefaults();
}
private void setDefaults() {
for (Field field : config.getFields()) {
if (field.getType() == null) {
field.setType(STRING);
}
if (field.getType() == DATE) {
if (field.getFormat() == null) {
field.setFormat("yyyy-MM-dd");
}
}
if (field.getType() == DATETIME) {
if (field.getFormat() == null) {
field.setFormat("yyyy-MM-ddThh:mm:ssZ");
}
}
if (field.getType() == TIME) {
if (field.getFormat() == null) {
field.setFormat("hh:mm:ss");
}
}
}
}
public ValidationConfiguration getContent() {

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -29,6 +29,7 @@ package ninja.javafx.smartcsv.validation;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import ninja.javafx.smartcsv.FileWriter;
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
import java.io.File;
import java.io.IOException;

View File

@@ -0,0 +1,52 @@
package ninja.javafx.smartcsv.validation;
import java.text.SimpleDateFormat;
/**
* @author abi
*/
public class ValidationFormatHelper {
public static String dateFormat(String format, String defaultFormat) {
if (format != null && !format.trim().isEmpty()) {
format = format.trim();
if (format.startsWith("fmt:")) {
format = format.substring(4);
format = format.replace("%Y", "yyyy");
format = format.replace("%y", "yy");
format = format.replace("%m", "MM");
format = format.replace("%d", "dd");
format = format.replace("%a", "E");
format = format.replace("%A", "EEEE");
format = format.replace("%w", "F");
format = format.replace("%b", "MMM");
format = format.replace("%B", "MMMMM");
format = format.replace("%H", "HH");
format = format.replace("%I", "hh");
format = format.replace("%p", "a");
format = format.replace("%M", "mm");
format = format.replace("%S", "ss");
format = format.replace("%z", "Z");
format = format.replace("%Z", "z");
format = format.replace("%j", "DDD");
format = format.replace("%U", "ww");
return format;
} else {
try {
new SimpleDateFormat(format);
return format;
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
}
return defaultFormat;
}
public static Integer doubleToInteger(Double value) {
if (value == null) return null;
return (int)Math.round(value);
}
}

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -26,10 +26,20 @@
package ninja.javafx.smartcsv.validation;
import ninja.javafx.smartcsv.fx.table.model.ColumnValueProvider;
import ninja.javafx.smartcsv.validation.checker.*;
import ninja.javafx.smartcsv.validation.configuration.Constraints;
import ninja.javafx.smartcsv.validation.configuration.Field;
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static ninja.javafx.smartcsv.validation.ValidationFormatHelper.dateFormat;
import static ninja.javafx.smartcsv.validation.configuration.StringFormat.*;
import static ninja.javafx.smartcsv.validation.configuration.Type.*;
/**
* This class checks all the validations defined in the
* Config against a given value
@@ -41,6 +51,7 @@ public class Validator {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private ValidationConfiguration validationConfig;
private ColumnValueProvider columnValueProvider;
private Map<String, Map<Validation.Type, Validation>> columnValidationMap = new HashMap<>();
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -52,8 +63,9 @@ public class Validator {
*
* @param validationConfig
*/
public Validator(ValidationConfiguration validationConfig) {
public Validator(ValidationConfiguration validationConfig, ColumnValueProvider columnValueProvider) {
this.validationConfig = validationConfig;
this.columnValueProvider = columnValueProvider;
initColumnValidations();
}
@@ -82,17 +94,12 @@ public class Validator {
public ValidationError isValid(Integer row, String column, String value) {
ValidationError result = null;
if (hasConfig()) {
ValidationError error = ValidationError.withLineNumber(row);
ValidationError error = ValidationError.withLineNumber(row).column(column);
Map<Validation.Type, Validation> validationMap = columnValidationMap.get(column);
if (validationMap != null) {
for (Validation validation: validationMap.values()) {
if (validation.getType() == Validation.Type.NOT_EMPTY) {
if (validation.canBeChecked(value)) {
validation.check(row, value, error);
} else {
if (value != null && !value.isEmpty()) {
validation.check(row, value, error);
}
}
}
}
@@ -126,6 +133,15 @@ public class Validator {
validationMap.put(validation.getType(), validation);
}
private void remove(String column, Validation.Type type) {
Map<Validation.Type, Validation> validationMap = columnValidationMap.get(column);
if (validationMap == null) {
validationMap = new HashMap<>();
columnValidationMap.put(column, validationMap);
}
validationMap.remove(type);
}
private void clear(String column) {
Map<Validation.Type, Validation> validationMap = columnValidationMap.get(column);
if (validationMap != null) {
@@ -135,70 +151,117 @@ public class Validator {
private void initColumnValidations() {
if (hasConfig()) {
String[] columns = validationConfig.headerNames();
for (String column : columns) {
for (Field column : validationConfig.getFields()) {
initializeColumnWithRules(column);
}
}
}
private void initializeColumnWithRules(String column) {
Boolean alphaNumeric = validationConfig.getAlphanumericRuleFor(column);
if (alphaNumeric != null && alphaNumeric) {
add(column, new AlphaNumericValidation());
private void initializeColumnWithRules(String columnName) {
if (hasConfig()) {
for (Field column : validationConfig.getFields()) {
if (column.getName().equals(columnName)) {
initializeColumnWithRules(column);
break;
}
}
}
Boolean doubleRule = validationConfig.getDoubleRuleFor(column);
if (doubleRule != null && doubleRule) {
add(column, new DoubleValidation());
}
private void initializeColumnWithRules(Field column) {
if (column.getType() != null) {
if (column.getType() == NUMBER) {
add(column.getName(), new DoubleValidation());
}
if (column.getType() == INTEGER) {
add(column.getName(), new IntegerValidation());
}
if (column.getType() == DATE) {
String format = dateFormat(column.getFormat(), "yyyy-MM-dd");
add(column.getName(), new DateValidation(format));
}
if (column.getType() == DATETIME) {
String format = dateFormat(column.getFormat(), "yyyy-MM-ddThh:mm:ssZ");
add(column.getName(), new DateValidation(format));
}
if (column.getType() == TIME) {
String format = dateFormat(column.getFormat(), "hh:mm:ss");
add(column.getName(), new DateValidation(format));
}
if (column.getType() == STRING && column.getFormat() == null) {
remove(column.getName(), Validation.Type.STRING);
} else {
if (column.getType() == STRING && column.getFormat().equalsIgnoreCase(EMAIL.getExternalValue())) {
add(column.getName(), new EmailValidation());
}
if (column.getType() == STRING && column.getFormat().equalsIgnoreCase(URI.getExternalValue())) {
add(column.getName(), new UriValidation());
}
if (column.getType() == STRING && column.getFormat().equalsIgnoreCase(UUID.getExternalValue())) {
add(column.getName(), new UuidValidation());
}
if (column.getType() == STRING && column.getFormat().equalsIgnoreCase(BINARY.getExternalValue())) {
add(column.getName(), new BinaryValidation());
}
}
}
Boolean integerRule = validationConfig.getIntegerRuleFor(column);
if (integerRule != null && integerRule) {
add(column, new IntegerValidation());
}
Boolean notEmptyRule = validationConfig.getNotEmptyRuleFor(column);
if (notEmptyRule != null && notEmptyRule) {
add(column, new NotEmptyValidation());
}
Boolean uniqueRule = validationConfig.getUniqueRuleFor(column);
if (uniqueRule != null && uniqueRule) {
add(column, new UniqueValidation());
}
String dateRule = validationConfig.getDateRuleFor(column);
if (dateRule != null && !dateRule.trim().isEmpty()) {
add(column, new DateValidation(dateRule));
}
Integer minLength = validationConfig.getMinLengthRuleFor(column);
if (minLength != null) {
add(column, new MinLengthValidation(minLength));
}
Integer maxLength = validationConfig.getMaxLengthRuleFor(column);
if (maxLength != null) {
add(column, new MaxLengthValidation(maxLength));
}
String regexp = validationConfig.getRegexpRuleFor(column);
if (regexp != null && !regexp.trim().isEmpty()) {
add(column, new RegExpValidation(regexp));
}
String groovy = validationConfig.getGroovyRuleFor(column);
String groovy = column.getGroovy();
if (groovy != null && !groovy.trim().isEmpty()) {
add(column, new GroovyValidation(groovy));
add(column.getName(), new GroovyValidation(groovy));
}
List<String> valueOfRule = validationConfig.getValueOfRuleFor(column);
if (valueOfRule != null && !valueOfRule.isEmpty()) {
add(column, new ValueOfValidation(valueOfRule));
Constraints 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()) {
add(column.getName(), new ValueOfValidation(valueOfRule));
}
}
}
public ValidationError isHeaderValid(String[] headerNames) {
ValidationError result = null;
if (validationConfig != null) {
@@ -228,4 +291,6 @@ public class Validator {
}
return result;
}
}

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -23,32 +23,28 @@
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation;
package ninja.javafx.smartcsv.validation.checker;
import java.util.HashMap;
import ninja.javafx.smartcsv.validation.ValidationError;
import java.util.Base64;
/**
* Checks if the value is unique in the column
* checks if the value is a base64 encoded string representing binary data
*/
public class UniqueValidation implements Validation {
private HashMap<String, Integer> columnValueMap = new HashMap<>();
public class BinaryValidation extends EmptyValueIsValid {
@Override
public void check(int row, String value, ValidationError error) {
Integer valueInLineNumber = columnValueMap.get(value);
if (valueInLineNumber != null) {
if (!valueInLineNumber.equals(row)) {
valueInLineNumber += 1; // show not 0 based line numbers to user
error.add("validation.message.uniqueness", value, valueInLineNumber.toString());
}
} else {
columnValueMap.put(value, row);
try {
Base64.getDecoder().decode(value);
} catch (IllegalArgumentException e) {
error.add("validation.message.binary");
}
}
@Override
public Type getType() {
return Type.UNIQUE;
return Type.STRING;
}
}

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -23,14 +23,16 @@
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation;
package ninja.javafx.smartcsv.validation.checker;
import ninja.javafx.smartcsv.validation.ValidationError;
import static org.apache.commons.validator.GenericValidator.isDate;
/**
* Checks if the date has the right format
*/
public class DateValidation implements Validation {
public class DateValidation extends EmptyValueIsValid {
private String dateformat;

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -23,14 +23,16 @@
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation;
package ninja.javafx.smartcsv.validation.checker;
import ninja.javafx.smartcsv.validation.ValidationError;
import static org.apache.commons.validator.GenericValidator.isDouble;
/**
* Checks if the value is a double
*/
public class DoubleValidation implements Validation {
public class DoubleValidation extends EmptyValueIsValid {
@Override
public void check(int row, String value, ValidationError error) {

View File

@@ -0,0 +1,47 @@
/*
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation.checker;
import ninja.javafx.smartcsv.validation.ValidationError;
import org.apache.commons.validator.routines.EmailValidator;
/**
* checks if the value is a valid email address
*/
public class EmailValidation extends EmptyValueIsValid {
@Override
public void check(int row, String value, ValidationError error) {
if (!EmailValidator.getInstance().isValid(value)) {
error.add("validation.message.email");
}
}
@Override
public Type getType() {
return Type.STRING;
}
}

View File

@@ -0,0 +1,12 @@
package ninja.javafx.smartcsv.validation.checker;
/**
* validations based on this are not validated when the value is null or empty
*/
public abstract class EmptyValueIsValid implements Validation {
@Override
public boolean canBeChecked(String value) {
return value != null && !value.isEmpty();
}
}

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -23,17 +23,18 @@
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation;
package ninja.javafx.smartcsv.validation.checker;
import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import groovy.lang.Script;
import ninja.javafx.smartcsv.validation.ValidationError;
import org.codehaus.groovy.control.CompilationFailedException;
/**
* Executes the given groovy as check
*/
public class GroovyValidation implements Validation {
public class GroovyValidation extends EmptyValueIsValid {
private String groovyScript;
private GroovyShell shell = new GroovyShell();

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -23,14 +23,16 @@
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation;
package ninja.javafx.smartcsv.validation.checker;
import ninja.javafx.smartcsv.validation.ValidationError;
import static org.apache.commons.validator.GenericValidator.isInt;
/**
* Checks if the value is an integer
*/
public class IntegerValidation implements Validation {
public class IntegerValidation extends EmptyValueIsValid {
@Override
public void check(int row, String value, ValidationError error) {

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -23,14 +23,16 @@
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation;
package ninja.javafx.smartcsv.validation.checker;
import ninja.javafx.smartcsv.validation.ValidationError;
import static org.apache.commons.validator.GenericValidator.maxLength;
/**
* Checks if the value is shorter or exactly as long as the given max length
*/
public class MaxLengthValidation implements Validation {
public class MaxLengthValidation extends EmptyValueIsValid {
private int maxLength;

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -23,14 +23,16 @@
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation;
package ninja.javafx.smartcsv.validation.checker;
import ninja.javafx.smartcsv.validation.ValidationError;
import static org.apache.commons.validator.GenericValidator.minLength;
/**
* Checks if the value is at minimum long as the given min length
*/
public class MinLengthValidation implements Validation {
public class MinLengthValidation extends EmptyValueIsValid {
private int minLength;

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -23,7 +23,9 @@
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation;
package ninja.javafx.smartcsv.validation.checker;
import ninja.javafx.smartcsv.validation.ValidationError;
import static org.apache.commons.validator.GenericValidator.isBlankOrNull;
@@ -43,4 +45,9 @@ public class NotEmptyValidation implements Validation {
public Type getType() {
return Type.NOT_EMPTY;
}
@Override
public boolean canBeChecked(String value) {
return true;
}
}

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -23,14 +23,16 @@
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation;
package ninja.javafx.smartcsv.validation.checker;
import ninja.javafx.smartcsv.validation.ValidationError;
import static org.apache.commons.validator.GenericValidator.matchRegexp;
/**
* Checks the value against the given reg exp
*/
public class RegExpValidation implements Validation {
public class RegExpValidation extends EmptyValueIsValid {
private String regexp;

View File

@@ -0,0 +1,79 @@
/*
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation.checker;
import ninja.javafx.smartcsv.fx.table.model.ColumnValueProvider;
import ninja.javafx.smartcsv.validation.ValidationError;
import java.util.ArrayList;
import java.util.List;
import static java.util.Collections.sort;
import static java.util.stream.Collectors.joining;
/**
* Checks if the value is unique in the column
*/
public class UniqueValidation extends EmptyValueIsValid {
private ColumnValueProvider columnValueProvider;
private String column;
public UniqueValidation(ColumnValueProvider columnValueProvider, String column) {
this.columnValueProvider = columnValueProvider;
this.column = column;
}
@Override
public void check(int row, String value, ValidationError error) {
List<Integer> lineNumbers = new ArrayList<>();
int numberOfRows = columnValueProvider.getNumberOfRows();
for (int currentRowOfIteration = 0; currentRowOfIteration < numberOfRows; currentRowOfIteration++) {
String storedValue = columnValueProvider.getValue(currentRowOfIteration, column);
if (value.equals(storedValue) && currentRowOfIteration != row) {
lineNumbers.add(currentRowOfIteration + 1); // show not 0 based line numbers to user
}
}
if (!lineNumbers.isEmpty()) {
if (lineNumbers.size() > 1) {
sort(lineNumbers);
error.add("validation.message.uniqueness.multiple", value, lineNumbers.stream().map(Object::toString).collect(joining(", ")));
} else {
error.add("validation.message.uniqueness.single", value, lineNumbers.get(0).toString());
}
}
}
@Override
public Type getType() {
return Type.UNIQUE;
}
}

View File

@@ -0,0 +1,51 @@
/*
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation.checker;
import ninja.javafx.smartcsv.validation.ValidationError;
import java.net.URI;
import java.net.URISyntaxException;
/**
* checks if the value is a valid uri address
*/
public class UriValidation extends EmptyValueIsValid {
@Override
public void check(int row, String value, ValidationError error) {
try {
new URI(value);
} catch (URISyntaxException e) {
error.add("validation.message.uri");
}
}
@Override
public Type getType() {
return Type.STRING;
}
}

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -23,23 +23,28 @@
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation;
package ninja.javafx.smartcsv.validation.checker;
import static org.apache.commons.validator.GenericValidator.matchRegexp;
import ninja.javafx.smartcsv.validation.ValidationError;
import java.util.UUID;
/**
* Checks if the value is alpha numeric
* checks if the value is a valid uuid
*/
public class AlphaNumericValidation implements Validation {
public class UuidValidation extends EmptyValueIsValid {
@Override
public void check(int row, String value, ValidationError error) {
if (!matchRegexp(value, "[0-9a-zA-Z]*")) {
error.add("validation.message.alphanumeric");
try {
UUID.fromString(value);
} catch (IllegalArgumentException e) {
error.add("validation.message.uuid");
}
}
@Override
public Type getType() {
return Type.ALPHANUMERIC;
return Type.STRING;
}
}

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -23,14 +23,17 @@
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation;
package ninja.javafx.smartcsv.validation.checker;
import ninja.javafx.smartcsv.validation.ValidationError;
/**
* Interface for all validations
*/
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, STRING, GROOVY }
void check(int row, String value, ValidationError error);
Type getType();
boolean canBeChecked(String value);
}

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -23,7 +23,9 @@
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation;
package ninja.javafx.smartcsv.validation.checker;
import ninja.javafx.smartcsv.validation.ValidationError;
import java.util.List;
@@ -32,7 +34,7 @@ import static java.util.stream.Collectors.joining;
/**
* Checks if the value is part of a list of values
*/
public class ValueOfValidation implements Validation {
public class ValueOfValidation extends EmptyValueIsValid {
private List<String> values;

View File

@@ -0,0 +1,96 @@
/*
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation.configuration;
import com.google.gson.annotations.SerializedName;
import java.util.List;
/**
* contraints defined in JSON Table Schema
* @see <a href="http://specs.frictionlessdata.io/json-table-schema/">JSON Table Schema</a>
*/
public class Constraints {
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;
}
}

View File

@@ -0,0 +1,109 @@
/*
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation.configuration;
/**
* this class represents a field in the configuration
* @see <a href="http://specs.frictionlessdata.io/json-table-schema/">JSON Table Schema</a>
*/
public class Field {
private String name;
private String title;
private Type type;
private String description;
private String format;
private Object missingValue;
private Constraints constraints;
private String groovy;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getFormat() {
return format;
}
public void setFormat(String format) {
this.format = format;
}
public Object getMissingValue() {
return missingValue;
}
public void setMissingValue(Object missingValue) {
this.missingValue = missingValue;
}
public Constraints getConstraints() {
return constraints;
}
public void setConstraints(Constraints constraints) {
this.constraints = constraints;
}
public String getGroovy() {
return groovy;
}
public void setGroovy(String groovy) {
this.groovy = groovy;
}
}

View File

@@ -0,0 +1,60 @@
/*
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation.configuration;
/**
* Enumeration for format values for type string in JSON Table Schema
* @see <a href="http://specs.frictionlessdata.io/json-table-schema/">JSON Table Schema</a>
*/
public enum StringFormat {
DEFAULT(null),
EMAIL("email"),
URI("uri"),
BINARY("binary"),
UUID("uuid");
private String externalValue;
StringFormat(String externalValue) {
this.externalValue = externalValue;
}
public String getExternalValue() {
return externalValue;
}
public static StringFormat fromExternalValue(String externalValue) {
if (externalValue != null) {
for (StringFormat value : StringFormat.values()) {
if (externalValue.equals(value.getExternalValue())) {
return value;
}
}
}
return DEFAULT;
}
}

View File

@@ -0,0 +1,48 @@
/*
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation.configuration;
import com.google.gson.annotations.SerializedName;
/**
* Types of JSON Table Schema
* @see <a href="http://specs.frictionlessdata.io/json-table-schema/">JSON Table Schema</a>
*/
public enum Type {
@SerializedName("string")STRING,
@SerializedName("integer")INTEGER,
@SerializedName("number")NUMBER,
@SerializedName("date")DATE,
@SerializedName("datetime")DATETIME,
@SerializedName("time")TIME
// TODO: currently not supported
// @SerializedName("object") OBJECT,
// @SerializedName("array") ARRAY,
// @SerializedName("duration") DURATION,
// @SerializedName("geopoint") GEOPOINT,
// @SerializedName("geojson") GEOJSON
}

View File

@@ -0,0 +1,81 @@
/*
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.validation.configuration;
import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
import java.util.List;
/**
* Configuration based on JSON Table Schema
* @see <a href="http://specs.frictionlessdata.io/json-table-schema/">JSON Table Schema</a>
*/
public class ValidationConfiguration {
@SerializedName("fields")
private Field[] fields;
public Field[] getFields() {
return fields;
}
public void setFields(Field[] fields) {
this.fields = fields;
}
public Field getFieldConfiguration(String column) {
for (Field field : fields) {
if (field.getName().equals(column)) {
return field;
}
}
return null;
}
public String[] headerNames() {
if (fields != null) {
List<String> headerNames = new ArrayList<>();
for (Field field : fields) {
headerNames.add(field.getName());
}
return headerNames.toArray(new String[headerNames.size()]);
}
return null;
}
public void setHeaderNames(String[] header) {
fields = new Field[header.length];
int i = 0;
for (String headerName: header) {
fields[i] = new Field();
fields[i].setName(headerName);
i++;
}
}
}

View File

@@ -1,21 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Hyperlink?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="600.0" spacing="4.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1">
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="600.0" spacing="4.0" xmlns="http://javafx.com/javafx/8.0.76-ea" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label text="SmartCSV.fx">
<font>
<Font size="18.0" />
</font>
<VBox.margin>
<Insets top="8.0" />
</VBox.margin>
</Label>
<Label text="A simple JavaFX application to load, save and edit a CSV file and provide a JSON configuration for columns " wrapText="true" />
<Label text="to check the values in the columns." />
<Label text="Thanks for contributions:">
<font>
<Font size="18.0" />
@@ -25,6 +22,7 @@
</VBox.margin>
</Label>
<Label text="AOE Takashi (https://github.com/aoetk)" />
<Label text="Hasan Kara (https://github.com/haisi)" />
<Label text="3rd party software">
<VBox.margin>
<Insets top="8.0" />
@@ -41,17 +39,17 @@
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0" />
</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" 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="20.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="20.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="20.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="20.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="20.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="20.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="20.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="20.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="20.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="20.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="20.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="junit" />
@@ -91,7 +89,7 @@
<Font size="18.0" />
</font>
</Label>
<TextArea editable="false" prefHeight="200.0" prefWidth="200.0" text="Copyright (c) 2015 Andreas Billmann &lt;andreas.billmann@javafx.ninja&gt;&#10;&#10;Permission is hereby granted, free of charge, to any person obtaining a copy&#10;of this software and associated documentation files (the &quot;Software&quot;), to deal&#10;in the Software without restriction, including without limitation the rights&#10;to use, copy, modify, merge, publish, distribute, sublicense, and/or sell&#10;copies of the Software, and to permit persons to whom the Software is&#10;furnished to do so, subject to the following conditions:&#10;&#10;The above copyright notice and this permission notice shall be included in&#10;all copies or substantial portions of the Software.&#10;&#10;&#10;&#10;THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR&#10;IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,&#10;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE&#10;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER&#10;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,&#10;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN&#10;THE SOFTWARE." wrapText="true" />
<TextArea editable="false" prefHeight="200.0" prefWidth="200.0" text="Copyright (c) 2015-2019 Andreas Billmann &lt;andreas.billmann@javafx.ninja&gt;&#10;&#10;Permission is hereby granted, free of charge, to any person obtaining a copy&#10;of this software and associated documentation files (the &quot;Software&quot;), to deal&#10;in the Software without restriction, including without limitation the rights&#10;to use, copy, modify, merge, publish, distribute, sublicense, and/or sell&#10;copies of the Software, and to permit persons to whom the Software is&#10;furnished to do so, subject to the following conditions:&#10;&#10;The above copyright notice and this permission notice shall be included in&#10;all copies or substantial portions of the Software.&#10;&#10;&#10;&#10;THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR&#10;IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,&#10;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE&#10;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER&#10;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,&#10;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN&#10;THE SOFTWARE." wrapText="true" />
</children>
<opaqueInsets>
<Insets />

View File

@@ -1,5 +1,5 @@
application.name = SmartCSV.fx
application.version = 0.6
application.version = 0.9.1
# fxml views
fxml.smartcvs.view = /ninja/javafx/smartcsv/fx/smartcsv.fxml

View File

@@ -14,6 +14,7 @@
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
</rowConstraints>
<children>
<Label text="%preferences.quoteChar" />
@@ -26,6 +27,8 @@
<CheckBox fx:id="ignoreEmptyLines" mnemonicParsing="false" text="" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label text="%preferences.quoteMode" GridPane.rowIndex="4" />
<ComboBox fx:id="quoteMode" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Label text="%preferences.fileEncoding" GridPane.rowIndex="5" />
<ComboBox fx:id="fileEncoding" editable="true" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="5" />
</children>
<padding>
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0" />

View File

@@ -1,16 +1,16 @@
.list-view {
.table-view .list-view {
-fx-background-color: -fx-background;
-fx-padding: 1;
}
.list-cell {
.table-view .list-cell {
-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;
}
.list-cell:even {
.table-view .list-cell:even {
-fx-background: -fx-control-inner-background;
}
@@ -82,9 +82,14 @@
.goto-icon {
-glyph-name: "SUBDIRECTORY_ARROW_RIGHT";
-glyph-size: 16px;
}
.export-icon {
-glyph-name: "BUG";
-glyph-size: 16px;
}
/* toolbar customization based on http://fxexperience.com/2012/02/customized-segmented-toolbar-buttons/ */
#background {
@@ -149,6 +154,11 @@
-fx-fill: white;
}
.tool-bar .export-icon {
-glyph-size: 16px;
-fx-fill: white;
}
.segmented-button-bar .button {
-fx-background-color:
-darkest-black,

View File

@@ -78,6 +78,11 @@
<MaterialDesignIconView styleClass="preferences-icon" />
</graphic>
</MenuItem>
<MenuItem fx:id="exportMenuItem" disable="true" mnemonicParsing="false" onAction="#export" text="%menu.export">
<graphic>
<MaterialDesignIconView styleClass="export-icon" />
</graphic>
</MenuItem>
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" onAction="#close" text="%menu.close">
<graphic>
@@ -229,6 +234,14 @@
<MaterialDesignIconView styleClass="preferences-icon" />
</graphic>
</Button>
<Button fx:id="exportButton" disable="true" mnemonicParsing="false" onAction="#export">
<tooltip>
<Tooltip text="%menu.export" />
</tooltip>
<graphic>
<MaterialDesignIconView styleClass="export-icon" />
</graphic>
</Button>
<Button mnemonicParsing="false" onAction="#close" styleClass="last">
<tooltip>
<Tooltip text="%menu.close" />

View File

@@ -14,6 +14,7 @@ menu.preferences = Preferences
menu.delete.row = Delete row
menu.add.row = Add row
menu.goto.line = Goto line
menu.export = Export error log
title.validation.errors = Validation Errors:
@@ -40,11 +41,13 @@ preferences.delimiterChar = Delimiter character:
preferences.ignoreEmptyLines = Ignore empty lines:
preferences.surroundingSpacesNeedQuotes = Surrounding spaces need quotes:
preferences.quoteMode = Quote mode:
preferences.fileEncoding = File encoding:
# validaton messages
validation.message.not.empty = should not be empty
validation.message.integer = should be an integer
validation.message.double = should be a double
validation.message.email = should be an email address
validation.message.alphanumeric = should be alphanumeric
validation.message.groovy.exception = groovy script '{0}' throws exception: {1}
validation.message.groovy.return.null = groovy script '{0}' returns null
@@ -52,29 +55,46 @@ validation.message.min.length = has not min length of {0}
validation.message.max.length = has not max length of {0}
validation.message.date.format = is not a date of format {0}
validation.message.regexp = does not match {0}
validation.message.uniqueness = value {0} is not unique (found in line {1})
validation.message.uniqueness.multiple = value {0} is not unique (found in rows {1})
validation.message.uniqueness.single = value {0} is not unique (found in row {1})
validation.message.uri = should be an uri
validation.message.uuid = should be an uuid
validation.message.binary = should be a base64 encoded string representing binary data
validation.message.header.length = number of headers is not correct! there are {0} but there should be {1}
validation.message.header.match = header number {0} does not match "{1}" should be "{2}"
validation.message.value.of = Value {0} is not part of this list {1}
validation.rule.label.not_empty = not empty:
validation.rule.label.integer = integer:
validation.rule.label.double = double:
validation.rule.label.not_empty = not empty
validation.rule.label.integer = integer
validation.rule.label.double = double
validation.rule.label.minlength = minimum length:
validation.rule.label.maxlength = maximum length:
validation.rule.label.dateformat = date format:
validation.rule.label.alphanumeric = alphanumeric:
validation.rule.label.alphanumeric = alphanumeric
validation.rule.label.regexp = regular expression:
validation.rule.label.value_of = value in list:
validation.rule.label.groovy = groovy:
validation.rules.active = active
validation.rules.name = rule
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.header = Validation rules of column "{0}"
context.menu.edit.column.rules = Edit rules
lineNumber = Selected line:
log.header.message = {0} has {1} errors
log.message = row {0} column {1} : {2}
column = column
format.type.DEFAULT = default
format.type.EMAIL = email
format.type.URI = uri
format.type.BINARY = binary
format.type.UUID = uuid

View File

@@ -23,6 +23,7 @@ menu.preferences = Einstellungen
menu.delete.row = Zeile l\u00f6schen
menu.add.row = Zeile hinzuf\u00fcgen
menu.goto.line = Springe zur Zeile
menu.export = Export Fehlerdatei
title.validation.errors = Fehler in der Datei:
@@ -49,11 +50,13 @@ preferences.delimiterChar = Trennzeichen:
preferences.ignoreEmptyLines = Leere Zeilen ignorieren:
preferences.surroundingSpacesNeedQuotes = Leerzeichen einfassen:
preferences.quoteMode = Einfassungsmodus:
preferences.fileEncoding = Dateicodierung:
# validaton messages
validation.message.not.empty = Darf nicht leer sein.
validation.message.integer = Muss eine Zahl sein.
validation.message.double = Muss eine Gleitkommazahl sein
validation.message.email = Muss eine Email-Adresse sein
validation.message.alphanumeric = Darf nur Zahlen und Buchstaben enthalten.
validation.message.groovy.exception = groovy script '{0}' wirft folgenden Fehler: {1}
validation.message.groovy.return.null = groovy script '{0}' meldet "null"
@@ -61,15 +64,19 @@ validation.message.min.length = Hat nicht die minimale L\u00e4nge von {0}
validation.message.max.length = Hat nicht die maximale L\u00e4nge von {0}
validation.message.date.format = Das Datumsformat entspricht nicht {0}
validation.message.regexp = entspricht nicht dem regul\u00e4ren Ausdruck {0}
validation.message.uniqueness = Wert {0} ist nicht einmalig (gefunden in Zeile {1})
validation.message.uniqueness.multiple = Wert {0} ist nicht einmalig (gefunden in den Zeilen {1})
validation.message.uniqueness.single = Wert {0} ist nicht einmalig (gefunden in Zeile {1})
validation.message.uri = Muss eine URI sein
validation.message.uuid = Muss eine UUID sein
validation.message.binary = Muss ein base64 encoded Text sein, der bin\u00e4re Daten enth\u00e4lt
validation.message.header.length = Anzahl der \u00dcberschriften ist nicht korrekt! Es sind {0} aber es sollten {1} sein
validation.message.header.match = \u00dcberschrift in Spalte {0} stimmt nicht. "{1}" sollte "{3}" sein
validation.message.value.of = Der Wert {0} ist nicht in der Liste {1} enthalten
validation.rule.label.not_empty = Nicht leer:
validation.rule.label.integer = Zahl:
validation.rule.label.double = Gleitkommazahl:
validation.rule.label.not_empty = Nicht leer
validation.rule.label.integer = Zahl
validation.rule.label.double = Gleitkommazahl
validation.rule.label.minlength = Minimale L\u00e4nge:
validation.rule.label.maxlength = Maximale L\u00e4nge:
validation.rule.label.dateformat = Datumsformat:
@@ -80,7 +87,9 @@ validation.rule.label.groovy = groovy:
validation.rules.active = Aktiv
validation.rules.name = Regel
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.header = Pr\u00fcfregeln f\u00fcr die Spalte "{0}"
@@ -88,3 +97,14 @@ dialog.validation.rules.header = Pr\u00fcfregeln f\u00fcr die Spalte "{0}"
context.menu.edit.column.rules = Pr\u00fcfregeln bearbeiten
lineNumber = Ausgew\u00e4hlte Zeile:
log.header.message = {0} hat {1} Fehler
log.message = Zeile {0} Spalte {1} : {2}
column = Spalte
format.type.DEFAULT = Standard
format.type.EMAIL = Email
format.type.URI = URI
format.type.BINARY = Bin\u00e4r
format.type.UUID = UUID

View File

@@ -1,73 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import org.fxmisc.richtext.CodeArea?>
<?import java.net.URL?>
<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.101" xmlns:fx="http://javafx.com/fxml/1">
<columnConstraints>
<ColumnConstraints halignment="CENTER" hgrow="NEVER" maxWidth="50.0" prefWidth="50.0" />
<ColumnConstraints hgrow="NEVER" />
<ColumnConstraints hgrow="ALWAYS" />
</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" 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" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="%validation.rule.label.not_empty" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text="%validation.rule.label.integer" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label text="%validation.rule.label.double" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label text="%validation.rule.label.minlength" GridPane.columnIndex="1" GridPane.rowIndex="6" />
<Label text="%validation.rule.label.maxlength" GridPane.columnIndex="1" GridPane.rowIndex="7" />
<Label text="%validation.rule.label.dateformat" GridPane.columnIndex="1" GridPane.rowIndex="8" />
<Label text="%validation.rule.label.alphanumeric" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Label text="%validation.rule.label.regexp" GridPane.columnIndex="1" GridPane.rowIndex="9" />
<Label text="%validation.rule.label.value_of" GridPane.columnIndex="1" GridPane.rowIndex="10" />
<Label text="%validation.rule.label.groovy" GridPane.columnIndex="1" GridPane.rowIndex="11" />
<Label text="%validation.rule.label.unique" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<CheckBox fx:id="enableNotEmptyRule" mnemonicParsing="false" GridPane.rowIndex="1" />
<CheckBox fx:id="notEmptyRuleCheckBox" mnemonicParsing="false" GridPane.columnIndex="2" GridPane.rowIndex="1" />
<CheckBox fx:id="enableIntegerRule" mnemonicParsing="false" GridPane.rowIndex="2" />
<CheckBox fx:id="integerRuleCheckBox" mnemonicParsing="false" GridPane.columnIndex="2" GridPane.rowIndex="2" />
<CheckBox fx:id="enableDoubleRule" mnemonicParsing="false" GridPane.rowIndex="3" />
<CheckBox fx:id="doublerRuleCheckBox" mnemonicParsing="false" GridPane.columnIndex="2" GridPane.rowIndex="3" />
<CheckBox fx:id="enableAlphanumericRule" mnemonicParsing="false" GridPane.rowIndex="4" />
<CheckBox fx:id="alphanumericRuleCheckBox" mnemonicParsing="false" GridPane.columnIndex="2" GridPane.rowIndex="4" />
<CheckBox fx:id="enableUniqueRule" mnemonicParsing="false" GridPane.rowIndex="5" />
<CheckBox fx:id="uniqueRuleCheckBox" mnemonicParsing="false" GridPane.columnIndex="2" 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" />
<Label style="-fx-font-weight: bold;" text="%validation.rules.name" GridPane.columnIndex="1" />
<Label style="-fx-font-weight: bold;" text="%validation.rules.value" GridPane.columnIndex="2" />
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.Spinner?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import org.fxmisc.richtext.CodeArea?>
</children>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<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.76-ea" xmlns:fx="http://javafx.com/fxml/1">
<columnConstraints>
<ColumnConstraints halignment="LEFT" hgrow="NEVER" />
<ColumnConstraints halignment="LEFT" hgrow="ALWAYS" />
<ColumnConstraints halignment="LEFT" hgrow="NEVER" />
<ColumnConstraints halignment="LEFT" hgrow="ALWAYS" />
</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" valignment="CENTER" 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" valignment="TOP" vgrow="ALWAYS" />
<RowConstraints />
</rowConstraints>
<children>
<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" />
<ComboBox fx:id="typeComboBox" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.halignment="LEFT" GridPane.hgrow="ALWAYS" />
<ComboBox fx:id="formatComboBox" prefWidth="150.0" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="1" visible="false" />
<TextField fx:id="formatTextField" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="1" visible="false" />
<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" />
<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" />
<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" />
<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" />
<CheckBox fx:id="enableGroovyRule" mnemonicParsing="false" text="%validation.rule.label.groovy" GridPane.rowIndex="7">
<GridPane.margin>
<Insets top="8.0" />
</GridPane.margin>
</CheckBox>
<CodeArea fx:id="groovyRuleTextArea" minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="7">
<GridPane.margin>
<Insets top="8.0" />
</GridPane.margin>
</CodeArea>
<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>
<URL value="@/ninja/javafx/smartcsv/fx/smartcsv.css" />
</stylesheets>

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -0,0 +1,56 @@
/*
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.preferences;
import org.junit.jupiter.api.Test;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.*;
public class CharsetHelperTest {
@Test
public void getCharsetName_known_charset() {
String result = CharsetHelper.getCharsetName("UTF-16");
assertEquals(StandardCharsets.UTF_16.name(), result);
}
@Test
public void getCharsetName_unknown_charset() {
String result = CharsetHelper.getCharsetName("foobar");
assertEquals(StandardCharsets.UTF_8.name(), result);
}
@Test
public void getCharsetName_null_charset() {
String result = CharsetHelper.getCharsetName(null);
assertEquals(StandardCharsets.UTF_8.name(), result);
}
}

View File

@@ -2,7 +2,7 @@
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -28,6 +28,7 @@ package ninja.javafx.smartcsv.validation;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -81,7 +82,7 @@ public class HeaderValidationTest {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Before
public void initialize() {
sut = new Validator(config);
sut = new Validator(config, new TestColumnValueProvider());
}
@@ -115,7 +116,21 @@ public class HeaderValidationTest {
}
public static String json(String... headerNames) {
return "{\"headers\":{\"list\":[" + asList(headerNames).stream().collect(joining(", ")) + "]}}";
String json = "{ \"fields\": [";
for (String headerName: headerNames) {
json += "{\"name\" : \""+headerName+"\" },";
}
if (headerNames != null && headerNames.length > 0) {
json = json.substring(0, json.length() - 1);
}
json += "]}";
return json;
}
}

View File

@@ -0,0 +1,18 @@
package ninja.javafx.smartcsv.validation;
import ninja.javafx.smartcsv.fx.table.model.ColumnValueProvider;
/**
* @author abi
*/
public class TestColumnValueProvider implements ColumnValueProvider {
@Override
public String getValue(int row, String column) {
return null;
}
@Override
public int getNumberOfRows() {
return 0;
}
}

View File

@@ -2,6 +2,7 @@ package ninja.javafx.smartcsv.validation;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -25,8 +26,7 @@ public class ValidatorTest {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// parameters
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private ValidationConfiguration config;
private String column;
private String config;
private String value;
private Boolean expectedResult;
private ValidationMessage expectedError;
@@ -42,14 +42,10 @@ public class ValidatorTest {
// parameterized constructor
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public ValidatorTest(String config,
String column,
String value,
Boolean expectedResult,
ValidationMessage expectedError) {
System.out.println(config);
Gson gson = new GsonBuilder().create();
this.config = gson.fromJson(config, ValidationConfiguration.class);
this.column = column;
this.config = config;
this.value = value;
this.expectedResult = expectedResult;
this.expectedError = expectedError;
@@ -61,7 +57,9 @@ public class ValidatorTest {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Before
public void initialize() {
sut = new Validator(config);
Gson gson = new GsonBuilder().create();
ValidationConfiguration validationConfiguration = gson.fromJson(config, ValidationConfiguration.class);
sut = new Validator(validationConfiguration, new TestColumnValueProvider());
}
@@ -70,10 +68,14 @@ public class ValidatorTest {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Test
public void validation() {
System.out.println(column + " " + value + " " + expectedResult + " " + expectedError);
System.out.println("===================================================");
System.out.println(config);
System.out.println(value + " " + expectedResult + " " + expectedError);
System.out.println("===================================================\n");
// execution
ValidationError result = sut.isValid(0, column, value);
ValidationError result = sut.isValid(0, "column", value);
// assertion
assertThat(result == null, is(expectedResult));
@@ -88,42 +90,80 @@ public class ValidatorTest {
@Parameterized.Parameters
public static Collection validationConfigurations() {
return asList(new Object[][] {
{ json("column", "not empty", true), "column", "value", true, null },
{ json("column", "not empty", true), "column", "", false, new ValidationMessage("validation.message.not.empty") },
{ json("column", "not empty", true), "column", null, false, new ValidationMessage("validation.message.not.empty") },
{ json("column", "integer", true), "column", "999", true, null },
{ json("column", "integer", true), "column", "a", false, new ValidationMessage("validation.message.integer") },
{ json("column", "double", true), "column", "999", true, null },
{ json("column", "double", true), "column", "999.000", true, null },
{ json("column", "double", true), "column", "a", false, new ValidationMessage("validation.message.double") },
{ json("column", "minlength", 2), "column", "12", true, null },
{ json("column", "minlength", 2), "column", "1", false, new ValidationMessage("validation.message.min.length", "2") },
{ json("column", "maxlength", 2), "column", "12", true, null },
{ json("column", "maxlength", 2), "column", "123", false, new ValidationMessage("validation.message.max.length", "2") },
{ json("column", "date", "yyyyMMdd"), "column", "20151127", true, null },
{ json("column", "date", "yyyyMMdd"), "column", "27.11.2015", false, new ValidationMessage("validation.message.date.format", "yyyyMMdd") },
{ json("column", "alphanumeric", true), "column", "abcABC123", true, null },
{ json("column", "alphanumeric", true), "column", "-abcABC123", false, new ValidationMessage("validation.message.alphanumeric") },
{ json("column", "regexp", "[a-z]*"), "column", "abc", true, null },
{ json("column", "regexp", "[a-z]*"), "column", "abcA", false, new ValidationMessage("validation.message.regexp", "[a-z]*") },
{ json("column", "groovy", "value.contains('a')? 'true' : 'no a inside'"), "column", "abcdef", true, null },
{ json("column", "groovy", "value.contains('a')? 'true' : 'no a inside'"), "column", "bcdefg", false, new ValidationMessage("no a inside") },
{ json("column", "value of", asList("a","b","c","d","e")), "column", "c", true, null },
{ json("column", "value of", asList("a","b","c","d","e")), "column", "f", false, new ValidationMessage("validation.message.value.of", "f", "a, b, c, d, e") },
{ constraintsJSON("string", "required", true), "value", true, null },
{ constraintsJSON("string", "required", true), "", false, new ValidationMessage("validation.message.not.empty") },
{ constraintsJSON("string", "required", true), null, false, new ValidationMessage("validation.message.not.empty") },
{ constraintsJSON("integer", null, true), "999", true, null },
{ constraintsJSON("integer", null, true), "a", false, new ValidationMessage("validation.message.integer") },
{ constraintsJSON("number", null, true), "999", true, null },
{ constraintsJSON("number", null, true), "999.000", true, null },
{ constraintsJSON("number", null, true), "a", false, new ValidationMessage("validation.message.double") },
{ constraintsJSON("string", "minLength", 2), "12", true, null },
{ constraintsJSON("string", "minLength", 2), "1", false, new ValidationMessage("validation.message.min.length", "2") },
{ constraintsJSON("string", "maxLength", 2), "12", true, null },
{ constraintsJSON("string", "maxLength", 2), "123", false, new ValidationMessage("validation.message.max.length", "2") },
{ constraintsJSON("string", "pattern", "[a-z]*"), "abc", true, null },
{ constraintsJSON("string", "pattern", "[a-z]*"), "abcA", false, new ValidationMessage("validation.message.regexp", "[a-z]*") },
{ constraintsJSON("string", "enum", asList("a","b","c","d","e")), "c", true, null },
{ constraintsJSON("string", "enum", asList("a","b","c","d","e")), "f", false, new ValidationMessage("validation.message.value.of", "f", "a, b, c, d, e") },
{ formatJSON("string", null), "some string", true, null },
{ formatJSON("string", "email"), "test@javafx.ninja", true, null },
{ formatJSON("string", "email"), "wrong email", false, new ValidationMessage("validation.message.email") },
{ formatJSON("string", "uri"), "http://www.javafx.ninja", true, null },
{ formatJSON("string", "uri"), "!$%&/()", false, new ValidationMessage("validation.message.uri") },
{ formatJSON("string", "binary"), "dGVzdA==", true, null },
{ formatJSON("string", "binary"), "no binary", false, new ValidationMessage("validation.message.binary") },
{ formatJSON("string", "uuid"), "6ba7b810-9dad-11d1-80b4-00c04fd430c8", true, null },
{ formatJSON("string", "uuid"), "no uuid", false, new ValidationMessage("validation.message.uuid") },
{ formatJSON("date", null), "2015-11-27", true, null },
{ formatJSON("date", null), "27.11.2015", false, new ValidationMessage("validation.message.date.format", "yyyy-MM-dd") },
{ formatJSON("date", "yyyyMMdd"), "20151127", true, null },
{ formatJSON("date", "yyyyMMdd"), "27.11.2015", false, new ValidationMessage("validation.message.date.format", "yyyyMMdd") },
{ customAttributeJSON( "groovy", "value.contains('a')? 'true' : 'no a inside'"), "abcdef", true, null },
{ customAttributeJSON( "groovy", "value.contains('a')? 'true' : 'no a inside'"), "bcdefg", false, new ValidationMessage("no a inside") },
});
}
public static String json(String column, String rule, Object value) {
String json = "{\"headers\": { \"list\": [\""+column+"\"]},\"columns\":{\"" + column + "\":{\"" + rule + "\":";
if (value instanceof String) {
json += "\""+ value + "\"";
} else if (value instanceof List) {
List<String> list = (List<String>)value;
json += "[" + list.stream().collect(joining(", ")) + "]";
} else {
json += value;
public static String constraintsJSON(String type, String constraint, Object value) {
String json = "{\"fields\": [ { \"name\": \"column\", \"type\" : \"" + type +"\"";
if (constraint != null) {
json += ", \"constraints\": { \"" + constraint + "\":";
if (value instanceof String) {
json += "\"" + value + "\"";
} else if (value instanceof List) {
List<String> list = (List<String>) value;
json += "[" + list.stream().collect(joining(", ")) + "]";
} else {
json += value;
}
json += "}";
}
json += "}}}";
json += "}]}";
return json;
}
public static String formatJSON(String type, String format) {
String json = "{\"fields\": [ { \"name\": \"column\", \"type\" : \"" + type +"\"";
if (format != null) {
json += ", \"format\": \"" + format + "\"";
}
json += "}]}";
return json;
}
public static String customAttributeJSON(String attribute, String value) {
String json = "{\"fields\": [ { \"name\": \"column\", \"type\" : \"string\"";
if (attribute != null) {
json += ", \""+attribute+"\": \"" + value + "\"";
}
json += "}]}";
return json;
}
}