Search in sources :

Example 1 with ByteArrayDataProvider

use of io.jmix.ui.download.ByteArrayDataProvider in project jmix by jmix-framework.

the class JsonEmailTemplateEdit method viewHtml.

@Subscribe("viewHtml")
public void viewHtml(Button.ClickEvent event) {
    String name = getEditedEntity().getName() != null ? getEditedEntity().getName() : "template";
    String html = getEditedEntity().getHtml() != null ? getEditedEntity().getHtml() : "";
    downloader.download(new ByteArrayDataProvider(html.getBytes(StandardCharsets.UTF_8), uiProperties.getSaveExportedByteArrayDataThresholdBytes(), coreProperties.getTempDir()), name + ".html");
}
Also used : ByteArrayDataProvider(io.jmix.ui.download.ByteArrayDataProvider)

Example 2 with ByteArrayDataProvider

use of io.jmix.ui.download.ByteArrayDataProvider in project jmix by jmix-framework.

the class PivotExcelExporter method export.

protected void export(Downloader downloader) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        wb.write(out);
    } catch (IOException e) {
        throw new RuntimeException("Unable to write document", e);
    }
    if (fileName == null) {
        fileName = DEFAULT_FILE_NAME;
    }
    DownloadFormat downloadFormat = exportFormat == ExportFormat.XLS ? DownloadFormat.XLS : DownloadFormat.XLSX;
    downloader.download(new ByteArrayDataProvider(out.toByteArray(), uiProperties.getSaveExportedByteArrayDataThresholdBytes(), coreProperties.getTempDir()), fileName + "." + downloadFormat.getFileExt(), downloadFormat);
}
Also used : DownloadFormat(io.jmix.ui.download.DownloadFormat) ByteArrayDataProvider(io.jmix.ui.download.ByteArrayDataProvider) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 3 with ByteArrayDataProvider

use of io.jmix.ui.download.ByteArrayDataProvider in project jmix by jmix-framework.

the class MBeanOperationResultScreen method exportToFile.

@Subscribe("exportBtn")
public void exportToFile(Button.ClickEvent clickEvent) {
    if (result != null || exception != null) {
        String exportResult = String.format("JMX Method %s : %s result\n", operation.getMbean().getClassName(), operation.getName());
        if (result != null) {
            exportResult += AttributeHelper.convertToString(result);
        }
        if (exception != null) {
            exportResult += getExceptionMessage(exception);
        }
        byte[] bytes = exportResult.getBytes(StandardCharsets.UTF_8);
        downloader.download(new ByteArrayDataProvider(bytes, uiProperties.getSaveExportedByteArrayDataThresholdBytes(), coreProperties.getTempDir()), String.format("jmx.%s-%s-%s.log", operation.getMbean().getClassName(), operation.getName(), new SimpleDateFormat("HH:mm:ss").format(timeSource.currentTimestamp())));
    } else {
        notifications.create().withCaption(messages.getMessage(getClass(), "operationResult.resultIsEmpty")).withType(Notifications.NotificationType.HUMANIZED).show();
    }
}
Also used : ByteArrayDataProvider(io.jmix.ui.download.ByteArrayDataProvider) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with ByteArrayDataProvider

use of io.jmix.ui.download.ByteArrayDataProvider in project jmix by jmix-framework.

the class ImapMessageEdit method downloadAttachment.

@Subscribe("attachmentsTable.download")
public void downloadAttachment(Action.ActionPerformedEvent event) {
    attachmentsTable.getSelected().forEach(attachment -> {
        byte[] bytes = imapAttachments.loadFile(attachment);
        downloader.download(new ByteArrayDataProvider(bytes, uiProperties.getSaveExportedByteArrayDataThresholdBytes(), coreProperties.getTempDir()), attachment.getName());
    });
}
Also used : ByteArrayDataProvider(io.jmix.ui.download.ByteArrayDataProvider)

Example 5 with ByteArrayDataProvider

use of io.jmix.ui.download.ByteArrayDataProvider in project jmix by jmix-framework.

the class PersistentDashboardEdit method onExportJsonBtnClick.

@Subscribe("exportJsonBtn")
public void onExportJsonBtnClick(Button.ClickEvent event) {
    String jsonModel = converter.dashboardToJson(getDashboardModel());
    if (isNotBlank(jsonModel)) {
        byte[] bytes = jsonModel.getBytes(UTF_8);
        String fileName = isNotBlank(getDashboardModel().getTitle()) ? getDashboardModel().getTitle() : "dashboard";
        downloader.download(new ByteArrayDataProvider(bytes, uiProperties.getSaveExportedByteArrayDataThresholdBytes(), coreProperties.getTempDir()), format("%s.json", fileName));
    }
}
Also used : ByteArrayDataProvider(io.jmix.ui.download.ByteArrayDataProvider)

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