use of io.jmix.ui.download.ByteArrayDataProvider in project jmix by jmix-framework.
the class SaveStepFragment method onDownloadTemplateFileClick.
@Subscribe("downloadTemplateFile")
public void onDownloadTemplateFileClick(Button.ClickEvent event) {
ReportData reportData = reportDataDc.getItem();
try {
TemplateFileType templateFileType = reportData.getTemplateFileType();
byte[] newTemplate = reportWizardService.generateTemplate(reportData, templateFileType);
downloader.download(new ByteArrayDataProvider(newTemplate, uiProperties.getSaveExportedByteArrayDataThresholdBytes(), coreProperties.getTempDir()), downloadTemplateFile.getCaption(), DownloadFormat.getByExtension(templateFileType.toString().toLowerCase()));
} catch (TemplateGenerationException e) {
notifications.create(Notifications.NotificationType.WARNING).withCaption(messages.getMessage(getClass(), "templateGenerationException")).show();
}
}
use of io.jmix.ui.download.ByteArrayDataProvider in project jmix by jmix-framework.
the class JsonExporter method exportTable.
@Override
public void exportTable(Downloader downloader, Table<Object> table, ExportMode exportMode) {
Collection<Object> items = getItems(table, exportMode);
Gson gson = createGsonForSerialization();
JsonArray jsonElements = new JsonArray();
for (Object entity : items) {
JsonObject jsonObject = new JsonObject();
for (Table.Column<Object> column : table.getColumns()) {
if (column.getId() instanceof MetaPropertyPath) {
MetaPropertyPath propertyPath = (MetaPropertyPath) column.getId();
Object columnValue = getColumnValue(table, column, entity);
if (columnValue != null) {
jsonObject.add(propertyPath.getMetaProperty().getName(), new JsonPrimitive(formatValue(columnValue, (MetaPropertyPath) column.getId())));
} else {
jsonObject.add(propertyPath.getMetaProperty().getName(), JsonNull.INSTANCE);
}
}
}
jsonElements.add(jsonObject);
}
downloader.download(new ByteArrayDataProvider(gson.toJson(jsonElements).getBytes(), uiProperties.getSaveExportedByteArrayDataThresholdBytes(), coreProperties.getTempDir()), getFileName(table) + ".json", DownloadFormat.JSON);
}
use of io.jmix.ui.download.ByteArrayDataProvider in project jmix by jmix-framework.
the class JsonExporter method exportDataGrid.
@Override
public void exportDataGrid(Downloader downloader, DataGrid<Object> dataGrid, ExportMode exportMode) {
Collection<Object> items = getItems(dataGrid, exportMode);
Gson gson = createGsonForSerialization();
JsonArray jsonElements = new JsonArray();
for (Object entity : items) {
JsonObject jsonObject = new JsonObject();
for (DataGrid.Column<Object> column : dataGrid.getColumns()) {
Object columnValue = getColumnValue(dataGrid, column, entity);
MetaPropertyPath metaPropertyPath = metadata.getClass(entity.getClass()).getPropertyPath(column.getId());
if (columnValue != null) {
jsonObject.add(column.getId(), new JsonPrimitive(formatValue(columnValue, metaPropertyPath)));
} else {
jsonObject.add(column.getId(), JsonNull.INSTANCE);
}
}
jsonElements.add(jsonObject);
}
downloader.download(new ByteArrayDataProvider(gson.toJson(jsonElements).getBytes(), uiProperties.getSaveExportedByteArrayDataThresholdBytes(), coreProperties.getTempDir()), getFileName(dataGrid) + ".json", DownloadFormat.JSON);
}
use of io.jmix.ui.download.ByteArrayDataProvider in project jmix by jmix-framework.
the class SendingMessageBrowser method buildContentTextField.
protected Component buildContentTextField() {
VBoxLayout contentArea = uiComponents.create(VBoxLayout.class);
contentArea.setSpacing(true);
contentArea.setCaption(messages.getMessage(SendingMessage.class, "SendingMessage.contentText"));
contentTextArea = uiComponents.create(TextArea.NAME);
contentTextArea.setWidth("100%");
contentTextArea.setEditable(false);
contentTextArea.setHeight("350px");
contentTextArea.setEditable(false);
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), uiProperties.getSaveExportedByteArrayDataThresholdBytes(), coreProperties.getTempDir());
String type = bodyContentType.getRawValue();
if (StringUtils.containsIgnoreCase(type, DownloadFormat.HTML.getContentType())) {
downloader.download(dataProvider, "email-preview.html", DownloadFormat.HTML);
} else {
downloader.download(dataProvider, "email-preview.txt", DownloadFormat.TEXT);
}
}
}
});
showContentButton.setEnabled(false);
showContentButton.setCaption(messages.getMessage(getClass(), "showContent"));
contentArea.add(contentTextArea);
contentArea.add(showContentButton);
return contentArea;
}
use of io.jmix.ui.download.ByteArrayDataProvider in project jmix by jmix-framework.
the class EmailTemplateSendScreen method onPreviewButtonClick.
@Subscribe("previewButton")
public void onPreviewButtonClick(Button.ClickEvent e) throws TemplateNotFoundException, ReportParameterTypeChangedException {
if (!validateAll()) {
return;
}
EmailInfo emailInfo = getEmailInfo();
downloader.download(new ByteArrayDataProvider(emailInfo.getBody().getBytes(PREVIEW_CHARSET), uiProperties.getSaveExportedByteArrayDataThresholdBytes(), coreProperties.getTempDir()), emailInfo.getSubject() + ".html");
}
Aggregations