Search in sources :

Example 1 with WorkingDialog

use of au.com.vaadinutils.ui.WorkingDialog in project VaadinUtils by rlsutton1.

the class ShowProgressStep method getContent.

@Override
public Component getContent() {
    VerticalLayout layout = new VerticalLayout();
    layout.setSizeFull();
    progressTable = new PoJoTable<JasperTransmission>(JasperTransmission.class, new String[] { "Description", "RecipientEmailAddress", "Exception" });
    progressTable.setColumnWidth("Description", 80);
    progressTable.setColumnWidth("RecipientEmailAddress", 100);
    progressTable.setColumnExpandRatio("Exception", 1);
    progressTable.setSizeFull();
    progressDescription = new Label();
    layout.addComponent(progressDescription);
    layout.setMargin(true);
    indicator = new ProgressBar(new Float(0.0));
    indicator.setHeight("30px");
    indicator.setIndeterminate(false);
    indicator.setImmediate(true);
    indicator.setSizeFull();
    layout.addComponent(indicator);
    layout.addComponent(this.progressTable);
    layout.setExpandRatio(progressTable, 1);
    Collection<?> recipients = wizardView.getRecipientStep().getRecipientIds();
    ArrayList<JasperTransmission> transmissions = new ArrayList<JasperTransmission>();
    HashSet<String> dedupList = new HashSet<String>();
    JasperProxy proxy;
    try {
        proxy = wizardView.getJasperProxy();
    } catch (JRException e) {
        logger.error(e, e);
        VUNotification.show(e, Type.ERROR_MESSAGE);
        throw new RuntimeException(e);
    }
    for (Object recipientId : recipients) {
        Recipient recipient = this.wizardView.getRecipient((Long) recipientId);
        // Find if the recipient has ane email address
        String email = recipient.getEmailAddress();
        if (email != null && email.length() > 0) {
            queueTransmission(transmissions, dedupList, recipient, email, proxy);
            continue;
        }
        // No email address found
        JasperTransmission transmission = new JasperTransmission(recipient, proxy, new RecipientException("No email address on recipient.", recipient));
        ShowProgressStep.this.progressTable.addRow(transmission);
        rejected.setValue(rejected.intValue() + 1);
    }
    if (transmissions.size() == 0) {
        Notification.show("None of the selected recipients have an Email address", Type.ERROR_MESSAGE);
    } else {
        queued.setValue(transmissions.size());
        progressDescription.setValue(queued.intValue() + " messages queued.");
        SendEmailTask task = new SendEmailTask(this, proxy, transmissions);
        workDialog = new WorkingDialog("Sending Emails", "Sending...", task);
        ProgressBarWorker<JasperTransmission> worker = new ProgressBarWorker<JasperTransmission>(task);
        worker.start();
        UI.getCurrent().addWindow(workDialog);
    }
    return layout;
}
Also used : JRException(net.sf.jasperreports.engine.JRException) Label(com.vaadin.ui.Label) ArrayList(java.util.ArrayList) WorkingDialog(au.com.vaadinutils.ui.WorkingDialog) ProgressBarWorker(au.com.vaadinutils.util.ProgressBarWorker) VerticalLayout(com.vaadin.ui.VerticalLayout) ProgressBar(com.vaadin.ui.ProgressBar) HashSet(java.util.HashSet)

Example 2 with WorkingDialog

use of au.com.vaadinutils.ui.WorkingDialog 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

WorkingDialog (au.com.vaadinutils.ui.WorkingDialog)2 JasperManager (au.com.vaadinutils.jasper.JasperManager)1 JasperProgressListener (au.com.vaadinutils.jasper.JasperProgressListener)1 ExpanderComponent (au.com.vaadinutils.jasper.filter.ExpanderComponent)1 ReportChooser (au.com.vaadinutils.jasper.parameter.ReportChooser)1 CancelListener (au.com.vaadinutils.listener.CancelListener)1 ProgressBarWorker (au.com.vaadinutils.util.ProgressBarWorker)1 Label (com.vaadin.ui.Label)1 ProgressBar (com.vaadin.ui.ProgressBar)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 JRException (net.sf.jasperreports.engine.JRException)1