我想一次执行两个任务
- 上传多个文件。
- 当上传所有选定的文件时,我想打开一个窗口并选择其类型和其他工作,然后保存。
当我进行单次上传时,它可以正常工作。
现在,我正在尝试使用MultiFileUpload addon实现多努力,但事件public void handleFile(InputStream in, String filename, String mimetype, long length)
逐个触发。我想在上传最后一个文件时打开窗口。如何检测最后一个文件已上传?
这是我的代码:
protected void init(VaadinRequest vaadinRequest) {
FormLayout layout = new FormLayout();
UploadFinishedHandler uploadFinishedHandler = new UploadFinishedHandler() {
@Override
public void handleFile(InputStream in, String filename, String mimetype, long length) {
try {
FileOutputStream fos = null;
String filePath = "/home/yassir/Desktop/";
File dirFile = new File(filePath);
if (!dirFile.exists()) {
dirFile.mkdirs();
}
filePath += filename;
Button btn = new Button(filename);
layout.addComponent(btn);
File file = new File(filePath);
fos = new FileOutputStream(file);
byte[] buffer = new byte[in.available()];
in.read(buffer);
fos.write(buffer);
fos.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(MyUI.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(MyUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
};
UploadStateWindow uploadStateWindow = new UploadStateWindow();
MultiFileUpload multiFileUpload = new MultiFileUpload(uploadFinishedHandler, uploadStateWindow);
layout.addComponent(multiFileUpload);
setContent(layout);
}
我将调用函数createWindowType()
(我在此处没有添加)。
您可以使用AlluPloAdfinedhandler处理最后一个文件。
类似的东西应该有效:
multiFileUpload.setAllUploadFinishedHandler(new AllUploadFinishedHandler() {
@Override
public void finished() {
//open window here
}
});
每次以下时间都会调用此听众
- 上传;
- 没有其他上传。