Search in sources :

Example 1 with ExpanderComponent

use of au.com.vaadinutils.jasper.filter.ExpanderComponent 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 ExpanderComponent

use of au.com.vaadinutils.jasper.filter.ExpanderComponent 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)

Example 3 with ExpanderComponent

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

the class JasperReportLayout method getProgressDialogRefreshListener.

private void getProgressDialogRefreshListener(final WorkingDialog dialog) {
    final Table reportQueue = new Table();
    reportQueue.addContainerProperty("Time", String.class, "");
    reportQueue.addContainerProperty("Report Name", String.class, "");
    reportQueue.addContainerProperty("User", String.class, "");
    reportQueue.addContainerProperty("Status", String.class, "");
    reportQueue.setSizeFull();
    reportQueue.setHeight("150");
    reportQueue.setWidth("100%");
    reportQueue.setColumnWidth("Time", 50);
    reportQueue.setColumnWidth("Report Name", 150);
    reportQueue.setColumnWidth("User", 100);
    // reportQueue.setColumnWidth("Status", 100);
    UI.getCurrent().setPollInterval(500);
    UI.getCurrent().addPollListener(new PollListener() {

        int refreshDivider = 0;

        boolean tableAdded = false;

        private static final long serialVersionUID = -5641305025399715756L;

        @SuppressWarnings("unchecked")
        @Override
        public void poll(PollEvent event) {
            if (manager == null) {
                return;
            }
            ReportStatus status = manager.getStatus();
            dialog.progress(0, 0, status.getStatus());
            if (refreshDivider % 4 == 0) {
                if (status.getEntries().size() > 0) {
                    reportQueue.removeAllItems();
                    for (QueueEntry entry : status.getEntries()) {
                        Object id = reportQueue.addItem();
                        Item item = reportQueue.getItem(id);
                        item.getItemProperty("Time").setValue(entry.getTime());
                        item.getItemProperty("Report Name").setValue(entry.getReportName());
                        item.getItemProperty("User").setValue(entry.getUser());
                        item.getItemProperty("Status").setValue(entry.getStatus());
                    }
                    if (!tableAdded) {
                        dialog.addUserComponent(reportQueue);
                        tableAdded = true;
                    }
                    dialog.setWidth("600");
                    dialog.setHeight("350");
                    dialog.center();
                } else {
                    dialog.removeUserComponent(reportQueue);
                    dialog.setWidth("300");
                    dialog.setHeight("150");
                    dialog.center();
                }
            }
            if (cancelled) {
                printButton.setEnabled(true);
                exportButton.setEnabled(true);
                showButton.setEnabled(true);
                for (ExpanderComponent componet : components) {
                    componet.getComponent().setEnabled(true);
                }
                UI.getCurrent().removePollListener(this);
                UI.getCurrent().setPollInterval(-1);
                dialog.close();
            }
            refreshDivider++;
        }
    });
}
Also used : Table(com.vaadin.ui.Table) ExpanderComponent(au.com.vaadinutils.jasper.filter.ExpanderComponent) PollListener(com.vaadin.event.UIEvents.PollListener) QueueEntry(au.com.vaadinutils.jasper.QueueEntry) PollEvent(com.vaadin.event.UIEvents.PollEvent) Item(com.vaadin.data.Item) JsonObject(elemental.json.JsonObject) ReportStatus(au.com.vaadinutils.jasper.ReportStatus)

Example 4 with ExpanderComponent

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

the class JasperReportLayout method addButtonListener.

private void addButtonListener(Button button, final OutputFormat format) {
    button.addClickListener(new ClickEventLogged.ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void clicked(ClickEvent event) {
            try {
                createFrequentlyUsed();
                createHistory();
                printButton.setEnabled(false);
                exportButton.setEnabled(false);
                showButton.setEnabled(false);
                for (ExpanderComponent componet : components) {
                    componet.getComponent().setEnabled(false);
                }
                generateReport(format, JasperReportLayout.this.builder.getReportParameters());
            } catch (Exception e) {
                printButton.setEnabled(true);
                exportButton.setEnabled(true);
                showButton.setEnabled(true);
                for (ExpanderComponent componet : components) {
                    componet.getComponent().setEnabled(true);
                }
                Notification.show(e.getMessage(), Type.ERROR_MESSAGE);
                logger.error(e, e);
            } finally {
            }
        }

        private void createHistory() {
            Collection<ReportParameter<?>> params = builder.getReportParameters();
            ReportSave reportSave = new ReportSave();
            reportSave.setReportClass(reportProperties.getReportClass().getName());
            reportSave.setUserDescription("");
            reportSave.setUser(reportProperties.getUsername());
            reportSave.setSaveType(SaveType.HISTORY);
            JpaBaseDao.getEntityManager().persist(reportSave);
            for (ReportParameter<?> param : params) {
                for (String pname : param.getParameterNames()) {
                    if (StringUtils.isNotBlank(param.getLabel(pname))) {
                        ReportSaveParameter reportSaveparam = new ReportSaveParameter();
                        reportSaveparam.setParameterName(param.getLabel(pname));
                        reportSaveparam.setTextualRepresentation(param.getDisplayValue(pname));
                        reportSaveparam.setParameterValue(param.getValue(pname).toString());
                        reportSaveparam.setMetaData(param.getSaveMetaData());
                        reportSaveparam.setMetaDataComment(param.getMetaDataComment());
                        reportSave.addParameter(reportSaveparam);
                        JpaBaseDao.getEntityManager().persist(reportSaveparam);
                    }
                }
            }
            // remove excess history
            JpaDslBuilder<ReportSave> q = new JpaBaseDao<>(ReportSave.class).select();
            List<ReportSave> history = q.where(q.eq(ReportSave_.user, reportProperties.getUsername()).and(q.eq(ReportSave_.saveType, SaveType.HISTORY))).orderBy(ReportSave_.lastUsed, true).getResultList();
            if (history.size() > 50) {
                ReportSave old = history.get(0);
                for (ReportSaveParameter param : old.getParameters()) {
                    EntityManagerProvider.remove(param);
                }
                EntityManagerProvider.remove(old);
            }
        }

        private void createFrequentlyUsed() {
            JpaDslBuilder<ReportSave> q = new JpaBaseDao<>(ReportSave.class).select();
            ReportSave reportSave = q.where(q.eq(ReportSave_.reportClass, reportProperties.getReportClass().getName()).and(q.eq(ReportSave_.user, reportProperties.getUsername()).and(q.eq(ReportSave_.saveType, SaveType.FREQUENTLY_USED)))).getSingleResultOrNull();
            if (reportSave == null) {
                reportSave = new ReportSave();
                reportSave.setReportClass(reportProperties.getReportClass().getName());
                reportSave.setUserDescription("Frequently used");
                reportSave.setUser(reportProperties.getUsername());
                reportSave.setSaveType(SaveType.FREQUENTLY_USED);
                JpaBaseDao.getEntityManager().persist(reportSave);
            }
            reportSave.incrementRunCounter();
        }
    });
}
Also used : JpaDslBuilder(au.com.vaadinutils.dao.JpaDslBuilder) ClickEventLogged(au.com.vaadinutils.listener.ClickEventLogged) ExpanderComponent(au.com.vaadinutils.jasper.filter.ExpanderComponent) ReportParameter(au.com.vaadinutils.jasper.parameter.ReportParameter) JpaBaseDao(au.com.vaadinutils.dao.JpaBaseDao) ClickEvent(com.vaadin.ui.Button.ClickEvent) ParseException(java.text.ParseException) ConversionException(com.vaadin.data.util.converter.Converter.ConversionException) ReadOnlyException(com.vaadin.data.Property.ReadOnlyException) Collection(java.util.Collection) List(java.util.List) LinkedList(java.util.LinkedList) ReportSave(au.com.vaadinutils.jasper.scheduler.entities.ReportSave) ReportSaveParameter(au.com.vaadinutils.jasper.scheduler.entities.ReportSaveParameter)

Example 5 with ExpanderComponent

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

the class JasperReportLayout method getOptionsPanel.

private Component getOptionsPanel() {
    VerticalLayout layout = new VerticalLayout();
    layout.setId("OptionsPanel");
    // layout.setMargin(new MarginInfo(false, false, false, false));
    // layout.setSpacing(true);
    layout.setSizeFull();
    String buttonHeight = "" + BUTTON_WIDTH;
    HorizontalLayout buttonBar = new HorizontalLayout();
    buttonBar.setStyleName("njadmin-grey-colour");
    buttonBar.setSpacing(true);
    // buttonBar.setStyleName(Reindeer.LAYOUT_BLUE);
    buttonBar.setWidth("100%");
    buttonBar.setHeight("" + (BUTTON_WIDTH));
    buttonBar.setMargin(new MarginInfo(false, false, false, false));
    HorizontalLayout buttonContainer = new HorizontalLayout();
    buttonContainer.setSizeFull();
    buttonContainer.setWidth("280");
    showButton = new Button();
    Resource previewButtonIcon = reportProperties.getPreviewButtonIconResource();
    if (previewButtonIcon == null) {
        previewButtonIcon = new ExternalResource("images/seanau/Print preview.png");
    }
    showButton.setIcon(previewButtonIcon);
    showButton.setDescription("Preview");
    showButton.setWidth("" + BUTTON_WIDTH);
    showButton.setHeight(buttonHeight);
    showButton.setDisableOnClick(true);
    showButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    showButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    addButtonListener(showButton, OutputFormat.HTML);
    buttonContainer.addComponent(showButton);
    printButton = new Button();
    Resource pdfButtonIcon = reportProperties.getPdfButtonIconResource();
    if (pdfButtonIcon == null) {
        pdfButtonIcon = new ExternalResource("images/seanau/Print_32.png");
    }
    printButton.setIcon(pdfButtonIcon);
    printButton.setDescription("Print (PDF)");
    printButton.setWidth("" + BUTTON_WIDTH);
    printButton.setHeight(buttonHeight);
    printButton.setDisableOnClick(true);
    printButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    printButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    addButtonListener(printButton, OutputFormat.PDF);
    buttonContainer.addComponent(printButton);
    exportButton = new Button();
    Resource exportButtonIcon = reportProperties.getExportButtonIconResource();
    if (exportButtonIcon == null) {
        exportButtonIcon = new ExternalResource("images/exporttoexcel.png");
    }
    exportButton.setDescription("Export (Excel - CSV)");
    exportButton.setIcon(exportButtonIcon);
    exportButton.setWidth("" + BUTTON_WIDTH);
    exportButton.setDisableOnClick(true);
    exportButton.setHeight(buttonHeight);
    exportButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    exportButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    addButtonListener(exportButton, OutputFormat.CSV);
    buttonContainer.addComponent(exportButton);
    createFavouriteButton(buttonHeight, buttonContainer);
    createEmailButton(buttonHeight, buttonContainer);
    createScheduleButton(buttonHeight, buttonContainer);
    if (reportProperties instanceof JasperReportPopUp) {
        // This is disabled because there are serious problems with
        // transient (JasperReportProperties is not aware of them)
        // parameters in drill
        // downs, these can not currently be save or represented in the
        // ReportEmailSchedule
        emailButton.setEnabled(false);
        scheduleButton.setEnabled(false);
    }
    buttonBar.addComponent(buttonContainer);
    layout.addComponent(buttonBar);
    components = builder.buildLayout(false);
    if (components.size() > 0) {
        VerticalLayout filterPanel = new VerticalLayout();
        filterPanel.setMargin(new MarginInfo(false, false, true, false));
        filterPanel.setSpacing(true);
        filterPanel.setSizeFull();
        Label filterLabel = new Label("<b>Filters</b>");
        filterLabel.setStyleName(Reindeer.LABEL_H2);
        filterLabel.setContentMode(ContentMode.HTML);
        filterPanel.addComponent(filterLabel);
        for (ExpanderComponent componet : components) {
            filterPanel.addComponent(componet.getComponent());
            if (componet.shouldExpand()) {
                filterPanel.setExpandRatio(componet.getComponent(), 1);
            }
        }
        layout.addComponent(filterPanel);
        layout.setExpandRatio(filterPanel, 1.0f);
        try {
            ReportSave reportSave = UI.getCurrent().getSession().getAttribute(ReportSave.class);
            if (reportSave != null) {
                for (ReportParameter<?> rp : builder.getReportParameters()) {
                    for (String paramterName : rp.getParameterNames()) {
                        for (ReportSaveParameter saved : reportSave.getParameters()) {
                            if (saved.getParameterName().equals(rp.getLabel(paramterName))) {
                                try {
                                    if (StringUtils.isNotBlank(saved.getMetaData())) {
                                        rp.applySaveMetaData(saved.getMetaData());
                                    } else {
                                        rp.setValueAsString(saved.getParameterValue(), paramterName);
                                    }
                                } catch (ReadOnlyException | ConversionException | ParseException e) {
                                    ErrorWindow.showErrorWindow(e);
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            logger.error(e, e);
        }
    }
    // hidden frame for downloading csv
    csv = new BrowserFrame();
    csv.setVisible(true);
    csv.setHeight("1");
    csv.setWidth("1");
    csv.setImmediate(true);
    layout.addComponent(csv);
    return layout;
}
Also used : ConversionException(com.vaadin.data.util.converter.Converter.ConversionException) ExpanderComponent(au.com.vaadinutils.jasper.filter.ExpanderComponent) BrowserFrame(com.vaadin.ui.BrowserFrame) ExternalResource(com.vaadin.server.ExternalResource) StreamResource(com.vaadin.server.StreamResource) Resource(com.vaadin.server.Resource) Label(com.vaadin.ui.Label) ExternalResource(com.vaadin.server.ExternalResource) ParseException(java.text.ParseException) ConversionException(com.vaadin.data.util.converter.Converter.ConversionException) ReadOnlyException(com.vaadin.data.Property.ReadOnlyException) HorizontalLayout(com.vaadin.ui.HorizontalLayout) Button(com.vaadin.ui.Button) MarginInfo(com.vaadin.shared.ui.MarginInfo) VerticalLayout(com.vaadin.ui.VerticalLayout) ParseException(java.text.ParseException) ReportSave(au.com.vaadinutils.jasper.scheduler.entities.ReportSave) ReportSaveParameter(au.com.vaadinutils.jasper.scheduler.entities.ReportSaveParameter) ReadOnlyException(com.vaadin.data.Property.ReadOnlyException)

Aggregations

ExpanderComponent (au.com.vaadinutils.jasper.filter.ExpanderComponent)7 ReadOnlyException (com.vaadin.data.Property.ReadOnlyException)3 ConversionException (com.vaadin.data.util.converter.Converter.ConversionException)3 ParseException (java.text.ParseException)3 JasperProgressListener (au.com.vaadinutils.jasper.JasperProgressListener)2 ReportSave (au.com.vaadinutils.jasper.scheduler.entities.ReportSave)2 ReportSaveParameter (au.com.vaadinutils.jasper.scheduler.entities.ReportSaveParameter)2 PollEvent (com.vaadin.event.UIEvents.PollEvent)2 PollListener (com.vaadin.event.UIEvents.PollListener)2 Label (com.vaadin.ui.Label)2 VerticalLayout (com.vaadin.ui.VerticalLayout)2 JsonObject (elemental.json.JsonObject)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 JpaBaseDao (au.com.vaadinutils.dao.JpaBaseDao)1 JpaDslBuilder (au.com.vaadinutils.dao.JpaDslBuilder)1 JasperManager (au.com.vaadinutils.jasper.JasperManager)1 QueueEntry (au.com.vaadinutils.jasper.QueueEntry)1 ReportStatus (au.com.vaadinutils.jasper.ReportStatus)1 ReportChooser (au.com.vaadinutils.jasper.parameter.ReportChooser)1