use of au.com.vaadinutils.jasper.scheduler.entities.ReportSaveParameter 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);
}
use of au.com.vaadinutils.jasper.scheduler.entities.ReportSaveParameter 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();
}
});
}
use of au.com.vaadinutils.jasper.scheduler.entities.ReportSaveParameter 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;
}
Aggregations