Search in sources :

Example 1 with ReportParameterConstant

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

Aggregations

ExpanderComponent (au.com.vaadinutils.jasper.filter.ExpanderComponent)1 ReportParameterConstant (au.com.vaadinutils.jasper.parameter.ReportParameterConstant)1 PollEvent (com.vaadin.event.UIEvents.PollEvent)1 PollListener (com.vaadin.event.UIEvents.PollListener)1 JavaScriptFunction (com.vaadin.ui.JavaScriptFunction)1 Label (com.vaadin.ui.Label)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1 JsonArray (elemental.json.JsonArray)1 JsonObject (elemental.json.JsonObject)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1