Skip to content

Commit

Permalink
Fixes for generic upload file dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhorridge committed May 17, 2024
1 parent 5470ad7 commit 08de6ec
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package edu.stanford.bmir.protege.web.client.merge;

import com.google.gwt.core.client.GWT;
import edu.stanford.bmir.protege.web.client.dispatch.DispatchServiceManager;
import edu.stanford.bmir.protege.web.client.library.dlg.WebProtegeDialog;
import edu.stanford.bmir.protege.web.client.upload.UploadFileDialogController;
import edu.stanford.bmir.protege.web.client.upload.UploadFileDialogControllerFactory;
import edu.stanford.bmir.protege.web.client.upload.UploadFileResultHandler;
import edu.stanford.bmir.protege.web.shared.csv.DocumentId;
import edu.stanford.bmir.protege.web.shared.project.ProjectId;
Expand All @@ -22,27 +24,39 @@ public class UploadAndMergeProjectWorkflow {
@Nonnull
private final MergeUploadedProjectWorkflow mergeWorkflow;

@Nonnull
private final DispatchServiceManager dispatchServiceManager;

@Nonnull
private final UploadFileDialogControllerFactory uploadFileDialogControllerFactory;

@Inject
public UploadAndMergeProjectWorkflow(@Nonnull MergeUploadedProjectWorkflow mergeWorkflow) {
public UploadAndMergeProjectWorkflow(@Nonnull MergeUploadedProjectWorkflow mergeWorkflow,
@Nonnull DispatchServiceManager dispatchServiceManager,
@Nonnull UploadFileDialogControllerFactory uploadFileDialogControllerFactory) {
this.mergeWorkflow = checkNotNull(mergeWorkflow);
this.dispatchServiceManager = dispatchServiceManager;
this.uploadFileDialogControllerFactory = uploadFileDialogControllerFactory;
}

public void start(ProjectId projectId) {
uploadProject(projectId);
}

private void uploadProject(final ProjectId projectId) {
UploadFileDialogController uploadFileDialogController = new UploadFileDialogController("Upload ontologies", new UploadFileResultHandler() {
@Override
public void handleFileUploaded(DocumentId fileDocumentId) {
startMergeWorkflow(projectId, fileDocumentId);
}

@Override
public void handleFileUploadFailed(String errorMessage) {
GWT.log("Upload failed");
}
});
UploadFileDialogController uploadFileDialogController = uploadFileDialogControllerFactory.create(
"Upload ontologies", new UploadFileResultHandler() {
@Override
public void handleFileUploaded(DocumentId fileDocumentId) {
startMergeWorkflow(projectId, fileDocumentId);
}

@Override
public void handleFileUploadFailed(String errorMessage) {
GWT.log("Upload failed");
}
}
);
WebProtegeDialog.showDialog(uploadFileDialogController);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import edu.stanford.bmir.protege.web.client.library.dlg.WebProtegeDialogButtonHandler;
import edu.stanford.bmir.protege.web.client.library.dlg.WebProtegeDialogCloser;
import edu.stanford.bmir.protege.web.client.upload.UploadFileDialogController;
import edu.stanford.bmir.protege.web.client.upload.UploadFileDialogControllerFactory;
import edu.stanford.bmir.protege.web.client.upload.UploadFileResultHandler;
import edu.stanford.bmir.protege.web.shared.csv.DocumentId;
import edu.stanford.bmir.protege.web.shared.merge_add.GetAllOntologiesAction;
Expand All @@ -30,6 +31,9 @@ public class UploadAndMergeAdditionsProjectsWorkflow {
@Nonnull
private final DispatchServiceManager dispatchServiceManager;

@Nonnull
private final UploadFileDialogControllerFactory uploadFileDialogControllerFactory;

@Nonnull
private final DispatchErrorMessageDisplay errorDisplay;

Expand All @@ -39,10 +43,12 @@ public class UploadAndMergeAdditionsProjectsWorkflow {
@Inject
public UploadAndMergeAdditionsProjectsWorkflow(@Nonnull SelectOptionForMergeAdditionsWorkflow selectOptionsWorkflow,
@Nonnull DispatchServiceManager dispatchServiceManager,
@Nonnull UploadFileDialogControllerFactory uploadFileDialogControllerFactory,
@Nonnull DispatchErrorMessageDisplay errorDisplay,
@Nonnull ProgressDisplay progressDisplay) {
this.selectOptionsWorkflow = selectOptionsWorkflow;
this.dispatchServiceManager = dispatchServiceManager;
this.uploadFileDialogControllerFactory = uploadFileDialogControllerFactory;
this.errorDisplay = errorDisplay;
this.progressDisplay = progressDisplay;
}
Expand All @@ -52,7 +58,7 @@ public void start(ProjectId projectId) {
}

private void uploadProject(final ProjectId projectId) {
UploadFileDialogController uploadFileDialogController = new UploadFileDialogController("Upload ontologies", new UploadFileResultHandler() {
UploadFileDialogController uploadFileDialogController = uploadFileDialogControllerFactory.create("Upload ontologies", new UploadFileResultHandler() {
@Override
public void handleFileUploaded(DocumentId fileDocumentId) {
getOntologies(projectId, fileDocumentId);
Expand Down Expand Up @@ -90,13 +96,10 @@ private void selectOntologies(ProjectId projectId, DocumentId documentId, GetAll

SelectOntologiesForMergeView view = new SelectOntologiesForMergeViewImpl(list);
SelectOntologiesForMergeDialogController controller = new SelectOntologiesForMergeDialogController(view);
controller.setDialogButtonHandler(DialogButton.OK, new WebProtegeDialogButtonHandler<List<OWLOntologyID>>() {
@Override
public void handleHide(List<OWLOntologyID> data, WebProtegeDialogCloser closer) {
List<OWLOntologyID> l = view.getSelectedOntologies();
startSelectAdditionsWorkflow(projectId, documentId, list, l);
closer.hide();
}
controller.setDialogButtonHandler(DialogButton.OK, (data, closer) -> {
List<OWLOntologyID> l = view.getSelectedOntologies();
startSelectAdditionsWorkflow(projectId, documentId, list, l);
closer.hide();
});
WebProtegeDialog.showDialog(controller);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package edu.stanford.bmir.protege.web.client.upload;

import com.google.auto.factory.AutoFactory;
import com.google.auto.factory.Provided;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.Widget;
import edu.stanford.bmir.protege.web.client.dispatch.DispatchErrorMessageDisplay;
import edu.stanford.bmir.protege.web.client.dispatch.DispatchServiceCallbackWithProgressDisplay;
import edu.stanford.bmir.protege.web.client.dispatch.DispatchServiceManager;
import edu.stanford.bmir.protege.web.client.dispatch.ProgressDisplay;
import edu.stanford.bmir.protege.web.client.library.dlg.*;
import edu.stanford.bmir.protege.web.client.progress.ProgressMonitor;
import edu.stanford.bmir.protege.web.client.uuid.UuidV4;
import edu.stanford.bmir.protege.web.shared.upload.SubmitFileAction;
import edu.stanford.bmir.protege.web.shared.upload.SubmitFileResult;

import javax.annotation.Nonnull;

Expand All @@ -15,39 +24,65 @@
* Bio-Medical Informatics Research Group<br>
* Date: 19/05/2013
*/
@AutoFactory
public class UploadFileDialogController extends WebProtegeOKCancelDialogController<String> {

private final DispatchServiceManager dispatch;

private final DispatchErrorMessageDisplay errorMessageDisplay;

private final ProgressDisplay progressDisplay;

private UploadFileDialogForm form = new UploadFileDialogForm();

public UploadFileDialogController(String title, final UploadFileResultHandler resultHandler) {
public UploadFileDialogController(String title,
final UploadFileResultHandler resultHandler,
@Provided DispatchServiceManager dispatch,
@Provided DispatchErrorMessageDisplay errorMessageDisplay,
@Provided ProgressDisplay progressDisplay) {
super(title);
setDialogButtonHandler(DialogButton.OK, new WebProtegeDialogButtonHandler<String>() {
@Override
public void handleHide(String data, final WebProtegeDialogCloser closer) {
ProgressMonitor.get().showProgressMonitor("Uploading", "Uploading file");
form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
public void onSubmitComplete(FormPanel.SubmitCompleteEvent event) {
ProgressMonitor.get().hideProgressMonitor();
GWT.log("Submittion of file is complete");
FileUploadResponse result = new FileUploadResponse(event.getResults());
if (result.wasUploadAccepted()) {
GWT.log("Successful upload");
resultHandler.handleFileUploaded(result.getDocumentId());

}
else {
GWT.log("Upload rejected: " + result.getUploadRejectedMessage());
resultHandler.handleFileUploadFailed(result.getUploadRejectedMessage());
}
closer.hide();

}
});
form.submit();
}
});
this.dispatch = dispatch;
this.errorMessageDisplay = errorMessageDisplay;
this.progressDisplay = progressDisplay;
setDialogButtonHandler(DialogButton.OK, (data, closer) -> handleButtonPress(resultHandler, closer));
form.getFileUpload().getElement().setId(UuidV4.uuidv4());
}

private void handleButtonPress(UploadFileResultHandler resultHandler, WebProtegeDialogCloser closer) {
ProgressMonitor.get().showProgressMonitor("Preparing file", "Preparing file for upload. Please wait.");
FileUploadFileReader reader = new FileUploadFileReader();
reader.readFiles(form.getFileUpload().getElement().getId(),
content -> {
dispatch.execute(SubmitFileAction.create(content), new DispatchServiceCallbackWithProgressDisplay<SubmitFileResult>(errorMessageDisplay,
progressDisplay) {
@Override
public String getProgressDisplayTitle() {
return "Uploading file";
}

@Override
public String getProgressDisplayMessage() {
return "Please wait";
}

@Override
public void handleSuccess(SubmitFileResult submitFileResult) {
closer.hide();
resultHandler.handleFileUploaded(submitFileResult.getFileSubmissionId());
}

@Override
public void handleErrorFinally(Throwable throwable) {
closer.hide();
resultHandler.handleFileUploadFailed("An error occurred uploading the file: " + throwable.getMessage());
}
});
},
errorHandler -> {
ProgressMonitor.get().hideProgressMonitor();
resultHandler.handleFileUploadFailed("An error occurred preparing the file for upload");
});
}

@Nonnull
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ public String getValidationMessage() {
return "A file name must be specified. Please specify a file name";
}
}

public FileUpload getFileUpload() {
return fileUpload;
}
}

0 comments on commit 08de6ec

Please sign in to comment.