List of usage examples for com.vaadin.server StreamResource StreamResource
public StreamResource(StreamSource streamSource, String filename)
From source file:com.esofthead.mycollab.module.project.view.TimeTrackingSummaryViewImpl.java
License:Open Source License
private StreamResource constructStreamResource(final ReportExportType exportType) { LazyStreamSource streamSource = new LazyStreamSource() { private static final long serialVersionUID = 1L; @Override//from w w w . j a va 2 s. c o m protected StreamSource buildStreamSource() { return new SimpleGridExportItemsStreamResource.AllItems<>("Time Tracking Report", new RpParameterBuilder(getVisibleFields()), exportType, itemTimeLoggingService, searchCriteria, SimpleItemTimeLogging.class); } }; return new StreamResource(streamSource, ExportItemsStreamResource.getDefaultExportFileName(exportType)); }
From source file:com.esofthead.mycollab.reporting.PrintButton.java
License:Open Source License
public PrintButton() { setIcon(FontAwesome.PRINT);//from w w w .j ava2 s .c om formReportStreamSource = new FormReportStreamSource(new FormReportTemplateExecutor("")); printWindowOpener = new BrowserWindowOpener( new StreamResource(formReportStreamSource, UUID.randomUUID().toString() + ".pdf")); printWindowOpener.extend(this); }
From source file:com.esofthead.mycollab.ui.chart.JFreeChartWrapper.java
License:Open Source License
@Override public Resource getSource() { if (res == null) { StreamSource streamSource = new StreamResource.StreamSource() { private ByteArrayInputStream bytestream = null; ByteArrayInputStream getByteStream() { if (chart != null && bytestream == null) { int width = getGraphWidth(); int height = getGraphHeight(); if (mode == RenderingMode.SVG) { // Create an instance of the SVG Generator SVGGraphics2D svgGenerator = new SVGGraphics2D(width, height); // draw the chart in the SVG generator chart.draw(svgGenerator, new Rectangle(width, height)); // create an xml string in svg format from the drawing String drawingSVG = svgGenerator.getSVGElement(); return new ByteArrayInputStream(drawingSVG.getBytes(StandardCharsets.UTF_8)); } else { // Draw png to bytestream try { byte[] bytes = ChartUtilities.encodeAsPNG(chart.createBufferedImage(width, height)); bytestream = new ByteArrayInputStream(bytes); } catch (Exception e) { log.error("Error while generating PNG chart", e); }// w w w. j av a 2 s . c o m } } else { bytestream.reset(); } return bytestream; } @Override public InputStream getStream() { return getByteStream(); } }; res = new StreamResource(streamSource, String.format("graph%d", System.currentTimeMillis())) { @Override public int getBufferSize() { if (getStreamSource().getStream() != null) { try { return getStreamSource().getStream().available(); } catch (IOException e) { log.warn("Error while get stream info", e); return 0; } } else { return 0; } } @Override public long getCacheTime() { return 0; } @Override public String getFilename() { if (mode == RenderingMode.PNG) { return super.getFilename() + ".png"; } else { return super.getFilename() + (gzipEnabled ? ".svgz" : ".svg"); } } @Override public DownloadStream getStream() { DownloadStream downloadStream = new DownloadStream(getStreamSource().getStream(), getMIMEType(), getFilename()); if (gzipEnabled && mode == RenderingMode.SVG) { downloadStream.setParameter("Content-Encoding", "gzip"); } return downloadStream; } @Override public String getMIMEType() { if (mode == RenderingMode.PNG) { return "image/png"; } else { return "image/svg+xml"; } } }; } return res; }
From source file:com.esofthead.mycollab.vaadin.desktop.ui.DefaultMassEditActionHandler.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/* w w w . ja va 2s. co m*/ public StreamResource buildStreamResource(String id) { StreamResource res = null; if (MassItemActionHandler.EXPORT_CSV_ACTION.equals(id)) { AbstractPagedBeanTable pagedBeanTable = ((ListView) presenter.getView()).getPagedBeanTable(); if (presenter.isSelectAll) { res = new StreamResource( new SimpleGridExportItemsStreamResource.AllItems("", new RpParameterBuilder(pagedBeanTable.getDisplayColumns()), ReportExportType.CSV, presenter.getSearchService(), presenter.searchCriteria, getReportModelClassType()), "export.csv"); } else { res = new StreamResource(new SimpleGridExportItemsStreamResource.ListData("", new RpParameterBuilder(pagedBeanTable.getDisplayColumns()), ReportExportType.CSV, presenter.getSelectedItems(), getReportModelClassType()), "export.csv"); } } else if (MassItemActionHandler.EXPORT_PDF_ACTION.equals(id)) { AbstractPagedBeanTable pagedBeanTable = ((ListView) presenter.getView()).getPagedBeanTable(); if (presenter.isSelectAll) { res = new StreamResource( new SimpleGridExportItemsStreamResource.AllItems(getReportTitle(), new RpParameterBuilder(pagedBeanTable.getDisplayColumns()), ReportExportType.PDF, presenter.getSearchService(), presenter.searchCriteria, getReportModelClassType()), "export.pdf"); } else { res = new StreamResource(new SimpleGridExportItemsStreamResource.ListData(getReportTitle(), new RpParameterBuilder(pagedBeanTable.getDisplayColumns()), ReportExportType.PDF, presenter.getSelectedItems(), getReportModelClassType()), "export.pdf"); } } else if (MassItemActionHandler.EXPORT_EXCEL_ACTION.equals(id)) { AbstractPagedBeanTable pagedBeanTable = ((ListView) presenter.getView()).getPagedBeanTable(); if (presenter.isSelectAll) { res = new StreamResource( new SimpleGridExportItemsStreamResource.AllItems(getReportTitle(), new RpParameterBuilder(pagedBeanTable.getDisplayColumns()), ReportExportType.EXCEL, presenter.getSearchService(), presenter.searchCriteria, getReportModelClassType()), "export.xlsx"); } else { res = new StreamResource(new SimpleGridExportItemsStreamResource.ListData(getReportTitle(), new RpParameterBuilder(pagedBeanTable.getDisplayColumns()), ReportExportType.EXCEL, presenter.getSelectedItems(), getReportModelClassType()), "export.xlsx"); } } return res; }
From source file:com.esofthead.mycollab.vaadin.resources.OnDemandFileDownloader.java
License:Open Source License
public OnDemandFileDownloader(LazyStreamSource lazyStreamSource) { super(new StreamResource(lazyStreamSource, "")); this.lazyStreamSource = lazyStreamSource; }
From source file:com.esofthead.mycollab.vaadin.resources.StreamDownloadResourceUtil.java
License:Open Source License
public static StreamResource getStreamResourceSupportExtDrive(List<Resource> lstRes) { String filename = getDownloadFileName(lstRes); StreamSource streamSource = getStreamSourceSupportExtDrive(lstRes); return new StreamResource(streamSource, filename); }
From source file:com.esofthead.mycollab.vaadin.ui.DefaultMassItemActionHandlersContainer.java
License:Open Source License
public void addDownloadActionItem(final String id, Resource resource, String groupId, String downloadFileName, String description) {//from ww w . j av a2 s . c o m ButtonGroup group = groupMap.get(groupId); if (group == null) { group = new ButtonGroup(); groupMap.put(groupId, group); this.addComponent(group); } Button optionBtn = new Button(""); FileDownloader fileDownler = new FileDownloader( new StreamResource(new LazyStreamSource(id), downloadFileName)); fileDownler.extend(optionBtn); optionBtn.setIcon(resource); optionBtn.addStyleName(UIConstants.THEME_BLUE_LINK); optionBtn.addStyleName("small-padding"); optionBtn.setDescription(description); group.addButton(optionBtn); }
From source file:com.esofthead.mycollab.vaadin.web.ui.DefaultMassEditActionHandler.java
License:Open Source License
@Override public StreamResource buildStreamResource(ReportExportType exportType) { IPagedBeanTable pagedBeanTable = ((IListView) presenter.getView()).getPagedBeanTable(); final Map<String, Object> parameters = new HashMap<>(); parameters.put("siteUrl", AppContext.getSiteUrl()); parameters.put(SimpleReportTemplateExecutor.CRITERIA, presenter.searchCriteria); ReportTemplateExecutor reportTemplateExecutor; if (presenter.isSelectAll) { reportTemplateExecutor = new SimpleReportTemplateExecutor.AllItems(getReportTitle(), new RpFieldsBuilder(pagedBeanTable.getDisplayColumns()), exportType, getReportModelClassType(), presenter.getSearchService()); } else {//from ww w . jav a 2s .c om reportTemplateExecutor = new SimpleReportTemplateExecutor.ListData(getReportTitle(), new RpFieldsBuilder(pagedBeanTable.getDisplayColumns()), exportType, presenter.getSelectedItems(), getReportModelClassType()); } return new StreamResource(new ReportStreamSource(reportTemplateExecutor) { @Override protected void initReportParameters(Map<String, Object> parameters) { } }, exportType.getDefaultFileName()); }
From source file:com.etest.pdfgenerator.TQViewer.java
public TQViewer(int tqCoverageId) { this.tqCoverageId = tqCoverageId; // setSizeFull(); setWidth("900px"); setHeight("600px"); center();/* w w w . j a va 2s. com*/ StreamResource resource = new StreamResource(new TQCoveragePDF(getTQCoverageId()), "TQ.pdf"); resource.setMIMEType("application/pdf"); VerticalLayout v = new VerticalLayout(); v.setSizeFull(); Embedded e = new Embedded(); e.setSource(resource); e.setSizeFull(); e.setType(Embedded.TYPE_BROWSER); v.addComponent(e); setContent(v); }
From source file:com.etest.pdfviewer.ItemAnalysisOfSubjectReportViewer.java
public ItemAnalysisOfSubjectReportViewer(int tqCoverageId) { this.tqCoverageId = tqCoverageId; setWidth("900px"); setHeight("600px"); center();// w w w. jav a2 s . c o m StreamResource resource = new StreamResource(new ItemAnalysisOfSubjectReportPDF(getTQCoverageId()), "ItemAnalysis.pdf"); resource.setMIMEType("application/pdf"); VerticalLayout v = new VerticalLayout(); v.setSizeFull(); Embedded e = new Embedded(); e.setSource(resource); e.setSizeFull(); e.setType(Embedded.TYPE_BROWSER); v.addComponent(e); setContent(v); }