mirror of
https://github.com/frosch95/SmartCSV.fx.git
synced 2026-04-11 13:38:23 +02:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9961373d76 | ||
|
|
fd6938fa80 | ||
|
|
78f3f5909e | ||
|
|
d572dcdeed | ||
| af6ce56f71 | |||
| 2f692352b7 | |||
| 5b59c76200 | |||
| 7e40daa1e5 | |||
| 2da843e1e2 | |||
| d1ffd09941 | |||
|
|
4c29d29bf5 | ||
|
|
c4f91d94f1 | ||
| 8c43c5a1de |
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 +0,0 @@
|
||||
language: java
|
||||
@@ -1,5 +1,5 @@
|
||||
# SmartCSV.fx
|
||||
[](https://travis-ci.org/frosch95/SmartCSV.fx)    
|
||||
    
|
||||
## 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.
|
||||
|
||||
@@ -24,7 +24,7 @@ binary distribution of the [latest release (1.0.0)](https://github.com/frosch95/
|
||||
### The MIT License (MIT)
|
||||
|
||||
|
||||
Copyright (c) 2015-2019 Andreas Billmann <andreas.billmann@javafx.ninja>
|
||||
Copyright (c) 2015-2020 Andreas Billmann <andreas.billmann@javafx.ninja>
|
||||
|
||||
|
||||
|
||||
|
||||
40
build.gradle
40
build.gradle
@@ -11,29 +11,33 @@ repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
sourceCompatibility = 17
|
||||
targetCompatibility = 17
|
||||
|
||||
javafx {
|
||||
modules = [ 'javafx.controls', 'javafx.fxml' ]
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
|
||||
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.2'
|
||||
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.5.2'
|
||||
testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '2.2'
|
||||
testCompile group: 'org.mockito', name: 'mockito-core', version:'3.1.0'
|
||||
compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '3.0.0-beta-3'
|
||||
compile group: 'org.springframework', name:'spring-context', version: '5.2.0.RELEASE'
|
||||
compile group: 'net.sf.supercsv', name: 'super-csv', version: '2.4.0'
|
||||
compile group: 'commons-validator', name: 'commons-validator', version: '1.6'
|
||||
compile group: 'de.jensd', name: 'fontawesomefx-commons', version: '11.0'
|
||||
compile group: 'de.jensd', name: 'fontawesomefx-fontawesome', version: '4.7.0-11'
|
||||
compile group: 'de.jensd', name: 'fontawesomefx-materialdesignfont', version: '1.7.22-11'
|
||||
compile group: 'de.jensd', name: 'fontawesomefx-materialicons', version: '2.2.0-11'
|
||||
compile group: 'org.controlsfx', name: 'controlsfx', version: '11.0.0'
|
||||
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
|
||||
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.0'
|
||||
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.0'
|
||||
compile group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.10.2'
|
||||
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.2'
|
||||
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.5.2'
|
||||
testImplementation group: 'org.hamcrest', name: 'hamcrest-library', version: '2.2'
|
||||
testImplementation group: 'org.mockito', name: 'mockito-core', version:'3.1.0'
|
||||
implementation group: 'org.codehaus.groovy', name: 'groovy-all', version: '3.0.6'
|
||||
implementation group: 'org.springframework', name:'spring-context', version: '5.3.10'
|
||||
implementation group: 'net.sf.supercsv', name: 'super-csv', version: '2.4.0'
|
||||
implementation group: 'commons-validator', name: 'commons-validator', version: '1.7'
|
||||
implementation group: 'de.jensd', name: 'fontawesomefx-commons', version: '11.0'
|
||||
implementation group: 'de.jensd', name: 'fontawesomefx-fontawesome', version: '4.7.0-11'
|
||||
implementation group: 'de.jensd', name: 'fontawesomefx-materialdesignfont', version: '1.7.22-11'
|
||||
implementation group: 'de.jensd', name: 'fontawesomefx-materialicons', version: '2.2.0-11'
|
||||
implementation group: 'org.controlsfx', name: 'controlsfx', version: '11.0.2'
|
||||
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
|
||||
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.0'
|
||||
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.0'
|
||||
implementation group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.10.5'
|
||||
}
|
||||
|
||||
test {
|
||||
@@ -41,5 +45,5 @@ test {
|
||||
}
|
||||
|
||||
group 'ninja.javafx'
|
||||
version '1.0.0'
|
||||
version '1.0.1'
|
||||
mainClassName = 'ninja.javafx.smartcsv.Main'
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -29,6 +29,7 @@ package ninja.javafx.smartcsv.csv;
|
||||
import ninja.javafx.smartcsv.FileReader;
|
||||
import ninja.javafx.smartcsv.fx.table.model.CSVModel;
|
||||
import ninja.javafx.smartcsv.fx.table.model.CSVRow;
|
||||
import org.supercsv.exception.SuperCsvException;
|
||||
import org.supercsv.io.CsvMapReader;
|
||||
import org.supercsv.io.ICsvMapReader;
|
||||
|
||||
@@ -47,10 +48,8 @@ public class CSVFileReader extends CSVConfigurable implements FileReader<CSVMode
|
||||
@Override
|
||||
public void read(File file) throws IOException {
|
||||
|
||||
ICsvMapReader mapReader = null;
|
||||
try {
|
||||
mapReader = new CsvMapReader(new java.io.FileReader(file.getAbsoluteFile(), Charset.forName(fileEncoding)),
|
||||
csvPreference);
|
||||
try (ICsvMapReader mapReader = new CsvMapReader(new java.io.FileReader(file.getAbsoluteFile(), Charset.forName(fileEncoding)),
|
||||
csvPreference)) {
|
||||
model = new CSVModel();
|
||||
|
||||
// the header columns are used as the keys to the Map
|
||||
@@ -64,11 +63,10 @@ public class CSVFileReader extends CSVConfigurable implements FileReader<CSVMode
|
||||
model.addValue(row, column, customerMap.get(column));
|
||||
}
|
||||
}
|
||||
|
||||
} finally {
|
||||
if (mapReader != null) {
|
||||
mapReader.close();
|
||||
}
|
||||
} catch (IOException | SuperCsvException ex) {
|
||||
// TODO perhaps a custom NinjaException that can properly identify and localize the exception message
|
||||
// is this a file not found? is this a corrupt csv? etc
|
||||
throw new IOException("Failed to read " + file + ": " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ import ninja.javafx.smartcsv.fx.table.ValidationCellFactory;
|
||||
import ninja.javafx.smartcsv.fx.table.model.CSVModel;
|
||||
import ninja.javafx.smartcsv.fx.table.model.CSVRow;
|
||||
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.SaveFileService;
|
||||
import ninja.javafx.smartcsv.fx.validation.ValidationEditorController;
|
||||
@@ -85,6 +86,7 @@ import static javafx.scene.layout.AnchorPane.*;
|
||||
@Component
|
||||
public class SmartCSVController extends FXMLController {
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// constants
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -595,8 +597,9 @@ public class SmartCSVController extends FXMLController {
|
||||
//Show open file dialog
|
||||
File file = fileChooser.showOpenDialog(applicationPane.getScene().getWindow());
|
||||
if (file != null) {
|
||||
File previousFile = storageFile.getFile();
|
||||
storageFile.setFile(file);
|
||||
useLoadFileService(storageFile, t -> resetContent());
|
||||
useLoadFileService(storageFile, t -> resetContent(), () -> storageFile.setFile(previousFile));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -625,13 +628,20 @@ public class SmartCSVController extends FXMLController {
|
||||
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.restart();
|
||||
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.restart();
|
||||
saveFileService.setOnSucceeded(t -> resetContent());
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -34,17 +34,17 @@ import ninja.javafx.smartcsv.files.FileStorage;
|
||||
* Service class for async load of a csv file
|
||||
*/
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Task createTask() {
|
||||
return new Task() {
|
||||
protected Task<Void> createTask() {
|
||||
return new Task<>() {
|
||||
@Override
|
||||
protected Void call() throws Exception {
|
||||
if (file != null) {
|
||||
|
||||
@@ -31,22 +31,22 @@ import javafx.concurrent.Task;
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Task createTask() {
|
||||
return new Task() {
|
||||
protected Task<Void> createTask() {
|
||||
return new Task<>() {
|
||||
@Override
|
||||
protected Void call() throws Exception {
|
||||
protected Void call() {
|
||||
try {
|
||||
file.save();
|
||||
} catch (Throwable ex) {
|
||||
|
||||
Reference in New Issue
Block a user