use of com.haulmont.cuba.gui.upload.FileUploadingAPI in project cuba by cuba-platform.
the class FileFrameController method init.
@Override
public void init(Map<String, Object> params) {
super.init(params);
uploadField = (FileUploadField) getComponent("uploadField");
filesTable = (Table) getComponent("files");
initGeneratedColumn();
ds = (CollectionDatasource) getDsContext().get("filesDs");
Button remove = (Button) getComponentNN("remove");
remove.setAction(new RemoveAction(filesTable, false));
uploadField.addFileUploadSucceedListener(e -> {
fd = metadata.create(FileDescriptor.class);
fd.setName(uploadField.getFileName());
fd.setExtension(FilenameUtils.getExtension(uploadField.getFileName()));
FileUploadingAPI fileUploading = AppBeans.get(FileUploadingAPI.NAME);
File file = fileUploading.getFile(uploadField.getFileId());
fd.setSize(file.length());
fd.setCreateDate(AppBeans.get(TimeSource.class).currentTimestamp());
saveFile();
ds.addItem(fd);
showNotification(getMessage("uploadSuccess"), NotificationType.HUMANIZED);
});
uploadField.addFileUploadErrorListener(e -> showNotification(getMessage("uploadUnsuccess"), NotificationType.HUMANIZED));
}
Aggregations