Search in sources :

Example 1 with JasperProgressListener

use of au.com.vaadinutils.jasper.JasperProgressListener in project VaadinUtils by rlsutton1.

the class JasperReportLayout method getJasperManagerProgressListener.

private JasperProgressListener getJasperManagerProgressListener(final UI ui, final WorkingDialog dialog, final OutputFormat outputFormat) {
    JasperProgressListener listener = new JasperProgressListener() {

        @Override
        public void outputStreamReady() {
            // flag that the stream is ready, and on the next
            // "Refresher call" it will connect to the stream
            streamReady = true;
        }

        @Override
        public void failed(String string) {
            // show the error message
            Notification.show(string, Type.ERROR_MESSAGE);
            reportFinished();
        }

        private void reportFinished() {
            // re-enable fields after report finished.
            printButton.setEnabled(true);
            exportButton.setEnabled(true);
            showButton.setEnabled(true);
            for (ExpanderComponent componet : components) {
                componet.getComponent().setEnabled(true);
            }
            dialog.close();
        }

        @Override
        public void completed() {
            ui.access(new Runnable() {

                @Override
                public void run() {
                    reportFinished();
                    JasperReportLayout.this.readyToPrint(outputFormat);
                }
            });
        }
    };
    return listener;
}
Also used : JasperProgressListener(au.com.vaadinutils.jasper.JasperProgressListener) ExpanderComponent(au.com.vaadinutils.jasper.filter.ExpanderComponent)

Example 2 with JasperProgressListener

use of au.com.vaadinutils.jasper.JasperProgressListener in project VaadinUtils by rlsutton1.

the class JasperReportLayout method generateReport.

private void generateReport(final JasperManager.OutputFormat outputFormat, final Collection<ReportParameter<?>> params) {
    streamConnected = false;
    streamReady = false;
    splitPanel.setSecondComponent(splash);
    manager = null;
    boolean validParams = true;
    // manager for the selected report.
    for (ReportParameter<?> p : params) {
        if (p instanceof ReportChooser) {
            ReportChooser chooser = (ReportChooser) p;
            manager = new JasperManager(chooser.getReportProperties(reportProperties));
            Preconditions.checkNotNull(manager, "chooser returned a NULL JasperManager.");
        } else {
            validParams &= p.validate();
        }
    }
    if (!validParams) {
        Notification.show("Please correct your filters and try again", Type.ERROR_MESSAGE);
        printButton.setEnabled(true);
        exportButton.setEnabled(true);
        showButton.setEnabled(true);
        for (ExpanderComponent componet : components) {
            componet.getComponent().setEnabled(true);
        }
        return;
    }
    if (manager == null) {
        this.manager = new JasperManager(reportProperties);
    }
    CancelListener cancelListener = getProgressDialogCancelListener();
    final WorkingDialog dialog = new WorkingDialog("Generating report, please be patient", "Please wait", cancelListener);
    dialog.setHeight("150");
    UI.getCurrent().addWindow(dialog);
    getProgressDialogRefreshListener(dialog);
    getStreamConnectorRefreshListener(outputFormat);
    JasperProgressListener listener = getJasperManagerProgressListener(UI.getCurrent(), dialog, outputFormat);
    manager.exportAsync(outputFormat, params, listener);
}
Also used : JasperProgressListener(au.com.vaadinutils.jasper.JasperProgressListener) WorkingDialog(au.com.vaadinutils.ui.WorkingDialog) ExpanderComponent(au.com.vaadinutils.jasper.filter.ExpanderComponent) ReportChooser(au.com.vaadinutils.jasper.parameter.ReportChooser) JasperManager(au.com.vaadinutils.jasper.JasperManager) CancelListener(au.com.vaadinutils.listener.CancelListener)

Aggregations

JasperProgressListener (au.com.vaadinutils.jasper.JasperProgressListener)2 ExpanderComponent (au.com.vaadinutils.jasper.filter.ExpanderComponent)2 JasperManager (au.com.vaadinutils.jasper.JasperManager)1 ReportChooser (au.com.vaadinutils.jasper.parameter.ReportChooser)1 CancelListener (au.com.vaadinutils.listener.CancelListener)1 WorkingDialog (au.com.vaadinutils.ui.WorkingDialog)1