Search in sources :

Example 1 with AJAXDownload

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());
        }
    };
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AgreementResult(de.tudarmstadt.ukp.clarin.webanno.curation.agreement.AgreementUtils.AgreementResult) AbstractResourceStream(org.apache.wicket.util.resource.AbstractResourceStream) AjaxEventBehavior(org.apache.wicket.ajax.AjaxEventBehavior) ResourceStreamNotFoundException(org.apache.wicket.util.resource.ResourceStreamNotFoundException) IOException(java.io.IOException) ResourceStreamNotFoundException(org.apache.wicket.util.resource.ResourceStreamNotFoundException) AJAXDownload(de.tudarmstadt.ukp.clarin.webanno.support.AJAXDownload)

Aggregations

AgreementResult (de.tudarmstadt.ukp.clarin.webanno.curation.agreement.AgreementUtils.AgreementResult)1 AJAXDownload (de.tudarmstadt.ukp.clarin.webanno.support.AJAXDownload)1 IOException (java.io.IOException)1 AjaxEventBehavior (org.apache.wicket.ajax.AjaxEventBehavior)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 AbstractResourceStream (org.apache.wicket.util.resource.AbstractResourceStream)1 ResourceStreamNotFoundException (org.apache.wicket.util.resource.ResourceStreamNotFoundException)1