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);
}
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);
}
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);
}
}
}
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;
}
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;
}
Aggregations