/** Cancel upload process and show an error message to the user. */ private void cancelUpload(String msg) { successful = false; uploadFinished(); if (fileInput instanceof IDragAndDropFileInput) { ((IDragAndDropFileInput) fileInput).reset(); } statusWidget.setStatus(IUploadStatus.Status.ERROR); statusWidget.setError(msg); }
/** Adds a file to the upload queue. */ private void addToQueue() { statusWidget.setStatus(IUploadStatus.Status.QUEUED); statusWidget.setProgress(0, 0); if (!fileQueue.contains(getInputName())) { onStartUpload(); fileQueue.add(getInputName()); if (!multiple && avoidRepeatedFiles) { fileUploading.add(getFileName()); } } }
private boolean validateExtension(String filename) { if (filename == null || filename.length() == 0) { return !avoidEmptyFile; } boolean valid = Utils.validateExtension(validExtensions, filename); if (!valid) { finished = true; statusWidget.setError(i18nStrs.uploaderInvalidExtension() + validExtensionsMsg); statusWidget.setStatus(Status.INVALID); } return valid; }
/** * Called when the uploader detects that the upload process has finished: - in the case of submit * complete. - in the case of error talking with the server. */ private void uploadFinished() { removeFromQueue(); finished = true; uploading = false; updateStatusTimer.cancel(); statusWidget.setVisible(false); if (successful) { if (avoidRepeatedFiles) { fileDone.addAll(fileInput.getFilenames()); statusWidget.setStatus(IUploadStatus.Status.SUCCESS); } else { statusWidget.setStatus(IUploadStatus.Status.SUCCESS); } } else if (canceled) { statusWidget.setStatus(IUploadStatus.Status.CANCELED); } else { statusWidget.setStatus(IUploadStatus.Status.ERROR); } onFinishUpload(); reatachIframe(uploadForm.getElement().getAttribute("target")); }
/** Cancel the current upload process. */ public void cancel() { if (getStatus() == Status.UNINITIALIZED) { return; } if (finished && !uploading) { if (successful) { try { sendAjaxRequestToDeleteUploadedFile(); } catch (Exception e) { } } else { statusWidget.setStatus(Status.DELETED); } return; } if (canceled || getStatus() == Status.CANCELING) { return; } canceled = true; automaticUploadTimer.cancel(); if (uploading) { updateStatusTimer.cancel(); try { sendAjaxRequestToCancelCurrentUpload(); } catch (Exception e) { log("Exception cancelling request " + e.getMessage(), e); } statusWidget.setStatus(IUploadStatus.Status.CANCELING); } else { uploadFinished(); reuse(); } }
/** Prepare the uploader for a new upload. */ public void reuse() { this.uploadForm.reset(); updateStatusTimer.cancel(); onSubmitComplete = uploading = canceled = finished = successful = false; statusWidget.setStatus(Status.UNINITIALIZED); }
/** * Method called when the file input has changed. This happens when the user selects a file. * * <p>Override this method if you want to add a customized behavior, but remember to call this in * your function */ protected void onChangeInput() { statusWidget.setStatus(Status.CHANGED); for (IUploader.OnChangeUploaderHandler handler : onChangeHandlers) { handler.onChange(this); } }