Search in sources :

Example 1 with StreamSource

use of com.vaadin.server.StreamResource.StreamSource in project catma by forTEXT.

the class MarkupCollectionExportOptionsDialog method initComponents.

private void initComponents(final Project repository, final SourceDocument sd, final AnnotationCollectionReference umcRef) {
    setModal(true);
    VerticalLayout content = new VerticalLayout();
    setContent(content);
    content.setMargin(true);
    content.setSpacing(true);
    // $NON-NLS-1$
    Button btExport = new Button(Messages.getString("MarkupCollectionExportOptionsDialog.exportAnnotations"));
    content.addComponent(btExport);
    StreamResource resultStreamResource = new StreamResource(new StreamSource() {

        @Override
        public InputStream getStream() {
            return createExportResultStream(repository, sd, umcRef, false);
        }
    }, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    umcRef.toString().replaceAll("\\s", "_") + ".xml");
    resultStreamResource.setCacheTime(0);
    new FileDownloader(resultStreamResource).extend(btExport);
    // $NON-NLS-1$
    Button btExportWithText = new Button(Messages.getString("MarkupCollectionExportOptionsDialog.exportAnnoWithText"));
    content.addComponent(btExportWithText);
    StreamResource resultWithTextStreamResource = new StreamResource(new StreamSource() {

        @Override
        public InputStream getStream() {
            return createExportResultStream(repository, sd, umcRef, true);
        }
    }, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    umcRef.toString().replaceAll("\\s", "_") + ".xml");
    resultWithTextStreamResource.setCacheTime(0);
    new FileDownloader(resultWithTextStreamResource).extend(btExportWithText);
}
Also used : StreamResource(com.vaadin.server.StreamResource) Button(com.vaadin.ui.Button) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StreamSource(com.vaadin.server.StreamResource.StreamSource) VerticalLayout(com.vaadin.ui.VerticalLayout) FileDownloader(com.vaadin.server.FileDownloader)

Example 2 with StreamSource

use of com.vaadin.server.StreamResource.StreamSource in project catma by forTEXT.

the class SourceDocumentExportOptionsDialog method initComponents.

private void initComponents(final Project repository, final SourceDocument sd) {
    setModal(true);
    VerticalLayout content = new VerticalLayout();
    setContent(content);
    content.setMargin(true);
    content.setSpacing(true);
    // $NON-NLS-1$
    Button btExport = new Button(Messages.getString("SourceDocumentExportOptionsDialog.exportDocument"));
    content.addComponent(btExport);
    StreamResource resultStreamResource = new StreamResource(new StreamSource() {

        @Override
        public InputStream getStream() {
            return createExportResultStream(repository, sd);
        }
    }, getFilename(sd));
    resultStreamResource.setCacheTime(0);
    new FileDownloader(resultStreamResource).extend(btExport);
    // $NON-NLS-1$
    Button btExportPlain = new Button(Messages.getString("SourceDocumentExportOptionsDialog.exportDocAsPlainText"));
    content.addComponent(btExportPlain);
    StreamResource resultUTF8StreamResource = new StreamResource(new StreamSource() {

        @Override
        public InputStream getStream() {
            return createUTF8ExportResultStream(sd);
        }
    }, getFilenameUTF8(sd));
    resultUTF8StreamResource.setCacheTime(0);
    new FileDownloader(resultUTF8StreamResource).extend(btExportPlain);
}
Also used : StreamResource(com.vaadin.server.StreamResource) Button(com.vaadin.ui.Button) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StreamSource(com.vaadin.server.StreamResource.StreamSource) VerticalLayout(com.vaadin.ui.VerticalLayout) FileDownloader(com.vaadin.server.FileDownloader)

Example 3 with StreamSource

use of com.vaadin.server.StreamResource.StreamSource in project esup-ecandidat by EsupPortail.

the class CommissionParametreView method miseAJourContainer.

/**
 * Met a jour le container
 *
 * @param ctrCand
 */
private void miseAJourContainer(final Commission commission) {
    containerReadOnly.removeAllItems();
    containerGeneral.removeAllItems();
    containerLettre.removeAllItems();
    labelSignataire.setValue("");
    if (commission != null) {
        containerReadOnly.addAll(commissionController.getListPresentationReadonly(commission));
        containerGeneral.addAll(commissionController.getListPresentationWritable(commission));
        containerLettre.addAll(commissionController.getListPresentationLettre(commission));
        labelSignataire.setValue(commission.getSignataireComm());
        Fichier file = commission.getFichier();
        if (file != null) {
            StreamResource imageResource = new StreamResource(new StreamSource() {

                @Override
                public InputStream getStream() {
                    InputStream is = fileController.getInputStreamFromFichier(file);
                    if (is != null) {
                        return is;
                    }
                    return null;
                }
            }, file.getNomFichier());
            imgSignataire.setSource(imageResource);
            btnAddImage.setVisible(false);
            btnDeleteImage.setVisible(true);
        } else {
            imgSignataire.setSource(null);
            btnAddImage.setVisible(true);
            btnDeleteImage.setVisible(false);
        }
    }
}
Also used : StreamResource(com.vaadin.server.StreamResource) InputStream(java.io.InputStream) StreamSource(com.vaadin.server.StreamResource.StreamSource) Fichier(fr.univlorraine.ecandidat.entities.ecandidat.Fichier)

Example 4 with StreamSource

use of com.vaadin.server.StreamResource.StreamSource in project VaadinUtils by rlsutton1.

the class GridContainerCSVExport method createDownloadButton.

private Button createDownloadButton(final String fileName, final Window window) {
    final Button downloadButton = new Button("Download CSV Data");
    downloadButton.setDisableOnClick(true);
    @SuppressWarnings("serial") StreamSource source = new StreamSource() {

        @Override
        public InputStream getStream() {
            try {
                ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
                BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(arrayOutputStream));
                export(grid, bufferedWriter, headingsSet);
                return new ByteArrayInputStream(arrayOutputStream.toByteArray());
            } catch (Throwable e) {
                logger.error(e, e);
                Notification.show(e.getMessage());
            } finally {
                Runnable runner = new Runnable() {

                    @Override
                    public void run() {
                        try {
                            Thread.sleep(500);
                            UI.getCurrent().access(new Runnable() {

                                @Override
                                public void run() {
                                    window.close();
                                }
                            });
                        } catch (InterruptedException e) {
                            logger.error(e, e);
                        }
                    }
                };
                new Thread(runner, "Dialog closer").start();
            }
            return null;
        }
    };
    StreamResource resource = new StreamResource(source, fileName + AttachmentType.CSV.getFileExtension());
    resource.setMIMEType(AttachmentType.CSV.getMIMETypeString());
    FileDownloader fileDownloader = new FileDownloader(resource);
    fileDownloader.setOverrideContentType(false);
    fileDownloader.extend(downloadButton);
    return downloadButton;
}
Also used : StreamSource(com.vaadin.server.StreamResource.StreamSource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedWriter(java.io.BufferedWriter) StreamResource(com.vaadin.server.StreamResource) Button(com.vaadin.ui.Button) ByteArrayInputStream(java.io.ByteArrayInputStream) OutputStreamWriter(java.io.OutputStreamWriter) FileDownloader(com.vaadin.server.FileDownloader)

Example 5 with StreamSource

use of com.vaadin.server.StreamResource.StreamSource in project VaadinUtils by rlsutton1.

the class ContainerCSVExport method createDownloadButton.

private Button createDownloadButton(final String fileName, final Window window) {
    final Button downloadButton = new Button("Download CSV Data");
    downloadButton.setDisableOnClick(true);
    @SuppressWarnings("serial") StreamSource source = new StreamSource() {

        @Override
        public InputStream getStream() {
            try {
                ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
                BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(arrayOutputStream));
                export(table, bufferedWriter, headingsSet);
                return new ByteArrayInputStream(arrayOutputStream.toByteArray());
            } catch (Throwable e) {
                logger.error(e, e);
                Notification.show(e.getMessage());
            } finally {
                Runnable runner = new Runnable() {

                    @Override
                    public void run() {
                        try {
                            Thread.sleep(500);
                            UI.getCurrent().access(new Runnable() {

                                @Override
                                public void run() {
                                    window.close();
                                }
                            });
                        } catch (InterruptedException e) {
                            logger.error(e, e);
                        }
                    }
                };
                new Thread(runner, "Dialog closer").start();
            }
            return null;
        }
    };
    StreamResource resource = new StreamResource(source, fileName + AttachmentType.CSV.getFileExtension());
    resource.setMIMEType(AttachmentType.CSV.getMIMETypeString());
    FileDownloader fileDownloader = new FileDownloader(resource);
    fileDownloader.setOverrideContentType(false);
    fileDownloader.extend(downloadButton);
    return downloadButton;
}
Also used : StreamSource(com.vaadin.server.StreamResource.StreamSource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedWriter(java.io.BufferedWriter) StreamResource(com.vaadin.server.StreamResource) Button(com.vaadin.ui.Button) ByteArrayInputStream(java.io.ByteArrayInputStream) OutputStreamWriter(java.io.OutputStreamWriter) FileDownloader(com.vaadin.server.FileDownloader)

Aggregations

StreamResource (com.vaadin.server.StreamResource)6 StreamSource (com.vaadin.server.StreamResource.StreamSource)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 FileDownloader (com.vaadin.server.FileDownloader)4 Button (com.vaadin.ui.Button)4 InputStream (java.io.InputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 VerticalLayout (com.vaadin.ui.VerticalLayout)2 BufferedWriter (java.io.BufferedWriter)2 FileInputStream (java.io.FileInputStream)2 CSVWriter (com.opencsv.CSVWriter)1 Notification (com.vaadin.ui.Notification)1 AgeGroup (de.symeda.sormas.api.AgeGroup)1 Fichier (fr.univlorraine.ecandidat.entities.ecandidat.Fichier)1 BufferedInputStream (java.io.BufferedInputStream)1 FilterInputStream (java.io.FilterInputStream)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 ArrayList (java.util.ArrayList)1