Search in sources :

Example 1 with DownloadFormat

use of io.jmix.ui.download.DownloadFormat 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 2 with DownloadFormat

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

the class UiReportRunnerImpl method showResult.

protected void showResult(ReportOutputDocument document, UiReportRunContext context) {
    String templateCode = getTemplateCode(context);
    Map<String, Object> params = context.getParams();
    ReportOutputType outputType = context.getOutputType();
    if (document.getReportOutputType().getId().equals(JmixReportOutputType.chart.getId())) {
        ShowChartScreen showChartScreen = (ShowChartScreen) screens.create("report_ShowChart.screen", OpenMode.DIALOG);
        showChartScreen.setChartJson(new String(document.getContent(), StandardCharsets.UTF_8));
        showChartScreen.setReport((Report) document.getReport());
        showChartScreen.setTemplateCode(templateCode);
        showChartScreen.setReportParameters(params);
        showChartScreen.show();
    } else if (document.getReportOutputType().getId().equals(JmixReportOutputType.pivot.getId())) {
        ShowPivotTableScreen showPivotTableScreen = (ShowPivotTableScreen) screens.create("report_ShowPivotTable.screen", OpenMode.DIALOG);
        showPivotTableScreen.setPivotTableData(document.getContent());
        showPivotTableScreen.setReport((Report) document.getReport());
        showPivotTableScreen.setTemplateCode(templateCode);
        showPivotTableScreen.setParams(params);
        showPivotTableScreen.show();
    } else if (document.getReportOutputType().getId().equals(JmixReportOutputType.table.getId())) {
        ShowReportTableScreen reportTable = (ShowReportTableScreen) screens.create("report_ShowReportTable.screen", OpenMode.DIALOG);
        reportTable.setTableData(document.getContent());
        reportTable.setReport((Report) document.getReport());
        reportTable.setTemplateCode(templateCode);
        reportTable.setReportParameters(params);
        reportTable.show();
    } else {
        byte[] byteArr = document.getContent();
        com.haulmont.yarg.structure.ReportOutputType finalOutputType = (outputType != null) ? outputType.getOutputType() : document.getReportOutputType();
        DownloadFormat exportFormat = DownloadFormat.getByExtension(finalOutputType.getId());
        String outputFileName = context.getOutputNamePattern();
        String documentName = isNotBlank(outputFileName) ? outputFileName : document.getDocumentName();
        downloader.download(byteArr, documentName, exportFormat);
    }
}
Also used : ShowPivotTableScreen(io.jmix.reportsui.screen.report.run.ShowPivotTableScreen) DownloadFormat(io.jmix.ui.download.DownloadFormat) ShowReportTableScreen(io.jmix.reportsui.screen.report.run.ShowReportTableScreen) ShowChartScreen(io.jmix.reportsui.screen.report.run.ShowChartScreen)

Example 3 with DownloadFormat

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

the class WebExportDisplay method show.

@Override
public void show(ExportDataProvider dataProvider, String resourceName, @Nullable ExportFormat format) {
    DownloadFormat downloadFormat = format == null ? null : format.getDownloadFormat();
    delegate.download(dataProvider, resourceName, downloadFormat);
}
Also used : DownloadFormat(io.jmix.ui.download.DownloadFormat)

Example 4 with DownloadFormat

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

the class WebExportDisplay method show.

@Override
public void show(FileDescriptor fileDescriptor, @Nullable ExportFormat format) {
    DownloadFormat downloadFormat = format == null ? null : format.getDownloadFormat();
    delegate.download(cubaFileStorage.toFileRef(fileDescriptor), downloadFormat);
}
Also used : DownloadFormat(io.jmix.ui.download.DownloadFormat)

Aggregations

DownloadFormat (io.jmix.ui.download.DownloadFormat)4 ShowChartScreen (io.jmix.reportsui.screen.report.run.ShowChartScreen)1 ShowPivotTableScreen (io.jmix.reportsui.screen.report.run.ShowPivotTableScreen)1 ShowReportTableScreen (io.jmix.reportsui.screen.report.run.ShowReportTableScreen)1 ByteArrayDataProvider (io.jmix.ui.download.ByteArrayDataProvider)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1