1
0
Fork 0
mirror of https://gitlab.com/kauron/jstudy synced 2024-12-22 16:33:33 +01:00

Main: added merge and multiple file opening

This commit is contained in:
Carlos Galindo 2016-12-08 22:17:03 +01:00
parent 76faea3fc7
commit e02b863a39
Signed by: kauron
GPG key ID: 83E68706DEE119A3

View file

@ -83,14 +83,45 @@ public class Controller implements Initializable {
private void onLoadAction(ActionEvent event) {
FileChooser chooser = new FileChooser();
chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("JStudy file", "*.jsdb"));
File file = chooser.showOpenDialog(root.getScene().getWindow());
if (file == null) return;
List<File> list = chooser.showOpenMultipleDialog(root.getScene().getWindow());
if (list == null || list.isEmpty()) return;
if (list.size() > 1) {
ButtonType mergeBT = new ButtonType("Merge", ButtonBar.ButtonData.APPLY);
ButtonType openBT = new ButtonType("Open", ButtonBar.ButtonData.OK_DONE);
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.getDialogPane().getButtonTypes().clear();
alert.getDialogPane().getButtonTypes().addAll(mergeBT, openBT, ButtonType.CANCEL);
alert.setTitle("Opening files...");
alert.setHeaderText("Several files have been opened");
alert.setContentText("Merge files or open them separately?");
Optional<ButtonType> result = alert.showAndWait();
if (result.isPresent() && result.get().equals(mergeBT)) {
List<TestItem> aux = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
aux.addAll(TestItem.loadFrom(list.get(i), TestItem.COLONS));
}
tabPane.getTabs().add(createTableTab("Merge table", aux, null));
tabPane.getSelectionModel().selectLast();
} else if (result.isPresent() && result.get().equals(openBT)){
for (int i = 0; i < list.size(); i++) {
File file = list.get(i);
List<TestItem> aux = TestItem.loadFrom(file, TestItem.COLONS);
if (aux != null) {
tabPane.getTabs().add(createTableTab(file.getName().substring(0, file.getName().lastIndexOf('.')), aux, file));
}
}
}
} else {
File file = list.get(0);
List<TestItem> aux = TestItem.loadFrom(file, TestItem.COLONS);
if (aux != null) {
tabPane.getTabs().add(createTableTab(file.getName().substring(0, file.getName().lastIndexOf('.')), aux, file));
tabPane.getSelectionModel().selectLast();
}
}
}
@FXML
private void onImportAction(ActionEvent event) {