Skip to content

Commit

Permalink
backend changes for upload options
Browse files Browse the repository at this point in the history
  • Loading branch information
karankotz committed Sep 16, 2018
1 parent 29f17e4 commit acf687d
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -43,15 +52,73 @@ public class PrestageUploadController {
@FXML
public GridPane preuploadGridPane;

@FXML
public Label chosenFile;

Map<String,File> 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<Boolean> 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<Boolean> getPreFileUploadService(Map<String, File> uploadFiles) {
Service<Boolean> service = new Service<Boolean>() {
@Override
protected Task<Boolean> 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;
}

}
2 changes: 2 additions & 0 deletions src/main/resources/views/prestageupload/upload-files.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<children>
<GridPane fx:id="preuploadGridPane" prefHeight="120.0" prefWidth="250.0">
<children>
<Label fx:id="chosenFile" maxHeight="25.0" prefHeight="25.0" prefWidth="788.0" text="" wrapText="false" VBox.vgrow="NEVER">
</Label>
<Label text="Select File" GridPane.columnIndex="0" GridPane.rowIndex="0" />
<Button fx:id="pickFile" mnemonicParsing="false" text="Upload" GridPane.columnIndex="1"
GridPane.rowIndex="0" onAction="#initialize">
Expand Down

0 comments on commit acf687d

Please sign in to comment.