I have Vaadin 7 code to give the user the ability to upload a file:
Button btnDownloadResults = new Button("Download Results", FontAwesome.CLOUD_DOWNLOAD);
resource = new StreamResource(new MyStreamResource(), suggestedSaveAsFilename);
new FileDownloader(resource).extend(btnDownloadResults);
I would like to run the code when the download is successful, or even if the download starts. Used for this: closing the window, starting the progress counter or increasing the number of downloads.
Unlike the Vaadin download component, FileDownloader does not have listeners to find out when a file download fails, runs, or starts.
Here is a simplified version of my StreamResouce subclass:
public class MyStreamResource implements StreamSource {
@Override
public InputStream getStream() {
String filename = ;
try {
final File results = new File(FilenameUtils.normalize(filename));
return new FileInputStream(results);
} catch (FileNotFoundException fnfe) {
String errorMsg = "Cannot download results. Try again later, or contact your sysadmin.";
Utilities.showError(errorMsg);
return null;
} catch (Exception e) {
Utilities.logAndShowException(e);
return null;
}
}
}
Note that the getStream method returns before the user is prompted to save the file (which they can cancel). Therefore, I cannot run anything from within this method.
, , FileDownloader :
FileDownloader fileDownloader = new FileDownloader(fileInputStream) {
private static final long serialVersionUID = -4584979099145066535L;
@Override
public boolean handleConnectorRequest(VaadinRequest request, VaadinResponse response, String path) throws IOException {
boolean result = super.handleConnectorRequest(request, response, path);
if (result) {
}
return result;
}
} ;
, ( , StreamSource null.)
?