Search in sources :

Example 6 with ByteArrayDataProvider

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();
    }
}
Also used : ByteArrayDataProvider(io.jmix.ui.download.ByteArrayDataProvider) TemplateFileType(io.jmix.reports.entity.wizard.TemplateFileType) ReportData(io.jmix.reports.entity.wizard.ReportData) TemplateGenerationException(io.jmix.reports.exception.TemplateGenerationException)

Example 7 with ByteArrayDataProvider

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);
}
Also used : ByteArrayDataProvider(io.jmix.ui.download.ByteArrayDataProvider) Table(io.jmix.ui.component.Table) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath)

Example 8 with ByteArrayDataProvider

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);
}
Also used : ByteArrayDataProvider(io.jmix.ui.download.ByteArrayDataProvider) DataGrid(io.jmix.ui.component.DataGrid) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath)

Example 9 with ByteArrayDataProvider

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;
}
Also used : ByteArrayDataProvider(io.jmix.ui.download.ByteArrayDataProvider) SendingMessage(io.jmix.email.entity.SendingMessage) AbstractAction(io.jmix.ui.action.AbstractAction)

Example 10 with ByteArrayDataProvider

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");
}
Also used : ByteArrayDataProvider(io.jmix.ui.download.ByteArrayDataProvider) EmailInfo(io.jmix.email.EmailInfo)

Aggregations

ByteArrayDataProvider (io.jmix.ui.download.ByteArrayDataProvider)12 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)4 Table (io.jmix.ui.component.Table)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 Entity (io.jmix.core.Entity)2 Id (io.jmix.core.Id)2 EntityValues (io.jmix.core.entity.EntityValues)2 Datatype (io.jmix.core.metamodel.datatype.Datatype)2 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)2 Range (io.jmix.core.metamodel.model.Range)2 Notifications (io.jmix.ui.Notifications)2 io.jmix.ui.component (io.jmix.ui.component)2 io.jmix.ui.component.data (io.jmix.ui.component.data)2 EntityDataGridItems (io.jmix.ui.component.data.meta.EntityDataGridItems)2 XLS (io.jmix.ui.download.DownloadFormat.XLS)2 XLSX (io.jmix.ui.download.DownloadFormat.XLSX)2 Downloader (io.jmix.ui.download.Downloader)2 InstanceContainer (io.jmix.ui.model.InstanceContainer)2 ExportAction (io.jmix.uiexport.action.ExportAction)2