Search in sources :

Example 1 with PollListener

use of com.vaadin.event.UIEvents.PollListener 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 2 with PollListener

use of com.vaadin.event.UIEvents.PollListener in project VaadinUtils by rlsutton1.

the class JasperReportLayout method initScreen.

protected void initScreen(SplitPanel panel) {
    this.setSizeFull();
    splitPanel = panel;
    this.addComponent(splitPanel.getComponent());
    splitPanel.setFirstComponent((AbstractComponent) getOptionsPanel());
    splash = new VerticalLayout();
    splash.setMargin(true);
    Label titleLabel = new Label("<h1>" + reportProperties.getReportTitle() + "</h1>");
    titleLabel.setContentMode(ContentMode.HTML);
    splash.addComponent(titleLabel);
    Label splashLabel = new Label("<font size='4' >Set the desired filters and click a print button to generate a report</font>");
    splashLabel.setContentMode(ContentMode.HTML);
    splitPanel.setSecondComponent(splash);
    // generate the report immediately if there are no visible filters
    if (!builder.hasFilters()) {
        splashLabel = new Label("<font size='4' >Please wait whilst we generate your report</font>");
        splashLabel.setContentMode(ContentMode.HTML);
        // disable the buttons and any filters
        printButton.setEnabled(false);
        exportButton.setEnabled(false);
        showButton.setEnabled(false);
        for (ExpanderComponent componet : components) {
            componet.getComponent().setEnabled(false);
        }
        // what follows is a horrible hack...
        // if we create the progress dialog at the same time as the popup
        // report window the progress dialog will be behind the popup report
        // window.
        // so I've created a refresher, and 1 seconds after the popup report
        // window opens we kick of the report generation which creates the
        // progress dialog then, which allows it to be in front.
        UI.getCurrent().setPollInterval(500);
        UI.getCurrent().addPollListener(new PollListener() {

            private static final long serialVersionUID = 1L;

            @Override
            public void poll(PollEvent event) {
                try {
                    UI.getCurrent().setPollInterval(-1);
                    UI.getCurrent().removePollListener(this);
                    generateReport(reportProperties.getDefaultFormat(), JasperReportLayout.this.builder.getReportParameters());
                } catch (Exception e) {
                    logger.catching(e);
                    Notification.show("Error", e.getMessage(), Type.ERROR_MESSAGE);
                }
            }
        });
    }
    splash.addComponent(splashLabel);
    JavaScript.getCurrent().addFunction("au.com.noojee.reportDrillDown", new JavaScriptFunction() {

        // expected syntax of a call to this javascript hook method
        // 
        // window.parent.au.com.noojee.reportDrillDown(
        // {
        // 'reportFileName':
        // 'CallDetailsPerTeamAgentPerHour_CallDetails.jasper',
        // 'reportTitle': 'Call Details Per Team Agent Per Hour'
        // },
        // {
        // 'ReportParameterStartDate'='$P{StartDate}',
        // 'ReportParameterEndDate'='$P{EndDate}',
        // 'ReportParameterExtension'='$F{loginid}',
        // 'ReportParameterTeamId'='$P{TeamId}',
        // 'ReportParameterHour'='$F{Day}.toString()'
        // }
        // 
        // );
        private static final long serialVersionUID = 1L;

        @Override
        public void call(JsonArray arguments) {
            try {
                JsonObject args = arguments.getObject(0);
                String subReportFileName = args.getString("ReportFileName");
                String subTitle = args.getString("ReportTitle");
                JsonObject params = arguments.getObject(1);
                List<ReportParameter<?>> subFilters = new LinkedList<>();
                boolean insitue = false;
                String[] itr = params.keys();
                for (String key : itr) {
                    if (key.equalsIgnoreCase("ReportParameterInsitue")) {
                        insitue = true;
                    } else {
                        subFilters.add(new ReportParameterConstant<>(key, params.getString(key), key, params.getString(key)));
                    }
                }
                if (!insitue) {
                    new JasperReportPopUp(new ChildJasperReportProperties(reportProperties, subTitle, subReportFileName, subFilters));
                } else {
                    generateReport(OutputFormat.HTML, subFilters);
                }
            } catch (Exception e) {
                logger.error(arguments.toString());
                logger.error(e, e);
            }
        }
    });
}
Also used : ExpanderComponent(au.com.vaadinutils.jasper.filter.ExpanderComponent) Label(com.vaadin.ui.Label) JsonObject(elemental.json.JsonObject) PollListener(com.vaadin.event.UIEvents.PollListener) PollEvent(com.vaadin.event.UIEvents.PollEvent) JsonArray(elemental.json.JsonArray) JavaScriptFunction(com.vaadin.ui.JavaScriptFunction) VerticalLayout(com.vaadin.ui.VerticalLayout) List(java.util.List) LinkedList(java.util.LinkedList) ReportParameterConstant(au.com.vaadinutils.jasper.parameter.ReportParameterConstant)

Example 3 with PollListener

use of com.vaadin.event.UIEvents.PollListener in project VaadinUtils by rlsutton1.

the class JasperReportLayout method getStreamConnectorRefreshListener.

private void getStreamConnectorRefreshListener(final JasperManager.OutputFormat outputFormat) {
    UI.getCurrent().setPollInterval(500);
    UI.getCurrent().addPollListener(new PollListener() {

        private static final long serialVersionUID = -5641305025399715756L;

        @Override
        public void poll(PollEvent event) {
            logger.warn("Checking if report is ready...");
            if (streamReady && !streamConnected) {
                // jasper manager is ready, so get the report stream and set
                // it as the source for the display panel
                streamConnected = true;
                StreamResource resource = new StreamResource(getReportStream(), "report");
                resource.setMIMEType(outputFormat.getMimeType());
                resource.setCacheTime(-1);
                resource.setFilename(exportFileName(outputFormat));
                if (outputFormat == OutputFormat.CSV) {
                    csv.setSource(resource);
                    showCsvSplash();
                } else {
                    getDisplayPanel().setSource(resource);
                }
                UI.getCurrent().removePollListener(this);
            }
        }

        private String exportFileName(final JasperManager.OutputFormat outputFormat) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
            String name = reportProperties.getReportTitle() + "At" + sdf.format(new Date());
            for (ReportParameter<?> param : builder.getReportParameters()) {
                if (param.showFilter()) {
                    name += "-" + param.getLabel("");
                    for (String parameterName : param.getParameterNames()) {
                        name += "-" + param.getDisplayValue(parameterName);
                    }
                }
            }
            if (name.length() > MAX_FILENAME_LENGTH) {
                name = name.substring(0, MAX_FILENAME_LENGTH);
            }
            name = name.replace("/", "-");
            return name + outputFormat.getFileExtension();
        }
    });
}
Also used : StreamResource(com.vaadin.server.StreamResource) ReportParameter(au.com.vaadinutils.jasper.parameter.ReportParameter) OutputFormat(au.com.vaadinutils.jasper.JasperManager.OutputFormat) JasperManager(au.com.vaadinutils.jasper.JasperManager) PollListener(com.vaadin.event.UIEvents.PollListener) SimpleDateFormat(java.text.SimpleDateFormat) PollEvent(com.vaadin.event.UIEvents.PollEvent) Date(java.util.Date)

Aggregations

PollEvent (com.vaadin.event.UIEvents.PollEvent)3 PollListener (com.vaadin.event.UIEvents.PollListener)3 ExpanderComponent (au.com.vaadinutils.jasper.filter.ExpanderComponent)2 JsonObject (elemental.json.JsonObject)2 JasperManager (au.com.vaadinutils.jasper.JasperManager)1 OutputFormat (au.com.vaadinutils.jasper.JasperManager.OutputFormat)1 QueueEntry (au.com.vaadinutils.jasper.QueueEntry)1 ReportStatus (au.com.vaadinutils.jasper.ReportStatus)1 ReportParameter (au.com.vaadinutils.jasper.parameter.ReportParameter)1 ReportParameterConstant (au.com.vaadinutils.jasper.parameter.ReportParameterConstant)1 Item (com.vaadin.data.Item)1 StreamResource (com.vaadin.server.StreamResource)1 JavaScriptFunction (com.vaadin.ui.JavaScriptFunction)1 Label (com.vaadin.ui.Label)1 Table (com.vaadin.ui.Table)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1 JsonArray (elemental.json.JsonArray)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1