Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.openhris.employee; import com.openhris.commons.OpenHrisUtilities; import com.openhris.employee.containers.EmployeeSummaryDataContainer; import com.openhris.employee.tables.EmployeeSummaryTableProperties; import com.openhris.service.CompanyService; import com.openhris.serviceprovider.CompanyServiceImpl; import com.vaadin.addon.tableexport.ExcelExport; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; import com.vaadin.ui.ComboBox; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Window; import org.apache.poi.hpsf.SummaryInformation; /** * * @author jetdario */ public class EmployeeSummaryUI extends VerticalLayout { CompanyService cs = new CompanyServiceImpl(); OpenHrisUtilities util = new OpenHrisUtilities(); EmployeeSummaryTableProperties summary = new EmployeeSummaryTableProperties(); private int branchId; private int tradeId; private int corporateId; public EmployeeSummaryUI(int branchId) { this.branchId = branchId; setSizeFull(); setSpacing(true); setMargin(new MarginInfo(true, true, false, false)); HorizontalLayout h = new HorizontalLayout(); h.setWidth("100%"); h.setMargin(true); h.setSpacing(true); final ComboBox employeeStatus = new ComboBox("Status: "); employeeStatus.setWidth("150px"); employeeStatus.setNullSelectionAllowed(false); employeeStatus.addItem("employed"); employeeStatus.addItem("resigned"); h.addComponent(employeeStatus); Button generateBtn = new Button("GENERATE EMPLOYEE SUMMARY"); generateBtn.setWidth("250px"); generateBtn.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (employeeStatus.getValue() == null) { getWindow().showNotification("Employee Status!", Window.Notification.TYPE_WARNING_MESSAGE); return; } tradeId = cs.getTradeIdByBranchId(getBranchId()); corporateId = cs.getCorporateIdByTradeId(tradeId); summary.setContainerDataSource( new EmployeeSummaryDataContainer(corporateId, employeeStatus.getValue().toString())); } }); h.addComponent(generateBtn); h.setComponentAlignment(generateBtn, Alignment.BOTTOM_LEFT); Button exportTableToExcel = new Button("EXPORT TO EXCEL"); exportTableToExcel.setWidth("250px"); exportTableToExcel.addListener(new Button.ClickListener() { private static final long serialVersionUID = -73954695086117200L; private ExcelExport excelExport; @Override public void buttonClick(Button.ClickEvent event) { excelExport = new ExcelExport(summary, "EMPLOYEE SUMMARY"); excelExport.excludeCollapsedColumns(); excelExport.setReportTitle(cs.getCorporateById(corporateId).toUpperCase() + " Employee Summary"); excelExport.setExportFileName(cs.getCorporateById(corporateId).replace(",", " ").toUpperCase() + "-Employee-Summary-" + ".xls"); excelExport.export(); } }); h.addComponent(exportTableToExcel); h.setComponentAlignment(exportTableToExcel, Alignment.BOTTOM_LEFT); h.setExpandRatio(exportTableToExcel, 3); addComponent(h); addComponent(summary); setExpandRatio(summary, 2); } public int getBranchId() { return branchId; } public void setBranchId(int branchId) { this.branchId = branchId; } }