13 Commits
1.0.0 ... 1.0.1

Author SHA1 Message Date
Andreas Billmann
9961373d76 Update version 2021-11-22 22:11:04 +01:00
Andreas Billmann
fd6938fa80 Merge pull request #23 from apixandru/loader_exceptions
#22 don't ignore loading exceptions
2021-11-22 22:08:58 +01:00
Alexandru
78f3f5909e #22 don't ignore loading exceptions 2021-10-29 05:05:13 -07:00
Andreas Billmann
d572dcdeed JDK17 2021-10-02 09:26:59 +02:00
af6ce56f71 changed to jdk 17 LTS 2021-10-02 07:28:16 +02:00
2f692352b7 remove travis badge 2020-11-02 22:02:45 +01:00
5b59c76200 try to build on ubuntu 2020-11-02 22:00:20 +01:00
7e40daa1e5 remove branch dependencies 2020-11-02 21:54:59 +01:00
2da843e1e2 added gthub action badge 2020-11-02 21:45:28 +01:00
d1ffd09941 use github action 2020-11-02 21:42:57 +01:00
Andreas Billmann
4c29d29bf5 Update README.md 2020-10-06 02:19:28 +02:00
Andreas Billmann
c4f91d94f1 Merge pull request #18 from frosch95/update-dependencies
update the dependencies
2020-10-02 23:43:52 +02:00
8c43c5a1de update the dependencies 2020-10-02 23:40:31 +02:00
10 changed files with 151 additions and 46 deletions

21
.github/workflows/build-and-test.yml vendored Normal file
View 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

View File

@@ -1 +0,0 @@
language: java

View File

@@ -1,5 +1,5 @@
# SmartCSV.fx
[![Build Status](https://travis-ci.org/frosch95/SmartCSV.fx.svg?branch=master)](https://travis-ci.org/frosch95/SmartCSV.fx) ![GitHub All Releases](https://img.shields.io/github/downloads/frosch95/SmartCSV.fx/total) ![GitHub](https://img.shields.io/github/license/frosch95/SmartCSV.fx) ![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/frosch95/SmartCSV.fx?label=version) ![GitHub Release Date](https://img.shields.io/github/release-date/frosch95/SmartCSV.fx)
![Build and Test](https://github.com/frosch95/SmartCSV.fx/workflows/Build%20and%20Test%20with%20Gradle/badge.svg) ![GitHub All Releases](https://img.shields.io/github/downloads/frosch95/SmartCSV.fx/total) ![GitHub](https://img.shields.io/github/license/frosch95/SmartCSV.fx) ![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/frosch95/SmartCSV.fx?label=version) ![GitHub Release Date](https://img.shields.io/github/release-date/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>

View File

@@ -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'

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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());

View 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();
}
}

View File

@@ -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) {

View File

@@ -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) {