mirror of
https://gitlab.com/kauron/jstudy
synced 2024-12-23 00:43:32 +01:00
Main: added merge and multiple file opening
This commit is contained in:
parent
76faea3fc7
commit
e02b863a39
1 changed files with 37 additions and 6 deletions
|
@ -83,12 +83,43 @@ public class Controller implements Initializable {
|
||||||
private void onLoadAction(ActionEvent event) {
|
private void onLoadAction(ActionEvent event) {
|
||||||
FileChooser chooser = new FileChooser();
|
FileChooser chooser = new FileChooser();
|
||||||
chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("JStudy file", "*.jsdb"));
|
chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("JStudy file", "*.jsdb"));
|
||||||
File file = chooser.showOpenDialog(root.getScene().getWindow());
|
List<File> list = chooser.showOpenMultipleDialog(root.getScene().getWindow());
|
||||||
if (file == null) return;
|
if (list == null || list.isEmpty()) return;
|
||||||
List<TestItem> aux = TestItem.loadFrom(file, TestItem.COLONS);
|
if (list.size() > 1) {
|
||||||
if (aux != null) {
|
ButtonType mergeBT = new ButtonType("Merge", ButtonBar.ButtonData.APPLY);
|
||||||
tabPane.getTabs().add(createTableTab(file.getName().substring(0, file.getName().lastIndexOf('.')), aux, file));
|
ButtonType openBT = new ButtonType("Open", ButtonBar.ButtonData.OK_DONE);
|
||||||
tabPane.getSelectionModel().selectLast();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue