mirror of
https://github.com/frosch95/SmartCSV.fx.git
synced 2026-04-11 13:38:23 +02:00
remember the last directory and fixed NPE
This commit is contained in:
@@ -99,6 +99,7 @@ public class SmartCSVController extends FXMLController {
|
|||||||
private final SaveCSVService saveCSVService = new SaveCSVService();
|
private final SaveCSVService saveCSVService = new SaveCSVService();
|
||||||
private CSVModel model;
|
private CSVModel model;
|
||||||
private TableView<CSVRow> tableView;
|
private TableView<CSVRow> tableView;
|
||||||
|
private File lastDirectory;
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -189,6 +190,10 @@ public class SmartCSVController extends FXMLController {
|
|||||||
fileChooser.getExtensionFilters().add(extFilter);
|
fileChooser.getExtensionFilters().add(extFilter);
|
||||||
fileChooser.setTitle(title);
|
fileChooser.setTitle(title);
|
||||||
|
|
||||||
|
if (lastDirectory != null) {
|
||||||
|
fileChooser.setInitialDirectory(lastDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
//Show open file dialog
|
//Show open file dialog
|
||||||
final File file = fileChooser.showOpenDialog(applicationPane.getScene().getWindow());
|
final File file = fileChooser.showOpenDialog(applicationPane.getScene().getWindow());
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
@@ -225,8 +230,8 @@ public class SmartCSVController extends FXMLController {
|
|||||||
*/
|
*/
|
||||||
private void resetContent() {
|
private void resetContent() {
|
||||||
model = csvLoader.getData();
|
model = csvLoader.getData();
|
||||||
|
if (model != null) {
|
||||||
model.setValidator(validationLoader.getValidator());
|
model.setValidator(validationLoader.getValidator());
|
||||||
|
|
||||||
tableView = new TableView<>();
|
tableView = new TableView<>();
|
||||||
|
|
||||||
for (String column : model.getHeader()) {
|
for (String column : model.getHeader()) {
|
||||||
@@ -241,9 +246,9 @@ public class SmartCSVController extends FXMLController {
|
|||||||
AnchorPane.setRightAnchor(tableView, 0.0);
|
AnchorPane.setRightAnchor(tableView, 0.0);
|
||||||
tableWrapper.getChildren().setAll(tableView);
|
tableWrapper.getChildren().setAll(tableView);
|
||||||
|
|
||||||
|
|
||||||
errorList.setItems(model.getValidationError());
|
errorList.setItems(model.getValidationError());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a column with the given name to the tableview
|
* Adds a column with the given name to the tableview
|
||||||
@@ -305,6 +310,7 @@ public class SmartCSVController extends FXMLController {
|
|||||||
protected Void call() throws Exception {
|
protected Void call() throws Exception {
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
try {
|
try {
|
||||||
|
lastDirectory = file.getParentFile();
|
||||||
fileReader.read(file);
|
fileReader.read(file);
|
||||||
runLater(SmartCSVController.this::resetContent);
|
runLater(SmartCSVController.this::resetContent);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
|
|||||||
Reference in New Issue
Block a user