Search in sources :

Example 46 with FileDescriptor

use of com.haulmont.cuba.core.entity.FileDescriptor in project cuba by cuba-platform.

the class FileDownloadHelper method initGeneratedColumn.

/**
 * Initializes a column for downloading files in a table displaying {@link FileDescriptor}s.
 *
 * @param table table that displays instances of the {@link FileDescriptor} entity
 */
public static void initGeneratedColumn(final Table table) {
    final ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.NAME);
    final ExportDisplay exportDisplay = AppBeans.get(ExportDisplay.NAME);
    table.addGeneratedColumn("name", new Table.ColumnGenerator<FileDescriptor>() {

        @Override
        public Component generateCell(final FileDescriptor fd) {
            if (fd == null) {
                return componentsFactory.createComponent(Label.NAME);
            }
            if (PersistenceHelper.isNew(fd)) {
                Label label = componentsFactory.createComponent(Label.class);
                label.setValue(fd.getName());
                return label;
            } else {
                Button button = componentsFactory.createComponent(Button.class);
                button.setStyleName("link");
                button.setAction(new AbstractAction("download") {

                    @Override
                    public void actionPerform(Component component) {
                        exportDisplay.show(fd);
                    }

                    @Override
                    public String getCaption() {
                        return fd.getName();
                    }
                });
                return button;
            }
        }
    });
}
Also used : ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) ExportDisplay(com.haulmont.cuba.gui.export.ExportDisplay) FileDescriptor(com.haulmont.cuba.core.entity.FileDescriptor)

Example 47 with FileDescriptor

use of com.haulmont.cuba.core.entity.FileDescriptor in project cuba by cuba-platform.

the class WebFileUploadField method saveFile.

protected void saveFile(FileDescriptor fileDescriptor) {
    switch(mode) {
        case MANUAL:
            internalValueChangedOnUpload = true;
            setValue(fileDescriptor);
            internalValueChangedOnUpload = false;
            break;
        case IMMEDIATE:
            try {
                fileUploading.putFileIntoStorage(fileId, fileDescriptor);
                FileDescriptor committedDescriptor = commitFileDescriptor(fileDescriptor);
                setValue(committedDescriptor);
            } catch (FileStorageException e) {
                log.error("Error has occurred during file saving", e);
            }
            break;
    }
}
Also used : FileStorageException(com.haulmont.cuba.core.global.FileStorageException) FileDescriptor(com.haulmont.cuba.core.entity.FileDescriptor)

Aggregations

FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)47 FileStorageException (com.haulmont.cuba.core.global.FileStorageException)12 UUID (java.util.UUID)9 EntityManager (com.haulmont.cuba.core.EntityManager)5 SecurityContext (com.haulmont.cuba.core.sys.SecurityContext)5 UserSession (com.haulmont.cuba.security.global.UserSession)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 Transaction (com.haulmont.cuba.core.Transaction)3 ExportDisplay (com.haulmont.cuba.gui.export.ExportDisplay)3 FileDataProvider (com.haulmont.cuba.gui.export.FileDataProvider)3 RestAPIException (com.haulmont.restapi.exception.RestAPIException)3 File (java.io.File)3 FileStorageAPI (com.haulmont.cuba.core.app.FileStorageAPI)2 FileStorageService (com.haulmont.cuba.core.app.FileStorageService)2 LoadContext (com.haulmont.cuba.core.global.LoadContext)2 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)2 TaskLifeCycle (com.haulmont.cuba.gui.executors.TaskLifeCycle)2 ByteArrayDataProvider (com.haulmont.cuba.gui.export.ByteArrayDataProvider)2