use of de.tudarmstadt.ukp.clarin.webanno.support.AJAXDownload in project webanno by webanno.
the class AgreementTable method makeDownloadBehavior.
private Behavior makeDownloadBehavior(final String aKey1, final String aKey2) {
return new AjaxEventBehavior("click") {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget aTarget) {
AJAXDownload download = new AJAXDownload() {
private static final long serialVersionUID = 1L;
@Override
protected IResourceStream getResourceStream() {
return new AbstractResourceStream() {
private static final long serialVersionUID = 1L;
@Override
public InputStream getInputStream() throws ResourceStreamNotFoundException {
try {
AgreementResult result = AgreementTable.this.getModelObject().getStudy(aKey1, aKey2);
switch(settings.getObject().exportFormat) {
case CSV:
return AgreementUtils.generateCsvReport(result);
case DEBUG:
return generateDebugReport(result);
default:
throw new IllegalStateException("Unknown export format [" + settings.getObject().exportFormat + "]");
}
} catch (Exception e) {
// FIXME Is there some better error handling here?
LOG.error("Unable to generate agreement report", e);
throw new ResourceStreamNotFoundException(e);
}
}
@Override
public void close() throws IOException {
// Nothing to do
}
};
}
};
getComponent().add(download);
download.initiate(aTarget, "agreement" + settings.getObject().exportFormat.getExtension());
}
};
}
Aggregations