Search in sources :

Example 1 with FileUploadingAPI

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));
}
Also used : FileUploadingAPI(com.haulmont.cuba.gui.upload.FileUploadingAPI) RemoveAction(com.haulmont.cuba.gui.components.actions.RemoveAction) File(java.io.File) FileDescriptor(com.haulmont.cuba.core.entity.FileDescriptor)

Aggregations

FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)1 RemoveAction (com.haulmont.cuba.gui.components.actions.RemoveAction)1 FileUploadingAPI (com.haulmont.cuba.gui.upload.FileUploadingAPI)1 File (java.io.File)1