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.hris.payroll.reports; import com.hris.common.ReportTypeComboBox; import com.hris.payroll.container.PayrollAdvancesContainer; import com.hris.payroll.grids.PayrollAdvancesGridProperties; import com.vaadin.server.FontAwesome; import com.vaadin.shared.ui.MarginInfo; import com.vaadin.ui.Button; import com.vaadin.ui.ComboBox; import com.vaadin.ui.DateField; import com.vaadin.ui.Grid; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Notification; import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Window; import com.vaadin.ui.themes.ValoTheme; import java.util.Date; /** * * @author jetdario */ public class ReportUI extends VerticalLayout { private int branchId; ComboBox reportType = new ReportTypeComboBox(); DateField payrollDate = new DateField(); Button viewReport = new Button("VIEW REPORT"); Grid grid = new PayrollAdvancesGridProperties(); public ReportUI(int branchId) { this.branchId = branchId; setSizeFull(); setMargin(new MarginInfo(true, true, false, true)); setSpacing(true); HorizontalLayout h1 = new HorizontalLayout(); h1.setWidthUndefined(); h1.setSpacing(true); h1.addComponent(reportType); h1.addComponent(payrollDateField()); h1.addComponent(viewReportBtn()); addComponent(h1); addComponent(grid); setExpandRatio(grid, 2); HorizontalLayout h2 = new HorizontalLayout(); h2.setWidthUndefined(); h2.setSpacing(true); } private int getBranchId() { return branchId; } public DateField getPayrollDate() { return payrollDate; } private Button viewReportBtn() { viewReport.setWidth("200px"); viewReport.setIcon(FontAwesome.EXCLAMATION_CIRCLE); viewReport.addStyleName(ValoTheme.BUTTON_PRIMARY); viewReport.addStyleName(ValoTheme.BUTTON_SMALL); viewReport.addClickListener((Button.ClickEvent e) -> { if (getBranchId() == 0) { Notification.show("Select a Branch!!!", Notification.Type.WARNING_MESSAGE); return; } if (getPayrollDate() == null) { Notification.show("Select a Payroll Date!!!", Notification.Type.WARNING_MESSAGE); return; } Window sub = new ReportViewer(reportType.getValue().toString(), getBranchId(), payrollDate.getValue()); if (sub.getParent() == null) { UI.getCurrent().addWindow(sub); } // switch(reportType.getValue().toString()){ // case "Payslip" : { // if(sub.getParent() == null){ // UI.getCurrent().addWindow(sub); // } // break; // } // // case "Advances Summary" : { // // } // // default: { // if(sub.getParent() == null){ // UI.getCurrent().addWindow(sub); // grid.setContainerDataSource( // new PayrollAdvancesContainer( // getBranchId(), // payrollDate.getValue(), // reportType.getValue().toString())); // removeComponent(grid); // addComponent(grid); // setExpandRatio(grid, 2); // } // } // } }); return viewReport; } private DateField payrollDateField() { payrollDate.setWidth("200px"); payrollDate.setValue(new Date()); payrollDate.addStyleName(ValoTheme.COMBOBOX_SMALL); return payrollDate; } }