public void runReport(Map<String, Object> params, FillListener fillListener) { try { Map<String, Object> reportParams = reportParams(params); AsynchronousFillHandle asyncHandle = AsynchronousFillHandle.createHandle( jasperReportsContext, report, reportParams); if (fillListener != null) { asyncHandle.addFillListener(fillListener); } AsyncJasperPrintAccessor accessor = new AsyncJasperPrintAccessor(asyncHandle); asyncHandle.startFill(); JasperPrint print = accessor.getFinalJasperPrint(); reportComplete(reportParams, print); } catch (JRException | NoSuchAlgorithmException | IOException e) { throw new RuntimeException(e); } }
/** * */ protected void runReport( ReportContext reportContext, JasperReport jasperReport, boolean async ) throws JRException { JasperPrintAccessor accessor; if (async) { AsynchronousFillHandle fillHandle = AsynchronousFillHandle.createHandle( jasperReportsContext, jasperReport, reportContext.getParameterValues() ); AsyncJasperPrintAccessor asyncAccessor = new AsyncJasperPrintAccessor(fillHandle); fillHandle.startFill(); accessor = asyncAccessor; } else { JasperPrint jasperPrint = JasperFillManager.getInstance(jasperReportsContext).fill( jasperReport, reportContext.getParameterValues() ); accessor = new SimpleJasperPrintAccessor(jasperPrint); } reportContext.setParameterValue(WebReportContext.REPORT_CONTEXT_PARAMETER_JASPER_PRINT_ACCESSOR, accessor); }
private void runJob(final PreviewContainer pcontainer) { fillError = null; Job job = new Job(Messages.PreviewEditor_preview_a + ": " + jrContext.getJasperDesign().getName() + Messages.PreviewEditor_preview_b) { //$NON-NLS-1$ @Override protected IStatus run(IProgressMonitor monitor) { ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); JasperDesign jd = null; try { Thread.currentThread().setContextClassLoader(jrContext.getClassLoader()); setParameters(); final IFile file = ((IFileEditorInput) pcontainer.getEditorInput()).getFile(); monitor.beginTask(Messages.PreviewEditor_starting, IProgressMonitor.UNKNOWN); jd = jrContext.getJasperDesign();// ModelUtils.copyJasperDesign(jrContext.getJasperDesign()); JasperReport jasperReport = compileJasperDesign(file, jd, monitor); if (jasperReport != null) { if (!prmInput.checkFieldsFilled()) return Status.CANCEL_STATUS; setupDataAdapter(pcontainer); if (pcontainer.getMode().equals(RunStopAction.MODERUN_JIVE)) { runJive(pcontainer, file, jasperReport); } else { setupVirtualizer(jd); c.startMessage(Messages.ReportControler_msg_fillreports); setupRecordCounters(); JaspersoftStudioPlugin.getExtensionManager().onRun(jrContext, jasperReport, jasperParameters); // We create the fillHandle to run the report based on the type of data adapter.... AsynchronousFillHandle fh = AsynchronousFillHandle.createHandle(jrContext, jasperReport, new HashMap<String, Object>(jasperParameters)); if (fillReport(fh, monitor, pcontainer) == Status.CANCEL_STATUS) { cancelMessage(); return Status.CANCEL_STATUS; } doneMessage(); } } } catch (final Throwable e) { errorMessage(); showRunReport(c, pcontainer, e, jd); } finally { Thread.currentThread().setContextClassLoader(oldLoader); monitor.done(); finishReport(pcontainer); } return Status.OK_STATUS; } }; job.setPriority(Job.LONG); job.schedule(); }