Search in sources :

Example 1 with FileDescriptorResource

use of com.haulmont.cuba.gui.components.FileDescriptorResource in project cuba by cuba-platform.

the class WebImage method createImageResource.

protected Resource createImageResource(final Object resourceObject) {
    if (resourceObject == null) {
        return null;
    }
    if (resourceObject instanceof FileDescriptor) {
        FileDescriptorResource imageResource = createResource(FileDescriptorResource.class);
        imageResource.setFileDescriptor((FileDescriptor) resourceObject);
        return imageResource;
    }
    if (resourceObject instanceof byte[]) {
        StreamResource imageResource = createResource(StreamResource.class);
        Supplier<InputStream> streamSupplier = () -> new ByteArrayDataProvider((byte[]) resourceObject).provide();
        imageResource.setStreamSupplier(streamSupplier);
        return imageResource;
    }
    throw new GuiDevelopmentException("The Image component supports only FileDescriptor and byte[] datasource property value binding", getFrame().getId());
}
Also used : ByteArrayDataProvider(com.haulmont.cuba.gui.export.ByteArrayDataProvider) StreamResource(com.haulmont.cuba.gui.components.StreamResource) InputStream(java.io.InputStream) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) FileDescriptorResource(com.haulmont.cuba.gui.components.FileDescriptorResource) FileDescriptor(com.haulmont.cuba.core.entity.FileDescriptor)

Aggregations

FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)1 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)1 FileDescriptorResource (com.haulmont.cuba.gui.components.FileDescriptorResource)1 StreamResource (com.haulmont.cuba.gui.components.StreamResource)1 ByteArrayDataProvider (com.haulmont.cuba.gui.export.ByteArrayDataProvider)1 InputStream (java.io.InputStream)1