read and edit csv preferences

This commit is contained in:
Andreas Billmann
2016-01-11 09:03:22 +01:00
parent 5762354d19
commit 789c5012a4
14 changed files with 391 additions and 12 deletions

View File

@@ -0,0 +1,45 @@
/*
The MIT License (MIT)
-----------------------------------------------------------------------------
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package ninja.javafx.smartcsv.csv;
import org.supercsv.prefs.CsvPreference;
/**
*
*/
public class CSVConfigurable {
protected CsvPreference csvPreference;
public CSVConfigurable() {
csvPreference = CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE;
}
public void setCsvPreference(CsvPreference csvPreference) {
this.csvPreference = csvPreference;
}
}

View File

@@ -32,7 +32,6 @@ import ninja.javafx.smartcsv.fx.table.model.CSVRow;
import org.springframework.stereotype.Service;
import org.supercsv.io.CsvMapReader;
import org.supercsv.io.ICsvMapReader;
import org.supercsv.prefs.CsvPreference;
import java.io.File;
import java.io.IOException;
@@ -42,7 +41,7 @@ import java.util.Map;
* reads the csv file and stores the values in csv model
*/
@Service
public class CSVFileReader implements FileReader {
public class CSVFileReader extends CSVConfigurable implements FileReader {
private CSVModel model;
@@ -51,7 +50,7 @@ public class CSVFileReader implements FileReader {
ICsvMapReader mapReader = null;
try {
mapReader = new CsvMapReader(new java.io.FileReader(file.getAbsoluteFile()), CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE);
mapReader = new CsvMapReader(new java.io.FileReader(file.getAbsoluteFile()), csvPreference);
model = new CSVModel(file.getAbsolutePath());
// the header columns are used as the keys to the Map

View File

@@ -31,8 +31,6 @@ import ninja.javafx.smartcsv.fx.table.model.CSVRow;
import org.springframework.stereotype.Service;
import org.supercsv.io.CsvMapWriter;
import org.supercsv.io.ICsvMapWriter;
import org.supercsv.prefs.CsvPreference;
import org.supercsv.quote.AlwaysQuoteMode;
import java.io.FileWriter;
import java.io.IOException;
@@ -44,16 +42,12 @@ import static java.util.stream.Collectors.toMap;
* filewriter for the csv
*/
@Service
public class CSVFileWriter {
public class CSVFileWriter extends CSVConfigurable {
public void saveFile(CSVModel model) throws IOException {
ICsvMapWriter mapWriter = null;
try {
CsvPreference preference = new CsvPreference.
Builder(CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE).
useQuoteMode(new AlwaysQuoteMode())
.build();
mapWriter = new CsvMapWriter(new FileWriter(model.getFilepath()), preference);
mapWriter = new CsvMapWriter(new FileWriter(model.getFilepath()), csvPreference);
mapWriter.writeHeader(model.getHeader());
for(CSVRow row: model.getRows()) {