Search in sources :

Example 1 with Recipient

use of au.com.vaadinutils.editors.Recipient in project VaadinUtils by rlsutton1.

the class JasperReportLayout method createFavouriteButton.

private void createFavouriteButton(String buttonHeight, HorizontalLayout buttonContainer) {
    favouriteButton = new Button();
    Resource favouriteButtonIcon = reportProperties.getFavouriteButtonIconResource();
    if (favouriteButtonIcon == null) {
        favouriteButtonIcon = new ExternalResource("images/favourite.png");
    }
    favouriteButton.setDescription("Favourite");
    favouriteButton.setIcon(favouriteButtonIcon);
    favouriteButton.setWidth("" + BUTTON_WIDTH);
    favouriteButton.setDisableOnClick(true);
    favouriteButton.setHeight(buttonHeight);
    favouriteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    favouriteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    favouriteButton.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            new InputDialog(UI.getCurrent(), "Save Favourite", "Provide a name for the faviourite", new Recipient() {

                @Override
                public boolean onOK(String input) {
                    if (StringUtils.length(input) >= 500) {
                        Notification.show("The name must be less than 500 characters", Type.ERROR_MESSAGE);
                        return false;
                    }
                    Collection<ReportParameter<?>> params = builder.getReportParameters();
                    ReportSave reportSave = new ReportSave();
                    reportSave.setReportClass(reportProperties.getReportClass().getName());
                    reportSave.setUserDescription(input);
                    reportSave.setUser(reportProperties.getUsername());
                    reportSave.setSaveType(SaveType.FAVOURITES);
                    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);
                            }
                        }
                    }
                    JpaBaseDao.getEntityManager().persist(reportSave);
                    return true;
                }

                @Override
                public boolean onCancel() {
                    return true;
                }
            });
        }
    });
    buttonContainer.addComponent(favouriteButton);
}
Also used : InputDialog(au.com.vaadinutils.editors.InputDialog) ReportParameter(au.com.vaadinutils.jasper.parameter.ReportParameter) ClickEvent(com.vaadin.ui.Button.ClickEvent) ExternalResource(com.vaadin.server.ExternalResource) StreamResource(com.vaadin.server.StreamResource) Resource(com.vaadin.server.Resource) Recipient(au.com.vaadinutils.editors.Recipient) ExternalResource(com.vaadin.server.ExternalResource) Button(com.vaadin.ui.Button) ClickListener(com.vaadin.ui.Button.ClickListener) ReportSave(au.com.vaadinutils.jasper.scheduler.entities.ReportSave) ReportSaveParameter(au.com.vaadinutils.jasper.scheduler.entities.ReportSaveParameter)

Aggregations

InputDialog (au.com.vaadinutils.editors.InputDialog)1 Recipient (au.com.vaadinutils.editors.Recipient)1 ReportParameter (au.com.vaadinutils.jasper.parameter.ReportParameter)1 ReportSave (au.com.vaadinutils.jasper.scheduler.entities.ReportSave)1 ReportSaveParameter (au.com.vaadinutils.jasper.scheduler.entities.ReportSaveParameter)1 ExternalResource (com.vaadin.server.ExternalResource)1 Resource (com.vaadin.server.Resource)1 StreamResource (com.vaadin.server.StreamResource)1 Button (com.vaadin.ui.Button)1 ClickEvent (com.vaadin.ui.Button.ClickEvent)1 ClickListener (com.vaadin.ui.Button.ClickListener)1