diff --git a/src/main/java/org/seagrid/desktop/ui/prestageupload/controller/PrestageUploadController.java b/src/main/java/org/seagrid/desktop/ui/prestageupload/controller/PrestageUploadController.java index 09a0a5c..7bf0407 100644 --- a/src/main/java/org/seagrid/desktop/ui/prestageupload/controller/PrestageUploadController.java +++ b/src/main/java/org/seagrid/desktop/ui/prestageupload/controller/PrestageUploadController.java @@ -20,14 +20,23 @@ */ package org.seagrid.desktop.ui.prestageupload.controller; +import javafx.concurrent.Service; +import javafx.concurrent.Task; +import javafx.concurrent.WorkerStateEvent; import javafx.fxml.FXML; +import javafx.scene.control.Alert; import javafx.scene.control.Button; +import javafx.scene.control.Label; import javafx.scene.layout.GridPane; import javafx.stage.FileChooser; +import org.seagrid.desktop.connectors.NextcloudStorage.NextcloudFileUploadTask; +import org.seagrid.desktop.ui.commons.SEAGridDialogHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; +import java.util.HashMap; +import java.util.Map; public class PrestageUploadController { private final static Logger logger = LoggerFactory.getLogger(PrestageUploadController.class); @@ -43,15 +52,73 @@ public class PrestageUploadController { @FXML public GridPane preuploadGridPane; + @FXML + public Label chosenFile; + + Map uploadFiles = new HashMap<>(); + @FXML public void initialize() { pickFile.setOnAction(event -> { - fileChooser = new FileChooser(); - fileChooser.setTitle("Open Resource File"); - File selectedFiles = fileChooser.showOpenDialog(null); + try { + fileChooser = new FileChooser(); + fileChooser.setTitle("Open Resource File"); + File file = fileChooser.showOpenDialog(null); + if (file != null) { + String fileAsString = file.getName(); + String remotePath = "/Documents/InputFiles/" + fileAsString; + String filePath = file.toString(); + chosenFile.setText("File: " + fileAsString); + uploadFiles.put(remotePath, file); + } else { + chosenFile.setText(null); + } + + } catch (Exception ex) { + SEAGridDialogHelper.showExceptionDialog(ex, "Caught Exception", null, "Unable to select file"); + } + }); + + saveButton.setOnAction(event -> { + try { + if (uploadFiles.size() > 0) + { + Service fileUploadService = getPreFileUploadService(uploadFiles); + fileUploadService.start(); + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setTitle("File Upload Status"); + alert.setContentText("File Upload Completed"); + alert.showAndWait(); + } + } catch (Exception e) { + + } }); + } + public Service getPreFileUploadService(Map uploadFiles) { + Service service = new Service() { + @Override + protected Task createTask() { + try { + return new NextcloudFileUploadTask(uploadFiles); + } catch (Exception e) { + e.printStackTrace(); + SEAGridDialogHelper.showExceptionDialogAndWait(e, "Exception Dialog", chosenFile.getScene().getWindow(), + "Unable To Connect To File Server !"); + } + return null; + } + }; + SEAGridDialogHelper.showProgressDialog(service,"Progress Dialog",chosenFile.getScene().getWindow(), + "Uploading Experiment Input Files"); + service.setOnFailed((WorkerStateEvent t) -> { + SEAGridDialogHelper.showExceptionDialogAndWait(service.getException(), "Exception Dialog", + chosenFile.getScene().getWindow(), "File Upload Failed"); + }); + return service; + } } \ No newline at end of file diff --git a/src/main/resources/views/prestageupload/upload-files.fxml b/src/main/resources/views/prestageupload/upload-files.fxml index 9a8a2c7..50c5d34 100644 --- a/src/main/resources/views/prestageupload/upload-files.fxml +++ b/src/main/resources/views/prestageupload/upload-files.fxml @@ -12,6 +12,8 @@ +