Skip to content

Commit 0a842d7

Browse files
author
kana0011
committed
Change file chooser to enable opening multiple files
Update error message to show names of invalid files Signed-off-by: kana0011 <marklynoel.alvarez@synacy.com>
1 parent c51e91d commit 0a842d7

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/ph/kana/csvv/controller/CsvViewerController.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import javafx.fxml.FXML;
44
import javafx.fxml.FXMLLoader;
5-
import javafx.scene.Parent;
65
import javafx.scene.Scene;
76
import javafx.scene.control.*;
87
import javafx.scene.control.cell.MapValueFactory;
@@ -31,10 +30,11 @@ public class CsvViewerController extends AbstractController {
3130
@FXML
3231
public void openCsvMenuClick() {
3332
FileChooser fileChooser = createFileChooser();
34-
File csvFile = fileChooser.showOpenDialog(window);
33+
List<File> csvFiles = fileChooser.showOpenMultipleDialog(window);
3534

36-
if (csvFile != null) {
37-
openCsvTab(csvFile);
35+
if (csvFiles != null) {
36+
csvFiles.stream()
37+
.forEach(this::openCsvTab);
3838
}
3939
}
4040

@@ -118,7 +118,7 @@ private Tab createCsvTab(File csvFile) {
118118

119119
return tab;
120120
} catch (IOException e) {
121-
reportError(e);
121+
reportIOException(e, csvFile);
122122
return null;
123123
}
124124
}
@@ -144,11 +144,13 @@ private void setupCellColumn(TableColumn column) {
144144
column.setMinWidth(100.0);
145145
}
146146

147-
private void reportError(Exception e) {
147+
private void reportIOException(IOException e, File f) {
148148
Alert alert = new Alert(AlertType.ERROR);
149149
alert.setTitle("CSV Viewer Error!");
150-
alert.setHeaderText(e.getClass().getSimpleName());
151-
alert.setContentText("Failed to open file!\nCSV format might be broken.");
150+
alert.setHeaderText("Failed to Open File!");
151+
alert.setContentText(String.format("Failed to open file: %s\nFile might be corrupted or not a valid CSV.", f.getName()));
152+
153+
e.printStackTrace(System.err);
152154
alert.showAndWait();
153155
}
154156
}

0 commit comments

Comments
 (0)