Search in sources :

Example 1 with ByteArrayDataProvider

use of com.haulmont.cuba.gui.export.ByteArrayDataProvider 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)

Example 2 with ByteArrayDataProvider

use of com.haulmont.cuba.gui.export.ByteArrayDataProvider in project cuba by cuba-platform.

the class DesktopImage method createImageResource.

protected Resource createImageResource(Object propertyValue) {
    if (propertyValue == null) {
        return null;
    }
    if (propertyValue instanceof FileDescriptor) {
        FileDescriptorResource imageResource = createResource(FileDescriptorResource.class);
        imageResource.setFileDescriptor((FileDescriptor) propertyValue);
        return imageResource;
    }
    if (propertyValue instanceof byte[]) {
        StreamResource imageResource = createResource(StreamResource.class);
        Supplier<InputStream> streamSupplier = () -> new ByteArrayDataProvider((byte[]) propertyValue).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) InputStream(java.io.InputStream) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) FileDescriptor(com.haulmont.cuba.core.entity.FileDescriptor)

Example 3 with ByteArrayDataProvider

use of com.haulmont.cuba.gui.export.ByteArrayDataProvider in project cuba by cuba-platform.

the class SendingMessageBrowser method init.

@Override
public void init(Map<String, Object> params) {
    fg.addCustomField(CONTENT_TEXT, new FieldGroup.CustomFieldGenerator() {

        @Override
        public Component generateField(Datasource datasource, String propertyId) {
            VBoxLayout contentArea = uiComponents.create(VBoxLayout.class);
            contentArea.setSpacing(true);
            contentTextArea = uiComponents.create(TextArea.NAME);
            contentTextArea.setWidth("100%");
            contentTextArea.setEditable(false);
            contentTextArea.setHeight(themeConstants.get("cuba.gui.SendingMessageBrowser.contentTextArea.height"));
            showContentButton = uiComponents.create(Button.class);
            showContentButton.setAction(new AbstractAction("") {

                @Override
                public void actionPerform(Component component) {
                    String textAreaValue = contentTextArea.getValue();
                    if (textAreaValue != null) {
                        ByteArrayDataProvider dataProvider = new ByteArrayDataProvider(textAreaValue.getBytes(StandardCharsets.UTF_8));
                        String type = bodyContentTypeField.getRawValue();
                        if (StringUtils.containsIgnoreCase(type, ExportFormat.HTML.getContentType())) {
                            exportDisplay.show(dataProvider, "email-preview.html", ExportFormat.HTML);
                        } else {
                            exportDisplay.show(dataProvider, "email-preview.txt", ExportFormat.TEXT);
                        }
                    }
                }
            });
            showContentButton.setEnabled(false);
            showContentButton.setCaption(messages.getMessage(getClass(), "sendingMessage.showContent"));
            contentArea.add(contentTextArea);
            contentArea.add(showContentButton);
            return contentArea;
        }
    });
    fg.setEditable(CONTENT_TEXT, false);
    sendingMessageDs.addItemChangeListener(e -> selectedItemChanged(e.getItem()));
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) ByteArrayDataProvider(com.haulmont.cuba.gui.export.ByteArrayDataProvider)

Example 4 with ByteArrayDataProvider

use of com.haulmont.cuba.gui.export.ByteArrayDataProvider in project cuba by cuba-platform.

the class RoleBrowser method export.

protected void export(ExportFormat exportFormat) {
    Collection<Role> selected = rolesTable.getSelected();
    if (selected.isEmpty() && rolesTable.getItems() != null) {
        selected = rolesTable.getItems().getItems();
    }
    View view = viewRepository.getView(Role.class, "role.export");
    if (view == null) {
        throw new DevelopmentException("View 'role.export' for sec$Role was not found");
    }
    try {
        if (exportFormat == ExportFormat.ZIP) {
            byte[] data = entityImportExportService.exportEntitiesToZIP(selected, view);
            exportDisplay.show(new ByteArrayDataProvider(data), "Roles", ExportFormat.ZIP);
        } else if (exportFormat == ExportFormat.JSON) {
            byte[] data = entityImportExportService.exportEntitiesToJSON(selected, view).getBytes(StandardCharsets.UTF_8);
            exportDisplay.show(new ByteArrayDataProvider(data), "Roles", ExportFormat.JSON);
        }
    } catch (Exception e) {
        showNotification(getMessage("exportFailed"), e.getMessage(), NotificationType.ERROR);
        log.error("Roles export failed", e);
    }
}
Also used : ByteArrayDataProvider(com.haulmont.cuba.gui.export.ByteArrayDataProvider) EntityImportView(com.haulmont.cuba.core.app.importexport.EntityImportView) IOException(java.io.IOException)

Example 5 with ByteArrayDataProvider

use of com.haulmont.cuba.gui.export.ByteArrayDataProvider in project cuba by cuba-platform.

the class DomainProvider method run.

@Override
public void run() {
    DomainDescriptionService service = beanLocator.get(DomainDescriptionService.NAME);
    String description = service.getDomainDescription();
    ExportDisplay exportDisplay = beanLocator.getPrototype(ExportDisplay.NAME, true);
    exportDisplay.show(new ByteArrayDataProvider(description.getBytes(StandardCharsets.UTF_8)), "domain-description.html", ExportFormat.HTML);
}
Also used : ByteArrayDataProvider(com.haulmont.cuba.gui.export.ByteArrayDataProvider) ExportDisplay(com.haulmont.cuba.gui.export.ExportDisplay) DomainDescriptionService(com.haulmont.cuba.core.app.DomainDescriptionService)

Aggregations

ByteArrayDataProvider (com.haulmont.cuba.gui.export.ByteArrayDataProvider)8 EntityImportView (com.haulmont.cuba.core.app.importexport.EntityImportView)2 FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)2 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ParamsMap (com.haulmont.bali.util.ParamsMap)1 DomainDescriptionService (com.haulmont.cuba.core.app.DomainDescriptionService)1 FileDescriptorResource (com.haulmont.cuba.gui.components.FileDescriptorResource)1 StreamResource (com.haulmont.cuba.gui.components.StreamResource)1 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)1 Datasource (com.haulmont.cuba.gui.data.Datasource)1 ExportDisplay (com.haulmont.cuba.gui.export.ExportDisplay)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1