mirror of
https://github.com/frosch95/SmartCSV.fx.git
synced 2026-04-11 21:48:22 +02:00
Compare commits
48 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 18335b9280 | |||
| 4e216b4792 | |||
| 3980e2951f | |||
| 1b39c9a08e | |||
| 0db16c0328 | |||
| bec55b6119 | |||
| 7dac3ce011 | |||
| 449f929f08 | |||
| 9e3561fedb | |||
| 9c1b110bfd | |||
| 398219a897 | |||
|
|
a79dde5421 | ||
| fb234fa50e | |||
| 43856dffab | |||
| 8cecca2172 | |||
|
|
35f395d44a | ||
|
|
9961373d76 | ||
|
|
fd6938fa80 | ||
|
|
78f3f5909e | ||
|
|
d572dcdeed | ||
| af6ce56f71 | |||
| 2f692352b7 | |||
| 5b59c76200 | |||
| 7e40daa1e5 | |||
| 2da843e1e2 | |||
| d1ffd09941 | |||
|
|
4c29d29bf5 | ||
|
|
c4f91d94f1 | ||
| 8c43c5a1de | |||
| 187002997c | |||
| aa7e38c613 | |||
| 13a41468d4 | |||
| f41979960b | |||
| a7fce854ca | |||
| 4f40418aea | |||
| d7c821d1fe | |||
|
|
49f8003f97 | ||
|
|
5f8383c6a1 | ||
| 03dcf20229 | |||
| 543125812a | |||
| c52f6c0bc8 | |||
| 422bd73bad | |||
| e6672834fb | |||
| 8e0ea66552 | |||
|
|
bf476308a2 | ||
|
|
cf9203549b | ||
|
|
02b102cfb2 | ||
| 8e0e1c41c3 |
21
.github/workflows/build-and-test.yml
vendored
Normal file
21
.github/workflows/build-and-test.yml
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
name: Build and Test with Gradle
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Set up JDK 17
|
||||||
|
uses: actions/setup-java@v1
|
||||||
|
with:
|
||||||
|
java-version: 17
|
||||||
|
- name: Grant execute permission for gradlew
|
||||||
|
run: chmod +x gradlew
|
||||||
|
- name: Build with Gradle
|
||||||
|
run: ./gradlew build
|
||||||
|
- name: Test with Gradle
|
||||||
|
run: ./gradlew test
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
------------------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2019 Andreas Billmann <andreas.billmann@javafx.ninja>
|
Copyright (c) 2015-2021 Andreas Billmann <andreas.billmann@javafx.ninja>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# SmartCSV.fx
|
# SmartCSV.fx
|
||||||
|
    
|
||||||
## Description
|
## 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.
|
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.
|
||||||
|
|
||||||
@@ -14,7 +15,7 @@ even in a "normal" CSV editor. So I decided to write this simple JavaFX applicat
|
|||||||
|
|
||||||
[Wiki & Documentation](https://github.com/frosch95/SmartCSV.fx/wiki)
|
[Wiki & Documentation](https://github.com/frosch95/SmartCSV.fx/wiki)
|
||||||
|
|
||||||
binary distribution of the [latest release (0.9.1)](https://github.com/frosch95/SmartCSV.fx/releases/download/0.9.1/SmartCSV.fx-0.9.1-SNAPSHOT.zip)
|
binary distribution of the [latest release (1.4.0)](https://github.com/frosch95/SmartCSV.fx/releases/download/1.4.0/SmartCSV.fx-1.4.0.zip)
|
||||||
|
|
||||||
## Talks
|
## Talks
|
||||||
[Introduction](http://javafx.ninja/talks/introduction/)
|
[Introduction](http://javafx.ninja/talks/introduction/)
|
||||||
@@ -23,7 +24,7 @@ binary distribution of the [latest release (0.9.1)](https://github.com/frosch95/
|
|||||||
### The MIT License (MIT)
|
### The MIT License (MIT)
|
||||||
|
|
||||||
|
|
||||||
Copyright (c) 2015-2016 Andreas Billmann <andreas.billmann@javafx.ninja>
|
Copyright (c) 2015-2020 Andreas Billmann <andreas.billmann@javafx.ninja>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
64
build.gradle
64
build.gradle
@@ -3,37 +3,61 @@ plugins {
|
|||||||
id 'java'
|
id 'java'
|
||||||
id 'groovy'
|
id 'groovy'
|
||||||
id 'application'
|
id 'application'
|
||||||
id 'org.openjfx.javafxplugin' version '0.0.8'
|
id 'org.openjfx.javafxplugin' version '0.0.14'
|
||||||
|
id 'com.github.ben-manes.versions' version '0.48.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
jcenter()
|
}
|
||||||
|
|
||||||
|
apply plugin: 'java'
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain {
|
||||||
|
languageVersion = JavaLanguageVersion.of(25)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
javafx {
|
javafx {
|
||||||
version = "13"
|
version = "25"
|
||||||
modules = [ 'javafx.controls', 'javafx.fxml' ]
|
modules = [ 'javafx.controls', 'javafx.fxml' ]
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
// updated testing libraries
|
||||||
testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3'
|
testImplementation group: 'org.junit.platform', name: 'junit-platform-launcher', version: '6.0.0'
|
||||||
compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '3.0.0-beta-3'
|
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '6.0.0'
|
||||||
compile group: 'org.springframework', name:'spring-context', version: '5.2.0.RELEASE'
|
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '6.0.0'
|
||||||
compile group: 'net.sf.supercsv', name: 'super-csv', version: '2.4.0'
|
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '6.0.0'
|
||||||
compile group: 'commons-validator', name: 'commons-validator', version: '1.6'
|
testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '3.0'
|
||||||
compile group: 'de.jensd', name: 'fontawesomefx-commons', version: '11.0'
|
testImplementation group: 'org.mockito', name: 'mockito-core', version:'5.20.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'
|
// runtime libraries - bumped to recent stable versions where compatible
|
||||||
compile group: 'de.jensd', name: 'fontawesomefx-materialicons', version: '2.2.0-11'
|
implementation group: 'org.apache.groovy', name: 'groovy', version: '5.0.2'
|
||||||
compile group: 'org.controlsfx', name: 'controlsfx', version: '11.0.0'
|
implementation group: 'org.springframework', name: 'spring-context', version: '6.2.12'
|
||||||
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
|
implementation group: 'de.siegmar', name: 'fastcsv', version: '4.1.0'
|
||||||
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.0'
|
implementation group: 'commons-validator', name: 'commons-validator', version: '1.10.0'
|
||||||
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.0'
|
implementation group: 'de.jensd', name: 'fontawesomefx-commons', version: '9.1.2'
|
||||||
compile group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.10.2'
|
implementation group: 'de.jensd', name: 'fontawesomefx-fontawesome', version: '4.7.0-9.1.2'
|
||||||
|
implementation group: 'de.jensd', name: 'fontawesomefx-materialdesignfont', version: '2.0.26-9.1.2'
|
||||||
|
implementation group: 'de.jensd', name: 'fontawesomefx-materialicons', version: '2.2.0-9.1.2'
|
||||||
|
implementation group: 'org.controlsfx', name: 'controlsfx', version: '11.2.2'
|
||||||
|
implementation group: 'com.google.code.gson', name: 'gson', version: '2.13.2'
|
||||||
|
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.25.2'
|
||||||
|
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.25.2'
|
||||||
|
implementation group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.11.6'
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'ninja.javafx'
|
group 'ninja.javafx'
|
||||||
version '0.9.2-SNAPSHOT'
|
version '1.5.0'
|
||||||
mainClassName = 'ninja.javafx.smartcsv.Main'
|
|
||||||
|
application {
|
||||||
|
mainClass = 'ninja.javafx.smartcsv.Main'
|
||||||
|
applicationDefaultJvmArgs = ["--enable-native-access=javafx.graphics"]
|
||||||
|
}
|
||||||
|
|||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -1,3 +1,29 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2015-2021 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;
|
package ninja.javafx.smartcsv;
|
||||||
|
|
||||||
import ninja.javafx.smartcsv.fx.SmartCSV;
|
import ninja.javafx.smartcsv.fx.SmartCSV;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -26,20 +26,29 @@
|
|||||||
|
|
||||||
package ninja.javafx.smartcsv.csv;
|
package ninja.javafx.smartcsv.csv;
|
||||||
|
|
||||||
import org.supercsv.prefs.CsvPreference;
|
import ninja.javafx.smartcsv.preferences.Preferences;
|
||||||
|
|
||||||
|
import static ninja.javafx.smartcsv.preferences.Preferences.defaultPreferences;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class CSVConfigurable {
|
public class CSVConfigurable {
|
||||||
|
|
||||||
protected CsvPreference csvPreference;
|
protected Preferences csvPreference;
|
||||||
|
|
||||||
|
protected String fileEncoding;
|
||||||
|
|
||||||
public CSVConfigurable() {
|
public CSVConfigurable() {
|
||||||
csvPreference = CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE;
|
csvPreference = defaultPreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCsvPreference(CsvPreference csvPreference) {
|
public void setCsvPreference(Preferences csvPreference) {
|
||||||
this.csvPreference = csvPreference;
|
this.csvPreference = csvPreference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFileEncoding(String fileEncoding) {
|
||||||
|
this.fileEncoding = fileEncoding;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -26,15 +26,14 @@
|
|||||||
|
|
||||||
package ninja.javafx.smartcsv.csv;
|
package ninja.javafx.smartcsv.csv;
|
||||||
|
|
||||||
|
import de.siegmar.fastcsv.reader.CsvReader;
|
||||||
|
import de.siegmar.fastcsv.reader.NamedCsvRecord;
|
||||||
import ninja.javafx.smartcsv.FileReader;
|
import ninja.javafx.smartcsv.FileReader;
|
||||||
import ninja.javafx.smartcsv.fx.table.model.CSVModel;
|
import ninja.javafx.smartcsv.fx.table.model.CSVModel;
|
||||||
import ninja.javafx.smartcsv.fx.table.model.CSVRow;
|
|
||||||
import org.supercsv.io.CsvMapReader;
|
|
||||||
import org.supercsv.io.ICsvMapReader;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reads the csv file and stores the values in csv model
|
* reads the csv file and stores the values in csv model
|
||||||
@@ -46,30 +45,44 @@ public class CSVFileReader extends CSVConfigurable implements FileReader<CSVMode
|
|||||||
@Override
|
@Override
|
||||||
public void read(File file) throws IOException {
|
public void read(File file) throws IOException {
|
||||||
|
|
||||||
ICsvMapReader mapReader = null;
|
System.out.println(csvPreference);
|
||||||
try {
|
try (var csv = getNamedCsvReader(file)) {
|
||||||
mapReader = new CsvMapReader(new java.io.FileReader(file.getAbsoluteFile()), csvPreference);
|
|
||||||
model = new CSVModel();
|
model = new CSVModel();
|
||||||
|
|
||||||
// the header columns are used as the keys to the Map
|
// the header columns are used as the keys to the Map
|
||||||
String[] header = mapReader.getHeader(true);
|
var firstRow = csv.stream().findFirst();
|
||||||
|
|
||||||
|
if (firstRow.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var header = firstRow.get().getHeader().toArray(String[]::new);
|
||||||
model.setHeader(header);
|
model.setHeader(header);
|
||||||
|
|
||||||
Map<String, String> customerMap;
|
csv.forEach(csvRow -> {
|
||||||
while ((customerMap = mapReader.read(header)) != null) {
|
var row = model.addRow();
|
||||||
CSVRow row = model.addRow();
|
|
||||||
for (String column : header) {
|
for (String column : header) {
|
||||||
model.addValue(row, column, customerMap.get(column));
|
model.addValue(row, column, csvRow.getField(column));
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
} finally {
|
} catch (IOException ex) {
|
||||||
if (mapReader != null) {
|
// TODO perhaps a custom NinjaException that can properly identify and localize the exception message
|
||||||
mapReader.close();
|
// is this a file not found? is this a corrupt csv? etc
|
||||||
}
|
throw new IOException("Failed to read " + file + ": " + ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CsvReader<NamedCsvRecord> getNamedCsvReader(File file) throws IOException {
|
||||||
|
var builder = CsvReader.builder()
|
||||||
|
.fieldSeparator(csvPreference.delimiterChar());
|
||||||
|
if (csvPreference.quoteChar() != null) {
|
||||||
|
builder.quoteCharacter(csvPreference.quoteChar());
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.ofNamedCsvRecord(file.toPath(), Charset.forName(fileEncoding));
|
||||||
|
}
|
||||||
|
|
||||||
public CSVModel getContent() {
|
public CSVModel getContent() {
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -26,17 +26,17 @@
|
|||||||
|
|
||||||
package ninja.javafx.smartcsv.csv;
|
package ninja.javafx.smartcsv.csv;
|
||||||
|
|
||||||
|
import de.siegmar.fastcsv.writer.CsvWriter;
|
||||||
|
import de.siegmar.fastcsv.writer.QuoteStrategies;
|
||||||
import ninja.javafx.smartcsv.fx.table.model.CSVModel;
|
import ninja.javafx.smartcsv.fx.table.model.CSVModel;
|
||||||
import ninja.javafx.smartcsv.fx.table.model.CSVRow;
|
import ninja.javafx.smartcsv.fx.table.model.CSVRow;
|
||||||
import org.supercsv.io.CsvMapWriter;
|
|
||||||
import org.supercsv.io.ICsvMapWriter;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static java.util.stream.Collectors.toMap;
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* filewriter for the csv
|
* filewriter for the csv
|
||||||
@@ -51,21 +51,22 @@ public class CSVFileWriter extends CSVConfigurable implements ninja.javafx.smart
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(File filename) throws IOException {
|
public void write(File filename) throws IOException {
|
||||||
ICsvMapWriter mapWriter = null;
|
try (var writer = getCsvWriter(filename)){
|
||||||
try {
|
writer.writeRecord(model.getHeader());
|
||||||
mapWriter = new CsvMapWriter(new FileWriter(filename.getAbsolutePath()), csvPreference);
|
|
||||||
mapWriter.writeHeader(model.getHeader());
|
|
||||||
|
|
||||||
for(CSVRow row: model.getRows()) {
|
for(CSVRow row: model.getRows()) {
|
||||||
Map<String, String> columns = convertMapFromModel(row);
|
writer.writeRecord(convertMapFromModel(row));
|
||||||
mapWriter.write(columns, model.getHeader());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
}
|
||||||
if( mapWriter != null ) {
|
|
||||||
mapWriter.close();
|
private CsvWriter getCsvWriter(File filename) throws IOException {
|
||||||
}
|
var writer = CsvWriter.builder().fieldSeparator(csvPreference.delimiterChar());
|
||||||
|
if (csvPreference.quoteChar() != null) {
|
||||||
|
writer.quoteCharacter(csvPreference.quoteChar());
|
||||||
|
writer.quoteStrategy(QuoteStrategies.ALWAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return writer.build(filename.toPath(), Charset.forName(fileEncoding));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -73,13 +74,8 @@ public class CSVFileWriter extends CSVConfigurable implements ninja.javafx.smart
|
|||||||
* @param row the row to convert
|
* @param row the row to convert
|
||||||
* @return a simple map for the supercvs writer
|
* @return a simple map for the supercvs writer
|
||||||
*/
|
*/
|
||||||
private Map<String, String> convertMapFromModel(CSVRow row) {
|
private List<String> convertMapFromModel(CSVRow row) {
|
||||||
return row.getColumns().entrySet().stream()
|
return row.getColumns().values().stream().map(v -> v.get().getValue())
|
||||||
.collect(
|
.collect(toList());
|
||||||
toMap(
|
|
||||||
Map.Entry::getKey,
|
|
||||||
e -> e.getValue().getValue().getValue() != null ? e.getValue().getValue().getValue() : ""
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,34 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2015-2021 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.export;
|
package ninja.javafx.smartcsv.export;
|
||||||
|
|
||||||
import javafx.concurrent.Service;
|
import javafx.concurrent.Service;
|
||||||
import javafx.concurrent.Task;
|
import javafx.concurrent.Task;
|
||||||
import ninja.javafx.smartcsv.fx.table.model.CSVModel;
|
import ninja.javafx.smartcsv.fx.table.model.CSVModel;
|
||||||
import ninja.javafx.smartcsv.validation.ValidationError;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
|||||||
@@ -1,3 +1,29 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2015-2021 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.files;
|
package ninja.javafx.smartcsv.files;
|
||||||
|
|
||||||
import javafx.beans.property.BooleanProperty;
|
import javafx.beans.property.BooleanProperty;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -30,6 +30,7 @@ import javafx.application.Application;
|
|||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.image.Image;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import ninja.javafx.smartcsv.fx.about.AboutController;
|
import ninja.javafx.smartcsv.fx.about.AboutController;
|
||||||
import org.springframework.context.annotation.*;
|
import org.springframework.context.annotation.*;
|
||||||
@@ -84,9 +85,12 @@ public class SmartCSV extends Application {
|
|||||||
private void showUI(Stage primaryStage, String name, String version) {
|
private void showUI(Stage primaryStage, String name, String version) {
|
||||||
SmartCSVController smartCVSController = appContext.getBean(SmartCSVController.class);
|
SmartCSVController smartCVSController = appContext.getBean(SmartCSVController.class);
|
||||||
Scene scene = new Scene((Parent) smartCVSController.getView());
|
Scene scene = new Scene((Parent) smartCVSController.getView());
|
||||||
|
var defaultThemeCss = getClass().getResource("/ninja/javafx/smartcsv/fx/smartcsv.css").toExternalForm();
|
||||||
|
scene.getRoot().getStylesheets().add(defaultThemeCss);
|
||||||
|
|
||||||
primaryStage.setScene(scene);
|
primaryStage.setScene(scene);
|
||||||
primaryStage.setTitle(String.format("%s %s", name, version));
|
primaryStage.setTitle(String.format("%s %s", name, version));
|
||||||
|
primaryStage.getIcons().add(new Image(SmartCSV.class.getResourceAsStream("/ninja/javafx/smartcsv/icon/logo.png")));
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
primaryStage.setMaximized(true);
|
primaryStage.setMaximized(true);
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
package ninja.javafx.smartcsv.fx;
|
package ninja.javafx.smartcsv.fx;
|
||||||
|
|
||||||
|
import javafx.beans.InvalidationListener;
|
||||||
import javafx.beans.binding.Bindings;
|
import javafx.beans.binding.Bindings;
|
||||||
import javafx.collections.ListChangeListener;
|
import javafx.collections.ListChangeListener;
|
||||||
import javafx.collections.WeakListChangeListener;
|
import javafx.collections.WeakListChangeListener;
|
||||||
@@ -35,6 +36,8 @@ import javafx.event.EventHandler;
|
|||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.input.Dragboard;
|
||||||
|
import javafx.scene.input.TransferMode;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
@@ -51,23 +54,23 @@ import ninja.javafx.smartcsv.fx.table.ValidationCellFactory;
|
|||||||
import ninja.javafx.smartcsv.fx.table.model.CSVModel;
|
import ninja.javafx.smartcsv.fx.table.model.CSVModel;
|
||||||
import ninja.javafx.smartcsv.fx.table.model.CSVRow;
|
import ninja.javafx.smartcsv.fx.table.model.CSVRow;
|
||||||
import ninja.javafx.smartcsv.fx.table.model.CSVValue;
|
import ninja.javafx.smartcsv.fx.table.model.CSVValue;
|
||||||
|
import ninja.javafx.smartcsv.fx.util.JavaFxUtils;
|
||||||
import ninja.javafx.smartcsv.fx.util.LoadFileService;
|
import ninja.javafx.smartcsv.fx.util.LoadFileService;
|
||||||
import ninja.javafx.smartcsv.fx.util.SaveFileService;
|
import ninja.javafx.smartcsv.fx.util.SaveFileService;
|
||||||
import ninja.javafx.smartcsv.fx.validation.ValidationEditorController;
|
import ninja.javafx.smartcsv.fx.validation.ValidationEditorController;
|
||||||
import ninja.javafx.smartcsv.preferences.PreferencesFileReader;
|
import ninja.javafx.smartcsv.preferences.*;
|
||||||
import ninja.javafx.smartcsv.preferences.PreferencesFileWriter;
|
|
||||||
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
|
|
||||||
import ninja.javafx.smartcsv.validation.ValidationError;
|
import ninja.javafx.smartcsv.validation.ValidationError;
|
||||||
import ninja.javafx.smartcsv.validation.ValidationFileReader;
|
import ninja.javafx.smartcsv.validation.ValidationFileReader;
|
||||||
import ninja.javafx.smartcsv.validation.ValidationFileWriter;
|
import ninja.javafx.smartcsv.validation.ValidationFileWriter;
|
||||||
|
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.supercsv.prefs.CsvPreference;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
@@ -77,6 +80,7 @@ import static javafx.application.Platform.exit;
|
|||||||
import static javafx.application.Platform.runLater;
|
import static javafx.application.Platform.runLater;
|
||||||
import static javafx.beans.binding.Bindings.*;
|
import static javafx.beans.binding.Bindings.*;
|
||||||
import static javafx.scene.layout.AnchorPane.*;
|
import static javafx.scene.layout.AnchorPane.*;
|
||||||
|
import static ninja.javafx.smartcsv.preferences.Preferences.defaultPreferences;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* main controller of the application
|
* main controller of the application
|
||||||
@@ -84,6 +88,7 @@ import static javafx.scene.layout.AnchorPane.*;
|
|||||||
@Component
|
@Component
|
||||||
public class SmartCSVController extends FXMLController {
|
public class SmartCSVController extends FXMLController {
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// constants
|
// constants
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -93,6 +98,13 @@ public class SmartCSVController extends FXMLController {
|
|||||||
".SmartCSV.fx" +
|
".SmartCSV.fx" +
|
||||||
File.separator + "" +
|
File.separator + "" +
|
||||||
"preferences.json");
|
"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_TEXT = "CSV files (*.csv)";
|
||||||
public static final String CSV_FILTER_EXTENSION = "*.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_TEXT = "JSON files (*.json)";
|
||||||
@@ -198,6 +210,9 @@ public class SmartCSVController extends FXMLController {
|
|||||||
@FXML
|
@FXML
|
||||||
private Label currentLineNumber;
|
private Label currentLineNumber;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label totalNumberOfLines;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// members
|
// members
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -212,7 +227,8 @@ public class SmartCSVController extends FXMLController {
|
|||||||
|
|
||||||
private FileStorage<CSVModel> currentCsvFile = new FileStorage<>(csvFileReader, csvFileWriter);
|
private FileStorage<CSVModel> currentCsvFile = new FileStorage<>(csvFileReader, csvFileWriter);
|
||||||
private FileStorage<ValidationConfiguration> currentConfigFile = new FileStorage<>(new ValidationFileReader(), new ValidationFileWriter());
|
private FileStorage<ValidationConfiguration> currentConfigFile = new FileStorage<>(new ValidationFileReader(), new ValidationFileWriter());
|
||||||
private FileStorage<CsvPreference> csvPreferenceFile = new FileStorage<>(new PreferencesFileReader(), new PreferencesFileWriter());
|
private FileStorage<Preferences> 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 ListChangeListener<ValidationError> errorListListener = c -> tableView.refresh();
|
||||||
private WeakListChangeListener<ValidationError> weakErrorListListener = new WeakListChangeListener<>(errorListListener);
|
private WeakListChangeListener<ValidationError> weakErrorListListener = new WeakListChangeListener<>(errorListListener);
|
||||||
@@ -238,8 +254,51 @@ public class SmartCSVController extends FXMLController {
|
|||||||
bindConfigFileName();
|
bindConfigFileName();
|
||||||
|
|
||||||
csvPreferenceFile.setFile(PREFERENCES_FILE);
|
csvPreferenceFile.setFile(PREFERENCES_FILE);
|
||||||
|
fileEncodingFile.setFile(ENCODING_FILE);
|
||||||
|
|
||||||
loadCsvPreferencesFromFile();
|
loadCsvPreferencesFromFile();
|
||||||
|
|
||||||
|
initDragAndDrop();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initDragAndDrop() {
|
||||||
|
tableWrapper.setOnDragOver(event -> {
|
||||||
|
Dragboard db = event.getDragboard();
|
||||||
|
if (event.getGestureSource() != tableWrapper
|
||||||
|
&& db.hasFiles()
|
||||||
|
&& db.getFiles().size() == 1
|
||||||
|
&& db.getFiles().get(0).getName().endsWith(".csv")) {
|
||||||
|
event.acceptTransferModes(TransferMode.COPY);
|
||||||
|
}
|
||||||
|
event.consume();
|
||||||
|
});
|
||||||
|
|
||||||
|
tableWrapper.setOnDragDropped(event -> {
|
||||||
|
Dragboard db = event.getDragboard();
|
||||||
|
boolean success = false;
|
||||||
|
if (db.hasFiles() && db.getFiles().size() == 1 && canOpen()) {
|
||||||
|
File file = db.getFiles().get(0);
|
||||||
|
openFile(currentCsvFile, file);
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
/* let the source know whether the string was successfully
|
||||||
|
* transferred and used */
|
||||||
|
event.setDropCompleted(success);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
private void setupErrorSideBar(ResourceBundle resourceBundle) {
|
||||||
@@ -342,11 +401,32 @@ public class SmartCSVController extends FXMLController {
|
|||||||
Optional<ButtonType> result = alert.showAndWait();
|
Optional<ButtonType> result = alert.showAndWait();
|
||||||
|
|
||||||
if (result.get() == ButtonType.OK){
|
if (result.get() == ButtonType.OK){
|
||||||
CsvPreference csvPreference = preferencesController.getCsvPreference();
|
Preferences csvPreference = preferencesController.getCsvPreference();
|
||||||
setCsvPreference(csvPreference);
|
setCsvPreference(csvPreference);
|
||||||
saveCsvPreferences(csvPreference);
|
saveCsvPreferences(csvPreference);
|
||||||
|
String fileEncoding = CharsetHelper.getCharsetName(preferencesController.getFileEncoding());
|
||||||
|
setFileEncoding(fileEncoding);
|
||||||
|
saveFileEncoding(fileEncoding);
|
||||||
} else {
|
} else {
|
||||||
preferencesController.setCsvPreference(csvPreferenceFile.getContent());
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -423,6 +503,22 @@ public class SmartCSVController extends FXMLController {
|
|||||||
return canExit;
|
return canExit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean canOpen() {
|
||||||
|
boolean canOpen = true;
|
||||||
|
if (currentCsvFile.getContent() != null && currentCsvFile.isFileChanged()) {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
||||||
|
alert.setTitle(resourceBundle.getString("dialog.changes.title"));
|
||||||
|
alert.setHeaderText(resourceBundle.getString("dialog.changes.header.text"));
|
||||||
|
alert.setContentText(resourceBundle.getString("dialog.changes.text"));
|
||||||
|
|
||||||
|
Optional<ButtonType> result = alert.showAndWait();
|
||||||
|
if (result.get() != ButtonType.OK){
|
||||||
|
canOpen = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return canOpen;
|
||||||
|
}
|
||||||
|
|
||||||
public void showValidationEditor(String column) {
|
public void showValidationEditor(String column) {
|
||||||
validationEditorController.setSelectedColumn(column);
|
validationEditorController.setSelectedColumn(column);
|
||||||
validationEditorController.updateForm();
|
validationEditorController.updateForm();
|
||||||
@@ -492,13 +588,17 @@ public class SmartCSVController extends FXMLController {
|
|||||||
|
|
||||||
private void loadCsvPreferencesFromFile() {
|
private void loadCsvPreferencesFromFile() {
|
||||||
if (csvPreferenceFile.getFile().exists()) {
|
if (csvPreferenceFile.getFile().exists()) {
|
||||||
useLoadFileService(csvPreferenceFile, event -> setCsvPreference(csvPreferenceFile.getContent()));
|
useLoadFileService(csvPreferenceFile, event -> {
|
||||||
|
setCsvPreference(csvPreferenceFile.getContent());
|
||||||
|
loadEncodingFromFile();
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
setCsvPreference(CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE);
|
setCsvPreference(defaultPreferences());
|
||||||
|
loadEncodingFromFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveCsvPreferences(CsvPreference csvPreference) {
|
private void saveCsvPreferences(Preferences csvPreference) {
|
||||||
try {
|
try {
|
||||||
createPreferenceFile();
|
createPreferenceFile();
|
||||||
csvPreferenceFile.setContent(csvPreference);
|
csvPreferenceFile.setContent(csvPreference);
|
||||||
@@ -521,7 +621,7 @@ public class SmartCSVController extends FXMLController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCsvPreference(CsvPreference csvPreference) {
|
private void setCsvPreference(Preferences csvPreference) {
|
||||||
preferencesController.setCsvPreference(csvPreference);
|
preferencesController.setCsvPreference(csvPreference);
|
||||||
csvFileReader.setCsvPreference(csvPreference);
|
csvFileReader.setCsvPreference(csvPreference);
|
||||||
csvFileWriter.setCsvPreference(csvPreference);
|
csvFileWriter.setCsvPreference(csvPreference);
|
||||||
@@ -545,9 +645,14 @@ public class SmartCSVController extends FXMLController {
|
|||||||
|
|
||||||
//Show open file dialog
|
//Show open file dialog
|
||||||
File file = fileChooser.showOpenDialog(applicationPane.getScene().getWindow());
|
File file = fileChooser.showOpenDialog(applicationPane.getScene().getWindow());
|
||||||
|
openFile(storageFile, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openFile(FileStorage storageFile, File file) {
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
|
File previousFile = storageFile.getFile();
|
||||||
storageFile.setFile(file);
|
storageFile.setFile(file);
|
||||||
useLoadFileService(storageFile, t -> resetContent());
|
useLoadFileService(storageFile, t -> resetContent(), () -> storageFile.setFile(previousFile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -576,13 +681,20 @@ public class SmartCSVController extends FXMLController {
|
|||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void useLoadFileService(FileStorage fileStorage, EventHandler<WorkerStateEvent> onSucceededHandler) {
|
private void useLoadFileService(FileStorage<?> fileStorage, EventHandler<WorkerStateEvent> onSucceededHandler) {
|
||||||
|
useLoadFileService(fileStorage, onSucceededHandler, () -> {
|
||||||
|
// nothing to rollback
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void useLoadFileService(FileStorage<?> fileStorage, EventHandler<WorkerStateEvent> onSucceededHandler, Runnable rollbackAction) {
|
||||||
loadFileService.setFileStorage(fileStorage);
|
loadFileService.setFileStorage(fileStorage);
|
||||||
loadFileService.restart();
|
loadFileService.restart();
|
||||||
loadFileService.setOnSucceeded(onSucceededHandler);
|
loadFileService.setOnSucceeded(onSucceededHandler);
|
||||||
|
loadFileService.setOnFailed(event -> JavaFxUtils.onServiceError(event, "LoadFileService Error", "Failed to load the file.", rollbackAction));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void useSaveFileService(FileStorage fileStorage) {
|
private void useSaveFileService(FileStorage<?> fileStorage) {
|
||||||
saveFileService.setFileStorage(fileStorage);
|
saveFileService.setFileStorage(fileStorage);
|
||||||
saveFileService.restart();
|
saveFileService.restart();
|
||||||
saveFileService.setOnSucceeded(t -> resetContent());
|
saveFileService.setOnSucceeded(t -> resetContent());
|
||||||
@@ -608,9 +720,15 @@ public class SmartCSVController extends FXMLController {
|
|||||||
addColumn(column, tableView);
|
addColumn(column, tableView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tableView.getColumns().addListener(
|
||||||
|
(InvalidationListener) observable -> currentCsvFile.getContent().setHeader(
|
||||||
|
tableView.getColumns().stream().map((x) -> x.getText()).toArray(String[]::new)));
|
||||||
|
|
||||||
tableView.getItems().setAll(currentCsvFile.getContent().getRows());
|
tableView.getItems().setAll(currentCsvFile.getContent().getRows());
|
||||||
tableView.setEditable(true);
|
tableView.setEditable(true);
|
||||||
|
|
||||||
|
totalNumberOfLines.textProperty().setValue("" + currentCsvFile.getContent().getRows().size());
|
||||||
|
|
||||||
setBottomAnchor(tableView, 0.0);
|
setBottomAnchor(tableView, 0.0);
|
||||||
setTopAnchor(tableView, 0.0);
|
setTopAnchor(tableView, 0.0);
|
||||||
setLeftAnchor(tableView, 0.0);
|
setLeftAnchor(tableView, 0.0);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -1,3 +1,29 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2015-2021 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.list;
|
package ninja.javafx.smartcsv.fx.list;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
@@ -9,9 +35,6 @@ import javafx.scene.layout.Region;
|
|||||||
|
|
||||||
import java.util.function.UnaryOperator;
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by abi on 05.08.2016.
|
|
||||||
*/
|
|
||||||
public class GotoLineDialog extends Dialog<Integer> {
|
public class GotoLineDialog extends Dialog<Integer> {
|
||||||
|
|
||||||
private final GridPane grid;
|
private final GridPane grid;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -34,17 +34,15 @@ import javafx.scene.control.ComboBox;
|
|||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.control.TextFormatter;
|
import javafx.scene.control.TextFormatter;
|
||||||
import ninja.javafx.smartcsv.fx.FXMLController;
|
import ninja.javafx.smartcsv.fx.FXMLController;
|
||||||
|
import ninja.javafx.smartcsv.preferences.Preferences;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.supercsv.prefs.CsvPreference;
|
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
import java.util.function.UnaryOperator;
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
import static ninja.javafx.smartcsv.preferences.QuoteModeHelper.getQuoteMode;
|
|
||||||
import static ninja.javafx.smartcsv.preferences.QuoteModeHelper.getQuoteModeName;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* controller for preferences
|
* controller for preferences
|
||||||
*/
|
*/
|
||||||
@@ -57,14 +55,11 @@ public class PreferencesController extends FXMLController {
|
|||||||
@FXML
|
@FXML
|
||||||
private TextField delimiterChar;
|
private TextField delimiterChar;
|
||||||
|
|
||||||
@FXML
|
|
||||||
private CheckBox surroundingSpacesNeedQuotes;
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private CheckBox ignoreEmptyLines;
|
private CheckBox ignoreEmptyLines;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private ComboBox<String> quoteMode;
|
private ComboBox<String> fileEncoding;
|
||||||
|
|
||||||
private String endOfLineSymbols;
|
private String endOfLineSymbols;
|
||||||
|
|
||||||
@@ -79,7 +74,7 @@ public class PreferencesController extends FXMLController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
quoteMode.getItems().addAll("normal", "always", "column");
|
fileEncoding.getItems().addAll(Charset.availableCharsets().keySet());
|
||||||
|
|
||||||
UnaryOperator<TextFormatter.Change> allowOnlyOneCharacter = change -> {
|
UnaryOperator<TextFormatter.Change> allowOnlyOneCharacter = change -> {
|
||||||
if (change.isContentChange()) {
|
if (change.isContentChange()) {
|
||||||
@@ -97,24 +92,31 @@ public class PreferencesController extends FXMLController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void revalidate() {
|
private void revalidate() {
|
||||||
valid.setValue(quoteChar.getText().length() == 1 && delimiterChar.getText().length() == 1);
|
valid.setValue(quoteChar.getText().length() <= 1 && delimiterChar.getText().length() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCsvPreference(CsvPreference csvPreference) {
|
public void setCsvPreference(Preferences csvPreference) {
|
||||||
quoteChar.setText(Character.toString(csvPreference.getQuoteChar()));
|
if (csvPreference.quoteChar() != null) {
|
||||||
delimiterChar.setText(Character.toString((char)csvPreference.getDelimiterChar()));
|
quoteChar.setText(csvPreference.quoteChar().toString());
|
||||||
surroundingSpacesNeedQuotes.setSelected(csvPreference.isSurroundingSpacesNeedQuotes());
|
} else {
|
||||||
ignoreEmptyLines.setSelected(csvPreference.isIgnoreEmptyLines());
|
quoteChar.setText("");
|
||||||
quoteMode.getSelectionModel().select(getQuoteModeName(csvPreference.getQuoteMode()));
|
}
|
||||||
endOfLineSymbols = csvPreference.getEndOfLineSymbols();
|
delimiterChar.setText(Character.toString(csvPreference.delimiterChar()));
|
||||||
|
ignoreEmptyLines.setSelected(csvPreference.ignoreEmptyLines());
|
||||||
|
endOfLineSymbols = csvPreference.endOfLineSymbols();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CsvPreference getCsvPreference() {
|
public Preferences getCsvPreference() {
|
||||||
return new CsvPreference.Builder(quoteChar.getText().charAt(0), delimiterChar.getText().charAt(0), endOfLineSymbols)
|
var quote = quoteChar.getText().length() == 0 ? null : quoteChar.getText().charAt(0);
|
||||||
.useQuoteMode(getQuoteMode(quoteMode.getSelectionModel().getSelectedItem()))
|
return new Preferences(quote, delimiterChar.getText().charAt(0), endOfLineSymbols, ignoreEmptyLines.isSelected());
|
||||||
.surroundingSpacesNeedQuotes(surroundingSpacesNeedQuotes.isSelected())
|
}
|
||||||
.ignoreEmptyLines(ignoreEmptyLines.isSelected())
|
|
||||||
.build();
|
public void setFileEncoding(String fileEncoding) {
|
||||||
|
this.fileEncoding.setValue(fileEncoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileEncoding() {
|
||||||
|
return fileEncoding.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getValid() {
|
public boolean getValid() {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -65,8 +65,8 @@ public class EditableValidationCell extends TableCell<CSVRow, CSVValue> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancelEdit() {
|
public void cancelEdit() {
|
||||||
super.cancelEdit();
|
|
||||||
setText(getItem().getValue());
|
setText(getItem().getValue());
|
||||||
|
super.cancelEdit();
|
||||||
setContentDisplay(ContentDisplay.TEXT_ONLY);
|
setContentDisplay(ContentDisplay.TEXT_ONLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,19 +113,14 @@ public class EditableValidationCell extends TableCell<CSVRow, CSVValue> {
|
|||||||
textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);
|
textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);
|
||||||
textField.setOnKeyPressed(t -> {
|
textField.setOnKeyPressed(t -> {
|
||||||
if (t.getCode() == KeyCode.ENTER) {
|
if (t.getCode() == KeyCode.ENTER) {
|
||||||
commitEdit(textField.getValue());
|
runLater(() -> commitEdit(textField.getValue()));
|
||||||
} else if (t.getCode() == KeyCode.ESCAPE) {
|
} else if (t.getCode() == KeyCode.ESCAPE) {
|
||||||
cancelEdit();
|
cancelEdit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
textField.focusedProperty().addListener((observable, oldValue, newValue) -> {
|
|
||||||
if (!newValue && textField != null) {
|
|
||||||
commitEdit(textField.getValue());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ValueTextField extends TextField {
|
private static class ValueTextField extends TextField {
|
||||||
private CSVValue value;
|
private CSVValue value;
|
||||||
|
|
||||||
public ValueTextField(CSVValue value) {
|
public ValueTextField(CSVValue value) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -47,7 +47,6 @@ public class ObservableMapValueFactory implements
|
|||||||
@Override
|
@Override
|
||||||
public ObjectProperty<CSVValue> call(TableColumn.CellDataFeatures<CSVRow, CSVValue> features) {
|
public ObjectProperty<CSVValue> call(TableColumn.CellDataFeatures<CSVRow, CSVValue> features) {
|
||||||
CSVRow row = features.getValue();
|
CSVRow row = features.getValue();
|
||||||
ObjectProperty<CSVValue> value = row.getColumns().get(key);
|
return row.getColumns().get(key);
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -1,3 +1,29 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2015-2021 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.table.model;
|
package ninja.javafx.smartcsv.fx.table.model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
73
src/main/java/ninja/javafx/smartcsv/fx/util/JavaFxUtils.java
Normal file
73
src/main/java/ninja/javafx/smartcsv/fx/util/JavaFxUtils.java
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2021 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.util;
|
||||||
|
|
||||||
|
import javafx.concurrent.Worker;
|
||||||
|
import javafx.concurrent.WorkerStateEvent;
|
||||||
|
import javafx.scene.control.Alert;
|
||||||
|
import ninja.javafx.smartcsv.fx.SmartCSVController;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class helps extract useful messages from exceptions
|
||||||
|
* TODO: make I18n maybe?
|
||||||
|
*/
|
||||||
|
public final class JavaFxUtils {
|
||||||
|
|
||||||
|
private static final Logger logger = LogManager.getLogger(SmartCSVController.class);
|
||||||
|
|
||||||
|
private JavaFxUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onServiceError(WorkerStateEvent event, String windowTitle, String errorHeader) {
|
||||||
|
onServiceError(event, windowTitle, errorHeader, () -> {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onServiceError(WorkerStateEvent event, String windowTitle, String errorHeader, Runnable rollbackAction) {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||||
|
alert.setTitle(windowTitle);
|
||||||
|
alert.setHeaderText(errorHeader);
|
||||||
|
alert.setContentText(findExceptionMessage(event.getSource()));
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String findExceptionMessage(Worker<?> source) {
|
||||||
|
if (source == null) {
|
||||||
|
return "Cannot identify the source of the event!";
|
||||||
|
} else if (source.getException() == null) {
|
||||||
|
return "The event did not have an exception?";
|
||||||
|
}
|
||||||
|
Throwable exception = source.getException();
|
||||||
|
logger.error("Error in " + source.getClass().getSimpleName(), exception);
|
||||||
|
if (exception.getMessage() == null) {
|
||||||
|
return "Exception of type " + exception.getClass() + " had no message, check the logs.";
|
||||||
|
}
|
||||||
|
return exception.getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -34,17 +34,17 @@ import ninja.javafx.smartcsv.files.FileStorage;
|
|||||||
* Service class for async load of a csv file
|
* Service class for async load of a csv file
|
||||||
*/
|
*/
|
||||||
@org.springframework.stereotype.Service
|
@org.springframework.stereotype.Service
|
||||||
public class LoadFileService extends Service {
|
public class LoadFileService extends Service<Void> {
|
||||||
|
|
||||||
private FileStorage file;
|
private FileStorage<?> file;
|
||||||
|
|
||||||
public void setFileStorage(FileStorage file) {
|
public void setFileStorage(FileStorage<?> file) {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Task createTask() {
|
protected Task<Void> createTask() {
|
||||||
return new Task() {
|
return new Task<>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void call() throws Exception {
|
protected Void call() throws Exception {
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -31,22 +31,22 @@ import javafx.concurrent.Task;
|
|||||||
import ninja.javafx.smartcsv.files.FileStorage;
|
import ninja.javafx.smartcsv.files.FileStorage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service class for async load of a csv file
|
* Service class for async save of a csv file
|
||||||
*/
|
*/
|
||||||
@org.springframework.stereotype.Service
|
@org.springframework.stereotype.Service
|
||||||
public class SaveFileService extends Service {
|
public class SaveFileService extends Service<Void> {
|
||||||
|
|
||||||
private FileStorage file;
|
private FileStorage<?> file;
|
||||||
|
|
||||||
public void setFileStorage(FileStorage value) {
|
public void setFileStorage(FileStorage<?> value) {
|
||||||
file = value;
|
file = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Task createTask() {
|
protected Task<Void> createTask() {
|
||||||
return new Task() {
|
return new Task<>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void call() throws Exception {
|
protected Void call() {
|
||||||
try {
|
try {
|
||||||
file.save();
|
file.save();
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2015-2021 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 java.nio.charset.Charset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class for getting charset's name
|
||||||
|
*/
|
||||||
|
public class CharsetHelper {
|
||||||
|
|
||||||
|
public static String getCharsetName(String name) {
|
||||||
|
try {
|
||||||
|
return Charset.forName(name).name();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Charset.defaultCharset().name();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -26,31 +26,37 @@
|
|||||||
|
|
||||||
package ninja.javafx.smartcsv.preferences;
|
package ninja.javafx.smartcsv.preferences;
|
||||||
|
|
||||||
import org.supercsv.quote.AlwaysQuoteMode;
|
import com.google.gson.GsonBuilder;
|
||||||
import org.supercsv.quote.ColumnQuoteMode;
|
import ninja.javafx.smartcsv.FileReader;
|
||||||
import org.supercsv.quote.NormalQuoteMode;
|
|
||||||
import org.supercsv.quote.QuoteMode;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class for mapping quote quoteModeName
|
* file reader for the file encoding
|
||||||
*/
|
*/
|
||||||
public class QuoteModeHelper {
|
public class EncodingFileReader implements FileReader<String> {
|
||||||
|
|
||||||
public static QuoteMode getQuoteMode(String quoteModeName) {
|
private String fileEncoding;
|
||||||
switch (quoteModeName) {
|
|
||||||
case "always": return new AlwaysQuoteMode();
|
public EncodingFileReader() {
|
||||||
case "column": return new ColumnQuoteMode();
|
fileEncoding = Charset.defaultCharset().name();
|
||||||
default: return new NormalQuoteMode();
|
}
|
||||||
|
|
||||||
|
@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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getQuoteModeName(QuoteMode quoteMode) {
|
|
||||||
if (quoteMode instanceof AlwaysQuoteMode) {
|
|
||||||
return "always";
|
|
||||||
} else if (quoteMode instanceof ColumnQuoteMode) {
|
|
||||||
return "column";
|
|
||||||
} else {
|
|
||||||
return "normal";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2015-2021 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2015-2021 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;
|
||||||
|
|
||||||
|
public record Preferences(
|
||||||
|
Character quoteChar,
|
||||||
|
char delimiterChar,
|
||||||
|
String endOfLineSymbols,
|
||||||
|
boolean ignoreEmptyLines) {
|
||||||
|
|
||||||
|
public static Preferences defaultPreferences() {
|
||||||
|
return new Preferences('\"',',', "\n", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -28,51 +28,39 @@ package ninja.javafx.smartcsv.preferences;
|
|||||||
|
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import ninja.javafx.smartcsv.FileReader;
|
import ninja.javafx.smartcsv.FileReader;
|
||||||
import org.supercsv.prefs.CsvPreference;
|
|
||||||
import org.supercsv.quote.AlwaysQuoteMode;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static ninja.javafx.smartcsv.preferences.QuoteModeHelper.getQuoteMode;
|
import static ninja.javafx.smartcsv.preferences.Preferences.defaultPreferences;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* file reader for the preferences
|
* file reader for the preferences
|
||||||
*/
|
*/
|
||||||
public class PreferencesFileReader implements FileReader<CsvPreference> {
|
public class PreferencesFileReader implements FileReader<Preferences> {
|
||||||
|
|
||||||
private Map config;
|
private Preferences csvPreference;
|
||||||
private CsvPreference csvPreference;
|
|
||||||
|
|
||||||
public PreferencesFileReader() {
|
public PreferencesFileReader() {
|
||||||
csvPreference = new CsvPreference.
|
csvPreference = defaultPreferences();
|
||||||
Builder(CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE).
|
|
||||||
useQuoteMode(new AlwaysQuoteMode()).build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(File filename) throws IOException {
|
public void read(File filename) throws IOException {
|
||||||
config = new GsonBuilder().create().fromJson(new java.io.FileReader(filename), HashMap.class);
|
Map config = new GsonBuilder().create().fromJson(new java.io.FileReader(filename), HashMap.class);
|
||||||
|
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
char quoteChar = config.get("quoteChar").toString().charAt(0);
|
Character quoteChar = config.get("quoteChar") == null ? null : config.get("quoteChar").toString().charAt(0);
|
||||||
char delimiterChar = config.get("delimiterChar").toString().charAt(0);
|
char delimiterChar = config.get("delimiterChar").toString().charAt(0);
|
||||||
String endOfLineSymbols = config.get("endOfLineSymbols").toString();
|
String endOfLineSymbols = config.get("endOfLineSymbols").toString();
|
||||||
boolean surroundingSpacesNeedQuotes = (Boolean)config.get("surroundingSpacesNeedQuotes");
|
boolean ignoreEmptyLines = (Boolean) config.get("ignoreEmptyLines");
|
||||||
boolean ignoreEmptyLines = (Boolean)config.get("ignoreEmptyLines");
|
csvPreference = new Preferences(quoteChar, delimiterChar, endOfLineSymbols, ignoreEmptyLines);
|
||||||
String quoteMode = config.get("quoteMode").toString();
|
|
||||||
|
|
||||||
csvPreference = new CsvPreference.Builder(quoteChar, delimiterChar, endOfLineSymbols)
|
|
||||||
.useQuoteMode(getQuoteMode(quoteMode))
|
|
||||||
.surroundingSpacesNeedQuotes(surroundingSpacesNeedQuotes)
|
|
||||||
.ignoreEmptyLines(ignoreEmptyLines)
|
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CsvPreference getContent() {
|
public Preferences getContent() {
|
||||||
return csvPreference;
|
return csvPreference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -29,7 +29,6 @@ package ninja.javafx.smartcsv.preferences;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import ninja.javafx.smartcsv.FileWriter;
|
import ninja.javafx.smartcsv.FileWriter;
|
||||||
import org.supercsv.prefs.CsvPreference;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -40,22 +39,20 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* Save preferences to configuration file
|
* Save preferences to configuration file
|
||||||
*/
|
*/
|
||||||
public class PreferencesFileWriter implements FileWriter<CsvPreference> {
|
public class PreferencesFileWriter implements FileWriter<Preferences> {
|
||||||
|
|
||||||
private CsvPreference csvPreference;
|
private Preferences csvPreference;
|
||||||
|
|
||||||
public void setContent(CsvPreference csvPreference) {
|
public void setContent(Preferences csvPreference) {
|
||||||
this.csvPreference = csvPreference;
|
this.csvPreference = csvPreference;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(File file) throws IOException {
|
public void write(File file) throws IOException {
|
||||||
Map<String, Object> preferences = new HashMap<>();
|
Map<String, Object> preferences = new HashMap<>();
|
||||||
preferences.put("quoteChar", Character.toString(csvPreference.getQuoteChar()));
|
preferences.put("quoteChar", csvPreference.quoteChar() == null ? null: csvPreference.quoteChar().toString());
|
||||||
preferences.put("delimiterChar", Character.toString((char)csvPreference.getDelimiterChar()));
|
preferences.put("delimiterChar", Character.toString((char)csvPreference.delimiterChar()));
|
||||||
preferences.put("endOfLineSymbols", csvPreference.getEndOfLineSymbols());
|
preferences.put("endOfLineSymbols", csvPreference.endOfLineSymbols());
|
||||||
preferences.put("surroundingSpacesNeedQuotes", csvPreference.isSurroundingSpacesNeedQuotes());
|
preferences.put("ignoreEmptyLines", csvPreference.ignoreEmptyLines());
|
||||||
preferences.put("ignoreEmptyLines", csvPreference.isIgnoreEmptyLines());
|
|
||||||
preferences.put("quoteMode", QuoteModeHelper.getQuoteModeName(csvPreference.getQuoteMode()));
|
|
||||||
|
|
||||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||||
Files.write(file.toPath(), gson.toJson(preferences).getBytes());
|
Files.write(file.toPath(), gson.toJson(preferences).getBytes());
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -37,11 +37,11 @@ import org.codehaus.groovy.control.CompilationFailedException;
|
|||||||
public class GroovyValidation extends EmptyValueIsValid {
|
public class GroovyValidation extends EmptyValueIsValid {
|
||||||
|
|
||||||
private String groovyScript;
|
private String groovyScript;
|
||||||
private GroovyShell shell = new GroovyShell();
|
|
||||||
private Script script;
|
private Script script;
|
||||||
|
|
||||||
public GroovyValidation(String groovyScript) {
|
public GroovyValidation(String groovyScript) {
|
||||||
this.groovyScript = groovyScript;
|
this.groovyScript = groovyScript;
|
||||||
|
GroovyShell shell = new GroovyShell();
|
||||||
script = shell.parse(groovyScript);
|
script = shell.parse(groovyScript);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -34,6 +34,7 @@ import java.util.UUID;
|
|||||||
*/
|
*/
|
||||||
public class UuidValidation extends EmptyValueIsValid {
|
public class UuidValidation extends EmptyValueIsValid {
|
||||||
|
|
||||||
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
@Override
|
@Override
|
||||||
public void check(int row, String value, ValidationError error) {
|
public void check(int row, String value, ValidationError error) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
</Label>
|
</Label>
|
||||||
<Label text="AOE Takashi (https://github.com/aoetk)" />
|
<Label text="AOE Takashi (https://github.com/aoetk)" />
|
||||||
<Label text="Hasan Kara (https://github.com/haisi)" />
|
<Label text="Hasan Kara (https://github.com/haisi)" />
|
||||||
|
<Label text="apixandru (https://github.com/apixandru)" />
|
||||||
<Label text="3rd party software">
|
<Label text="3rd party software">
|
||||||
<VBox.margin>
|
<VBox.margin>
|
||||||
<Insets top="8.0" />
|
<Insets top="8.0" />
|
||||||
@@ -60,8 +61,8 @@
|
|||||||
<Hyperlink onAction="#openLinkInBrowser" text="http://www.groovy-lang.org/" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
<Hyperlink onAction="#openLinkInBrowser" text="http://www.groovy-lang.org/" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
||||||
<Label text="spring framework" GridPane.rowIndex="3" />
|
<Label text="spring framework" GridPane.rowIndex="3" />
|
||||||
<Hyperlink onAction="#openLinkInBrowser" text="https://spring.io/" GridPane.columnIndex="1" GridPane.rowIndex="3" />
|
<Hyperlink onAction="#openLinkInBrowser" text="https://spring.io/" GridPane.columnIndex="1" GridPane.rowIndex="3" />
|
||||||
<Label text="supercsv" GridPane.rowIndex="4" />
|
<Label text="FastCSV" GridPane.rowIndex="4" />
|
||||||
<Hyperlink onAction="#openLinkInBrowser" text="http://super-csv.github.io/super-csv/" GridPane.columnIndex="1" GridPane.rowIndex="4" />
|
<Hyperlink onAction="#openLinkInBrowser" text="https://github.com/osiegmar/FastCSV" GridPane.columnIndex="1" GridPane.rowIndex="4" />
|
||||||
<Label text="Gson" GridPane.rowIndex="5" />
|
<Label text="Gson" GridPane.rowIndex="5" />
|
||||||
<Hyperlink onAction="#openLinkInBrowser" text="https://github.com/google/gson/" GridPane.columnIndex="1" GridPane.rowIndex="5" />
|
<Hyperlink onAction="#openLinkInBrowser" text="https://github.com/google/gson/" GridPane.columnIndex="1" GridPane.rowIndex="5" />
|
||||||
<Label text="commons-validator" GridPane.rowIndex="6" />
|
<Label text="commons-validator" GridPane.rowIndex="6" />
|
||||||
@@ -89,7 +90,7 @@
|
|||||||
<Font size="18.0" />
|
<Font size="18.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
<TextArea editable="false" prefHeight="200.0" prefWidth="200.0" text="Copyright (c) 2015-2019 Andreas Billmann <andreas.billmann@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." wrapText="true" />
|
<TextArea editable="false" prefHeight="200.0" prefWidth="200.0" text="Copyright (c) 2015-2021 Andreas Billmann <andreas.billmann@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." wrapText="true" />
|
||||||
</children>
|
</children>
|
||||||
<opaqueInsets>
|
<opaqueInsets>
|
||||||
<Insets />
|
<Insets />
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
application.name = SmartCSV.fx
|
application.name = SmartCSV.fx
|
||||||
application.version = 0.9.1
|
application.version = 1.4.0
|
||||||
|
|
||||||
# fxml views
|
# fxml views
|
||||||
fxml.smartcvs.view = /ninja/javafx/smartcsv/fx/smartcsv.fxml
|
fxml.smartcvs.view = /ninja/javafx/smartcsv/fx/smartcsv.fxml
|
||||||
|
|||||||
@@ -12,20 +12,17 @@
|
|||||||
<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 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 minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
|
|
||||||
</rowConstraints>
|
</rowConstraints>
|
||||||
<children>
|
<children>
|
||||||
<Label text="%preferences.quoteChar" />
|
<Label text="%preferences.quoteChar" />
|
||||||
<TextField fx:id="quoteChar" GridPane.columnIndex="1" />
|
<TextField fx:id="quoteChar" GridPane.columnIndex="1" />
|
||||||
<Label text="%preferences.delimiterChar" GridPane.rowIndex="1" />
|
<Label text="%preferences.delimiterChar" GridPane.rowIndex="1" />
|
||||||
<TextField fx:id="delimiterChar" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
<TextField fx:id="delimiterChar" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||||
<Label text="%preferences.surroundingSpacesNeedQuotes" GridPane.rowIndex="2" />
|
<Label text="%preferences.ignoreEmptyLines" GridPane.rowIndex="2" />
|
||||||
<CheckBox fx:id="surroundingSpacesNeedQuotes" mnemonicParsing="false" text="" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
<CheckBox fx:id="ignoreEmptyLines" mnemonicParsing="false" text="" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
||||||
<Label text="%preferences.ignoreEmptyLines" GridPane.rowIndex="3" />
|
<Label text="%preferences.fileEncoding" GridPane.rowIndex="3" />
|
||||||
<CheckBox fx:id="ignoreEmptyLines" mnemonicParsing="false" text="" GridPane.columnIndex="1" GridPane.rowIndex="3" />
|
<ComboBox fx:id="fileEncoding" editable="true" prefWidth="150.0" 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" />
|
|
||||||
</children>
|
</children>
|
||||||
<padding>
|
<padding>
|
||||||
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0" />
|
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0" />
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
<?import javafx.geometry.Insets?>
|
<?import javafx.geometry.Insets?>
|
||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
<?import java.net.URL?>
|
|
||||||
<BorderPane fx:id="applicationPane" maxHeight="-Infinity" maxWidth="1000.0" minHeight="700.0" minWidth="-Infinity" prefHeight="700.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/8.0.101" xmlns:fx="http://javafx.com/fxml/1">
|
<BorderPane fx:id="applicationPane" maxHeight="-Infinity" maxWidth="1000.0" minHeight="700.0" minWidth="-Infinity" prefHeight="700.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/8.0.101" xmlns:fx="http://javafx.com/fxml/1">
|
||||||
<top>
|
<top>
|
||||||
<VBox id="background" prefWidth="100.0" BorderPane.alignment="CENTER">
|
<VBox id="background" prefWidth="100.0" BorderPane.alignment="CENTER">
|
||||||
@@ -265,9 +264,6 @@
|
|||||||
</center>
|
</center>
|
||||||
<left>
|
<left>
|
||||||
</left>
|
</left>
|
||||||
<stylesheets>
|
|
||||||
<URL value="@/ninja/javafx/smartcsv/fx/smartcsv.css" />
|
|
||||||
</stylesheets>
|
|
||||||
<bottom>
|
<bottom>
|
||||||
<GridPane hgap="8.0" BorderPane.alignment="CENTER">
|
<GridPane hgap="8.0" BorderPane.alignment="CENTER">
|
||||||
<columnConstraints>
|
<columnConstraints>
|
||||||
@@ -279,7 +275,9 @@
|
|||||||
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0" />
|
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0" />
|
||||||
<ColumnConstraints hgrow="NEVER" minWidth="10.0" />
|
<ColumnConstraints hgrow="NEVER" minWidth="10.0" />
|
||||||
<ColumnConstraints fillWidth="false" halignment="RIGHT" hgrow="NEVER" minWidth="10.0" prefWidth="100.0" />
|
<ColumnConstraints fillWidth="false" halignment="RIGHT" hgrow="NEVER" minWidth="10.0" prefWidth="100.0" />
|
||||||
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0" prefWidth="100.0" />
|
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0" prefWidth="100.0" />
|
||||||
|
<ColumnConstraints fillWidth="false" halignment="RIGHT" hgrow="NEVER" minWidth="10.0" prefWidth="100.0" />
|
||||||
|
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0" prefWidth="100.0" />
|
||||||
</columnConstraints>
|
</columnConstraints>
|
||||||
<rowConstraints>
|
<rowConstraints>
|
||||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||||
@@ -293,6 +291,8 @@
|
|||||||
<Label fx:id="configurationName" GridPane.columnIndex="5" GridPane.hgrow="ALWAYS" />
|
<Label fx:id="configurationName" GridPane.columnIndex="5" GridPane.hgrow="ALWAYS" />
|
||||||
<Label text="%lineNumber" GridPane.columnIndex="7" />
|
<Label text="%lineNumber" GridPane.columnIndex="7" />
|
||||||
<Label fx:id="currentLineNumber" text="" GridPane.columnIndex="8" />
|
<Label fx:id="currentLineNumber" text="" GridPane.columnIndex="8" />
|
||||||
|
<Label text="%totalNumberOfLines" GridPane.columnIndex="9" />
|
||||||
|
<Label fx:id="totalNumberOfLines" text="0" GridPane.columnIndex="10" />
|
||||||
</children>
|
</children>
|
||||||
<BorderPane.margin>
|
<BorderPane.margin>
|
||||||
<Insets bottom="4.0" left="8.0" right="8.0" top="4.0" />
|
<Insets bottom="4.0" left="8.0" right="8.0" top="4.0" />
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ dialog.exit.title = Close Application
|
|||||||
dialog.exit.header.text = Do you want to close application?
|
dialog.exit.header.text = Do you want to close application?
|
||||||
dialog.exit.text = There are changes made to the csv file. If you close now, the changes are lost!
|
dialog.exit.text = There are changes made to the csv file. If you close now, the changes are lost!
|
||||||
|
|
||||||
|
dialog.changes.title = Discard changes
|
||||||
|
dialog.changes.header.text = Do you want to discard changes?
|
||||||
|
dialog.changes.text = There are changes made to the csv file. If you open a new file, the changes are lost!
|
||||||
|
|
||||||
dialog.preferences.title = Preferences
|
dialog.preferences.title = Preferences
|
||||||
dialog.preferences.header.text = Preferences
|
dialog.preferences.header.text = Preferences
|
||||||
|
|
||||||
@@ -41,6 +45,7 @@ preferences.delimiterChar = Delimiter character:
|
|||||||
preferences.ignoreEmptyLines = Ignore empty lines:
|
preferences.ignoreEmptyLines = Ignore empty lines:
|
||||||
preferences.surroundingSpacesNeedQuotes = Surrounding spaces need quotes:
|
preferences.surroundingSpacesNeedQuotes = Surrounding spaces need quotes:
|
||||||
preferences.quoteMode = Quote mode:
|
preferences.quoteMode = Quote mode:
|
||||||
|
preferences.fileEncoding = File encoding:
|
||||||
|
|
||||||
# validaton messages
|
# validaton messages
|
||||||
validation.message.not.empty = should not be empty
|
validation.message.not.empty = should not be empty
|
||||||
@@ -86,6 +91,7 @@ dialog.validation.rules.header = Validation rules of column "{0}"
|
|||||||
context.menu.edit.column.rules = Edit rules
|
context.menu.edit.column.rules = Edit rules
|
||||||
|
|
||||||
lineNumber = Selected line:
|
lineNumber = Selected line:
|
||||||
|
totalNumberOfLines = Lines:
|
||||||
|
|
||||||
log.header.message = {0} has {1} errors
|
log.header.message = {0} has {1} errors
|
||||||
log.message = row {0} column {1} : {2}
|
log.message = row {0} column {1} : {2}
|
||||||
|
|||||||
@@ -45,11 +45,16 @@ dialog.exit.title = Anwendung beenden
|
|||||||
dialog.exit.header.text = M\u00f6chten Sie wirklich die Anwendung beenden?
|
dialog.exit.header.text = M\u00f6chten Sie wirklich die Anwendung beenden?
|
||||||
dialog.exit.text = Es gibt noch ungespeicherte \u00c4nderungen, die verloren gehen, wenn Sie die Anwendung jetzt beenden.
|
dialog.exit.text = Es gibt noch ungespeicherte \u00c4nderungen, die verloren gehen, wenn Sie die Anwendung jetzt beenden.
|
||||||
|
|
||||||
|
dialog.changes.title = Änderungen verwerfen
|
||||||
|
dialog.changes.header.text = Wollen Sie Ihre Änderungen verwerfen?
|
||||||
|
dialog.changes.text = Es gibt noch ungespeicherte \u00c4nderungen, die verloren gehen, wenn Sie die Datei laden.
|
||||||
|
|
||||||
preferences.quoteChar = Einfassungszeichen:
|
preferences.quoteChar = Einfassungszeichen:
|
||||||
preferences.delimiterChar = Trennzeichen:
|
preferences.delimiterChar = Trennzeichen:
|
||||||
preferences.ignoreEmptyLines = Leere Zeilen ignorieren:
|
preferences.ignoreEmptyLines = Leere Zeilen ignorieren:
|
||||||
preferences.surroundingSpacesNeedQuotes = Leerzeichen einfassen:
|
preferences.surroundingSpacesNeedQuotes = Leerzeichen einfassen:
|
||||||
preferences.quoteMode = Einfassungsmodus:
|
preferences.quoteMode = Einfassungsmodus:
|
||||||
|
preferences.fileEncoding = Dateicodierung:
|
||||||
|
|
||||||
# validaton messages
|
# validaton messages
|
||||||
validation.message.not.empty = Darf nicht leer sein.
|
validation.message.not.empty = Darf nicht leer sein.
|
||||||
@@ -96,6 +101,7 @@ dialog.validation.rules.header = Pr\u00fcfregeln f\u00fcr die Spalte "{0}"
|
|||||||
context.menu.edit.column.rules = Pr\u00fcfregeln bearbeiten
|
context.menu.edit.column.rules = Pr\u00fcfregeln bearbeiten
|
||||||
|
|
||||||
lineNumber = Ausgew\u00e4hlte Zeile:
|
lineNumber = Ausgew\u00e4hlte Zeile:
|
||||||
|
totalNumberOfLines = Zeilen:
|
||||||
|
|
||||||
log.header.message = {0} hat {1} Fehler
|
log.header.message = {0} hat {1} Fehler
|
||||||
log.message = Zeile {0} Spalte {1} : {2}
|
log.message = Zeile {0} Spalte {1} : {2}
|
||||||
|
|||||||
BIN
src/main/resources/ninja/javafx/smartcsv/icon/logo.afdesign
Normal file
BIN
src/main/resources/ninja/javafx/smartcsv/icon/logo.afdesign
Normal file
Binary file not shown.
BIN
src/main/resources/ninja/javafx/smartcsv/icon/logo.png
Normal file
BIN
src/main/resources/ninja/javafx/smartcsv/icon/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 750 B |
BIN
src/main/resources/ninja/javafx/smartcsv/icon/logo_256x256.png
Normal file
BIN
src/main/resources/ninja/javafx/smartcsv/icon/logo_256x256.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.1 KiB |
BIN
src/main/resources/ninja/javafx/smartcsv/icon/logo_32x32.png
Normal file
BIN
src/main/resources/ninja/javafx/smartcsv/icon/logo_32x32.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
BIN
src/main/resources/ninja/javafx/smartcsv/icon/logo_64x64.png
Normal file
BIN
src/main/resources/ninja/javafx/smartcsv/icon/logo_64x64.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
109
src/test/java/ninja/javafx/smartcsv/files/FileStorageTest.java
Normal file
109
src/test/java/ninja/javafx/smartcsv/files/FileStorageTest.java
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
package ninja.javafx.smartcsv.files;
|
||||||
|
|
||||||
|
import ninja.javafx.smartcsv.FileReader;
|
||||||
|
import ninja.javafx.smartcsv.FileWriter;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.hamcrest.Matchers.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
public class FileStorageTest {
|
||||||
|
|
||||||
|
private FileReader<String> reader;
|
||||||
|
private FileWriter<String> writer;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// subject under test
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
private FileStorage<String> sut;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// init
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@BeforeEach
|
||||||
|
public void initialize() {
|
||||||
|
reader = mock(FileReader.class);
|
||||||
|
writer = mock(FileWriter.class);
|
||||||
|
sut = new FileStorage<>(reader, writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// tests
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@Test
|
||||||
|
public void setFile_ShouldStoreFile() {
|
||||||
|
|
||||||
|
// pre execution assertion
|
||||||
|
assertThat("get file returns null", sut.getFile(), nullValue());
|
||||||
|
assertThat("property is null", sut.fileProperty().isNull().get(), equalTo(true));
|
||||||
|
|
||||||
|
// execution
|
||||||
|
final File file = new File("file");
|
||||||
|
sut.setFile(file);
|
||||||
|
|
||||||
|
// assertion
|
||||||
|
assertThat("get file returns the file", sut.getFile(), sameInstance(file));
|
||||||
|
assertThat("property is not null", sut.fileProperty().isNull().get(), equalTo(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void load_ShouldReadContentFromReader() throws Exception {
|
||||||
|
// setup
|
||||||
|
final File file = new File("file");
|
||||||
|
sut.setFile(file);
|
||||||
|
when(reader.getContent()).thenReturn("CONTENT");
|
||||||
|
|
||||||
|
// execution
|
||||||
|
sut.load();
|
||||||
|
|
||||||
|
// assertion
|
||||||
|
verify(reader).read(file);
|
||||||
|
assertThat("content is set", sut.getContent(), equalTo("CONTENT"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void load_ShouldResetFileChangedProperty() throws Exception {
|
||||||
|
// setup
|
||||||
|
sut.setFileChanged(true);
|
||||||
|
when(reader.getContent()).thenReturn("CONTENT");
|
||||||
|
|
||||||
|
// execution
|
||||||
|
sut.load();
|
||||||
|
|
||||||
|
// assertion
|
||||||
|
assertThat("file changed is reset", sut.isFileChanged(), equalTo(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void save_ShouldWriteContentToWriter() throws Exception {
|
||||||
|
// setup
|
||||||
|
final String content = "CONTENT";
|
||||||
|
sut.setContent(content);
|
||||||
|
final File file = new File("file");
|
||||||
|
sut.setFile(file);
|
||||||
|
|
||||||
|
// execution
|
||||||
|
sut.save();
|
||||||
|
|
||||||
|
// assertion
|
||||||
|
verify(writer).setContent(content);
|
||||||
|
verify(writer).write(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void save_ShouldResetFileChangedProperty() throws Exception {
|
||||||
|
// setup
|
||||||
|
sut.setFileChanged(true);
|
||||||
|
|
||||||
|
// execution
|
||||||
|
sut.save();
|
||||||
|
|
||||||
|
// assertion
|
||||||
|
assertThat("file changed is reset", sut.isFileChanged(), equalTo(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -26,10 +26,11 @@
|
|||||||
|
|
||||||
package ninja.javafx.smartcsv.fx.table.model;
|
package ninja.javafx.smartcsv.fx.table.model;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unit test for the csv model
|
* unit test for the csv model
|
||||||
@@ -39,14 +40,13 @@ public class CSVModelTest {
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// constants
|
// constants
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
static final String TESTHEADER = "TESTHEADER";
|
private static final String TESTHEADER = "TESTHEADER";
|
||||||
static final String TESTVALUE = "TESTVALUE";
|
private static final String TESTVALUE = "TESTVALUE";
|
||||||
static final String FILEPATH = "filepath";
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// subject under test
|
// subject under test
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
CSVModel sut = new CSVModel();
|
private CSVModel sut = new CSVModel();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// tests
|
// tests
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
package ninja.javafx.smartcsv.fx.table.model;
|
package ninja.javafx.smartcsv.fx.table.model;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.hasKey;
|
import static org.hamcrest.Matchers.hasKey;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unit test for row class
|
* unit test for row class
|
||||||
@@ -14,13 +15,13 @@ public class CSVRowTest {
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// constants
|
// constants
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
static final String COLUMN = "COLUMN";
|
private static final String COLUMN = "COLUMN";
|
||||||
static final String VALUE = "VALUE";
|
private static final String VALUE = "VALUE";
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// subject under test
|
// subject under test
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
CSVRow sut = new CSVRow();
|
private CSVRow sut = new CSVRow();
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2015-2021 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);
|
||||||
|
assertNotEquals(StandardCharsets.UTF_16.name(), Charset.defaultCharset());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getCharsetName_unknown_charset() {
|
||||||
|
String result = CharsetHelper.getCharsetName("foobar");
|
||||||
|
assertEquals(Charset.defaultCharset().name(), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getCharsetName_null_charset() {
|
||||||
|
String result = CharsetHelper.getCharsetName(null);
|
||||||
|
assertEquals(Charset.defaultCharset().name(), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2015-2016 javafx.ninja <info@javafx.ninja>
|
Copyright (c) 2015-2021 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -29,68 +29,39 @@ package ninja.javafx.smartcsv.validation;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
|
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import org.junit.runners.Parameterized;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
import static java.util.stream.Collectors.joining;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unit test for header validator
|
* unit test for header validator
|
||||||
*/
|
*/
|
||||||
@RunWith(Parameterized.class)
|
|
||||||
public class HeaderValidationTest {
|
public class HeaderValidationTest {
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// parameters
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
private ValidationConfiguration config;
|
|
||||||
private Boolean expectedResult;
|
|
||||||
private List<ValidationMessage> expectedErrors;
|
|
||||||
private String[] headerNames;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// subject under test
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
private Validator sut;
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// parameterized constructor
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
public HeaderValidationTest(String configHeaderNames,
|
|
||||||
String[] headerNames,
|
|
||||||
Boolean expectedResult,
|
|
||||||
List<ValidationMessage> expectedErrors) {
|
|
||||||
Gson gson = new GsonBuilder().create();
|
|
||||||
this.config = gson.fromJson(configHeaderNames, ValidationConfiguration.class);
|
|
||||||
this.headerNames = headerNames;
|
|
||||||
this.expectedResult = expectedResult;
|
|
||||||
this.expectedErrors = expectedErrors;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// init
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
@Before
|
|
||||||
public void initialize() {
|
|
||||||
sut = new Validator(config, new TestColumnValueProvider());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// tests
|
// tests
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@Test
|
@ParameterizedTest
|
||||||
public void validation() {
|
@MethodSource("validationConfigurations")
|
||||||
|
public void validation(String configHeaderNames,
|
||||||
|
String[] headerNames,
|
||||||
|
Boolean expectedResult,
|
||||||
|
List<ValidationMessage> expectedErrors) {
|
||||||
|
// setup
|
||||||
|
Gson gson = new GsonBuilder().create();
|
||||||
|
ValidationConfiguration config = gson.fromJson(configHeaderNames, ValidationConfiguration.class);
|
||||||
|
Validator sut = new Validator(config, new TestColumnValueProvider());
|
||||||
|
|
||||||
// execution
|
// execution
|
||||||
ValidationError result = sut.isHeaderValid(headerNames);
|
ValidationError result = sut.isHeaderValid(headerNames);
|
||||||
|
|
||||||
@@ -104,17 +75,17 @@ public class HeaderValidationTest {
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// parameters for tests
|
// parameters for tests
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@Parameterized.Parameters
|
public static Stream<Arguments> validationConfigurations() {
|
||||||
public static Collection validationConfigurations() {
|
return Stream.of(
|
||||||
return asList(new Object[][] {
|
Arguments.of( json(), new String[] {}, true, null ),
|
||||||
{ json(), new String[] {}, true, null },
|
Arguments.of( json("a"), new String[] {"a"}, true, null ),
|
||||||
{ json("a"), new String[] {"a"}, true, null },
|
Arguments.of( json("a"), new String[] {"b"}, false, singletonList(new ValidationMessage("validation.message.header.match", "0", "a", "b"))),
|
||||||
{ json("a"), new String[] {"b"}, false, singletonList(new ValidationMessage("validation.message.header.match", "0", "a", "b"))},
|
Arguments.of( json("a"), new String[] {"a","b"}, false, singletonList(new ValidationMessage("validation.message.header.length", "2", "1"))),
|
||||||
{ json("a"), new String[] {"a","b"}, false, singletonList(new ValidationMessage("validation.message.header.length", "2", "1"))},
|
Arguments.of( json("a", "b"), new String[] {"b", "a"}, false, asList(new ValidationMessage("validation.message.header.match", "0", "a", "b"), new ValidationMessage("validation.message.header.match", "1", "b", "a")) )
|
||||||
{ json("a", "b"), new String[] {"b", "a"}, false, asList(new ValidationMessage("validation.message.header.match", "0", "a", "b"), new ValidationMessage("validation.message.header.match", "1", "b", "a")) }
|
);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("StringConcatenationInLoop")
|
||||||
public static String json(String... headerNames) {
|
public static String json(String... headerNames) {
|
||||||
|
|
||||||
String json = "{ \"fields\": [";
|
String json = "{ \"fields\": [";
|
||||||
|
|||||||
@@ -3,76 +3,37 @@ package ninja.javafx.smartcsv.validation;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
|
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import org.junit.runners.Parameterized;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.stream.Collectors.joining;
|
import static java.util.stream.Collectors.joining;
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.contains;
|
import static org.hamcrest.Matchers.contains;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unit test for validator
|
* unit test for validator
|
||||||
*/
|
*/
|
||||||
@RunWith(Parameterized.class)
|
|
||||||
public class ValidatorTest {
|
public class ValidatorTest {
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// parameters
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
private String config;
|
|
||||||
private String value;
|
|
||||||
private Boolean expectedResult;
|
|
||||||
private ValidationMessage expectedError;
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// subject under test
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
private Validator sut;
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// parameterized constructor
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
public ValidatorTest(String config,
|
|
||||||
String value,
|
|
||||||
Boolean expectedResult,
|
|
||||||
ValidationMessage expectedError) {
|
|
||||||
this.config = config;
|
|
||||||
this.value = value;
|
|
||||||
this.expectedResult = expectedResult;
|
|
||||||
this.expectedError = expectedError;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// init
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
@Before
|
|
||||||
public void initialize() {
|
|
||||||
Gson gson = new GsonBuilder().create();
|
|
||||||
ValidationConfiguration validationConfiguration = gson.fromJson(config, ValidationConfiguration.class);
|
|
||||||
sut = new Validator(validationConfiguration, new TestColumnValueProvider());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// tests
|
// tests
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@Test
|
@ParameterizedTest
|
||||||
public void validation() {
|
@MethodSource("validationConfigurations")
|
||||||
System.out.println("===================================================");
|
public void validation(String config,
|
||||||
System.out.println(config);
|
String value,
|
||||||
System.out.println(value + " " + expectedResult + " " + expectedError);
|
Boolean expectedResult,
|
||||||
System.out.println("===================================================\n");
|
ValidationMessage expectedError) {
|
||||||
|
// setup
|
||||||
|
Gson gson = new GsonBuilder().create();
|
||||||
|
ValidationConfiguration validationConfiguration = gson.fromJson(config, ValidationConfiguration.class);
|
||||||
|
Validator sut = new Validator(validationConfiguration, new TestColumnValueProvider());
|
||||||
|
|
||||||
// execution
|
// execution
|
||||||
ValidationError result = sut.isValid(0, "column", value);
|
ValidationError result = sut.isValid(0, "column", value);
|
||||||
@@ -87,45 +48,42 @@ public class ValidatorTest {
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// parameters for tests
|
// parameters for tests
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@Parameterized.Parameters
|
public static Stream<Arguments> validationConfigurations() {
|
||||||
public static Collection validationConfigurations() {
|
return Stream.of(
|
||||||
return asList(new Object[][] {
|
Arguments.of( constraintsJSON("string", "required", true), "value", true, null ),
|
||||||
{ constraintsJSON("string", "required", true), "value", true, null },
|
Arguments.of( constraintsJSON("string", "required", true), "", false, new ValidationMessage("validation.message.not.empty") ),
|
||||||
{ constraintsJSON("string", "required", true), "", false, new ValidationMessage("validation.message.not.empty") },
|
Arguments.of( constraintsJSON("string", "required", true), null, false, new ValidationMessage("validation.message.not.empty") ),
|
||||||
{ constraintsJSON("string", "required", true), null, false, new ValidationMessage("validation.message.not.empty") },
|
Arguments.of( constraintsJSON("integer", null, true), "999", true, null ),
|
||||||
{ constraintsJSON("integer", null, true), "999", true, null },
|
Arguments.of( constraintsJSON("integer", null, true), "a", false, new ValidationMessage("validation.message.integer") ),
|
||||||
{ constraintsJSON("integer", null, true), "a", false, new ValidationMessage("validation.message.integer") },
|
Arguments.of( constraintsJSON("number", null, true), "999", true, null ),
|
||||||
{ constraintsJSON("number", null, true), "999", true, null },
|
Arguments.of( constraintsJSON("number", null, true), "999.000", true, null ),
|
||||||
{ constraintsJSON("number", null, true), "999.000", true, null },
|
Arguments.of( constraintsJSON("number", null, true), "a", false, new ValidationMessage("validation.message.double") ),
|
||||||
{ constraintsJSON("number", null, true), "a", false, new ValidationMessage("validation.message.double") },
|
Arguments.of( constraintsJSON("string", "minLength", 2), "12", true, null ),
|
||||||
{ constraintsJSON("string", "minLength", 2), "12", true, null },
|
Arguments.of( constraintsJSON("string", "minLength", 2), "1", false, new ValidationMessage("validation.message.min.length", "2") ),
|
||||||
{ constraintsJSON("string", "minLength", 2), "1", false, new ValidationMessage("validation.message.min.length", "2") },
|
Arguments.of( constraintsJSON("string", "maxLength", 2), "12", true, null ),
|
||||||
{ constraintsJSON("string", "maxLength", 2), "12", true, null },
|
Arguments.of( constraintsJSON("string", "maxLength", 2), "123", false, new ValidationMessage("validation.message.max.length", "2") ),
|
||||||
{ constraintsJSON("string", "maxLength", 2), "123", false, new ValidationMessage("validation.message.max.length", "2") },
|
Arguments.of( constraintsJSON("string", "pattern", "[a-z]*"), "abc", true, null ),
|
||||||
{ constraintsJSON("string", "pattern", "[a-z]*"), "abc", true, null },
|
Arguments.of( constraintsJSON("string", "pattern", "[a-z]*"), "abcA", false, new ValidationMessage("validation.message.regexp", "[a-z]*") ),
|
||||||
{ constraintsJSON("string", "pattern", "[a-z]*"), "abcA", false, new ValidationMessage("validation.message.regexp", "[a-z]*") },
|
Arguments.of( constraintsJSON("string", "enum", asList("a","b","c","d","e")), "c", true, null ),
|
||||||
{ constraintsJSON("string", "enum", asList("a","b","c","d","e")), "c", true, null },
|
Arguments.of( constraintsJSON("string", "enum", asList("a","b","c","d","e")), "f", false, new ValidationMessage("validation.message.value.of", "f", "a, b, c, d, e") ),
|
||||||
{ 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 },
|
Arguments.of( formatJSON("string", null), "some string", true, null ),
|
||||||
{ formatJSON("string", "email"), "test@javafx.ninja", true, null },
|
Arguments.of( formatJSON("string", "email"), "test@javafx.ninja", true, null ),
|
||||||
{ formatJSON("string", "email"), "wrong email", false, new ValidationMessage("validation.message.email") },
|
Arguments.of( formatJSON("string", "email"), "wrong email", false, new ValidationMessage("validation.message.email") ),
|
||||||
{ formatJSON("string", "uri"), "http://www.javafx.ninja", true, null },
|
Arguments.of( formatJSON("string", "uri"), "http://www.javafx.ninja", true, null ),
|
||||||
{ formatJSON("string", "uri"), "!$%&/()", false, new ValidationMessage("validation.message.uri") },
|
Arguments.of( formatJSON("string", "uri"), "!$%&/()", false, new ValidationMessage("validation.message.uri") ),
|
||||||
{ formatJSON("string", "binary"), "dGVzdA==", true, null },
|
Arguments.of( formatJSON("string", "binary"), "dGVzdA==", true, null ),
|
||||||
{ formatJSON("string", "binary"), "no binary", false, new ValidationMessage("validation.message.binary") },
|
Arguments.of( formatJSON("string", "binary"), "no binary", false, new ValidationMessage("validation.message.binary") ),
|
||||||
{ formatJSON("string", "uuid"), "6ba7b810-9dad-11d1-80b4-00c04fd430c8", true, null },
|
Arguments.of( formatJSON("string", "uuid"), "6ba7b810-9dad-11d1-80b4-00c04fd430c8", true, null ),
|
||||||
{ formatJSON("string", "uuid"), "no uuid", false, new ValidationMessage("validation.message.uuid") },
|
Arguments.of( formatJSON("string", "uuid"), "no uuid", false, new ValidationMessage("validation.message.uuid") ),
|
||||||
{ formatJSON("date", null), "2015-11-27", true, null },
|
Arguments.of( formatJSON("date", null), "2015-11-27", true, null ),
|
||||||
{ formatJSON("date", null), "27.11.2015", false, new ValidationMessage("validation.message.date.format", "yyyy-MM-dd") },
|
Arguments.of( formatJSON("date", null), "27.11.2015", false, new ValidationMessage("validation.message.date.format", "yyyy-MM-dd") ),
|
||||||
{ formatJSON("date", "yyyyMMdd"), "20151127", true, null },
|
Arguments.of( formatJSON("date", "yyyyMMdd"), "20151127", true, null ),
|
||||||
{ formatJSON("date", "yyyyMMdd"), "27.11.2015", false, new ValidationMessage("validation.message.date.format", "yyyyMMdd") },
|
Arguments.of( formatJSON("date", "yyyyMMdd"), "27.11.2015", false, new ValidationMessage("validation.message.date.format", "yyyyMMdd") ),
|
||||||
|
|
||||||
|
Arguments.of( customAttributeJSON( "groovy", "value.contains('a')? 'true' : 'no a inside'"), "abcdef", true, null ),
|
||||||
{ customAttributeJSON( "groovy", "value.contains('a')? 'true' : 'no a inside'"), "abcdef", true, null },
|
Arguments.of( customAttributeJSON( "groovy", "value.contains('a')? 'true' : 'no a inside'"), "bcdefg", false, new ValidationMessage("no a inside") )
|
||||||
{ customAttributeJSON( "groovy", "value.contains('a')? 'true' : 'no a inside'"), "bcdefg", false, new ValidationMessage("no a inside") },
|
);
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String constraintsJSON(String type, String constraint, Object value) {
|
public static String constraintsJSON(String type, String constraint, Object value) {
|
||||||
|
|||||||
Reference in New Issue
Block a user