Skip to content

Commit

Permalink
Change file chooser to enable opening multiple files
Browse files Browse the repository at this point in the history
Update error message to show names of invalid files

Signed-off-by: kana0011 <marklynoel.alvarez@synacy.com>
  • Loading branch information
kana0011 committed Aug 1, 2016
1 parent c51e91d commit 0a842d7
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/ph/kana/csvv/controller/CsvViewerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.cell.MapValueFactory;
Expand Down Expand Up @@ -31,10 +30,11 @@ public class CsvViewerController extends AbstractController {
@FXML
public void openCsvMenuClick() {
FileChooser fileChooser = createFileChooser();
File csvFile = fileChooser.showOpenDialog(window);
List<File> csvFiles = fileChooser.showOpenMultipleDialog(window);

if (csvFile != null) {
openCsvTab(csvFile);
if (csvFiles != null) {
csvFiles.stream()
.forEach(this::openCsvTab);
}
}

Expand Down Expand Up @@ -118,7 +118,7 @@ private Tab createCsvTab(File csvFile) {

return tab;
} catch (IOException e) {
reportError(e);
reportIOException(e, csvFile);
return null;
}
}
Expand All @@ -144,11 +144,13 @@ private void setupCellColumn(TableColumn column) {
column.setMinWidth(100.0);
}

private void reportError(Exception e) {
private void reportIOException(IOException e, File f) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("CSV Viewer Error!");
alert.setHeaderText(e.getClass().getSimpleName());
alert.setContentText("Failed to open file!\nCSV format might be broken.");
alert.setHeaderText("Failed to Open File!");
alert.setContentText(String.format("Failed to open file: %s\nFile might be corrupted or not a valid CSV.", f.getName()));

e.printStackTrace(System.err);
alert.showAndWait();
}
}

0 comments on commit 0a842d7

Please sign in to comment.