use of au.com.vaadinutils.dao.JpaDslBuilder 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.dao.JpaDslBuilder in project VaadinUtils by rlsutton1.
the class BasePortal method createHeader.
private HorizontalLayout createHeader(String title, final DashBoardController dashBoard) {
HorizontalLayout header = new HorizontalLayout();
header.setWidth("100%");
header.setHeight("25");
titleLabel = new Label(title);
titleLabel.setStyleName(ValoTheme.LABEL_COLORED);
header.addComponent(titleLabel);
HorizontalLayout controlLayout = new HorizontalLayout();
Button removeButton = new Button(FontAwesome.CLOSE);
removeButton.setStyleName(ValoTheme.BUTTON_LINK);
removeButton.addClickListener(new ClickListener() {
private static final long serialVersionUID = 1L;
@Override
public void buttonClick(ClickEvent event) {
dashBoard.removeComponent(BasePortal.this);
Tblportal portal = JpaBaseDao.getGenericDao(Tblportal.class).findOneByAttribute(Tblportal_.guid, guid);
if (portal != null) {
portal.getPortalLayout().removePortal(portal);
JpaDslBuilder<Tblportalconfig> q = JpaBaseDao.getGenericDao(Tblportalconfig.class).select();
q.where(q.eq(Tblportalconfig_.portal, portal)).delete();
EntityManagerProvider.remove(portal);
}
}
});
if (canUserConfigurePortal()) {
addCustomHeaderButtons(controlLayout);
controlLayout.addComponent(removeButton);
}
header.addComponent(controlLayout);
header.setComponentAlignment(controlLayout, Alignment.MIDDLE_RIGHT);
return header;
}
Aggregations