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());
}
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());
}
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()));
}
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);
}
}
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);
}
Aggregations