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.fnc.view.ui.thirteenth; import com.fnc.common.CorporateComboBox; import com.fnc.common.CorporateComboBoxPropertyListener; import com.vaadin.data.Property; import com.vaadin.server.FontAwesome; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; import com.vaadin.ui.ComboBox; import com.vaadin.ui.FormLayout; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; import com.vaadin.ui.ProgressBar; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.themes.ValoTheme; import java.util.Calendar; import java.util.Date; /** * * @author jetdario */ public class ThirteenthMonthUI extends VerticalLayout { ComboBox corporation = new CorporateComboBox(); ComboBox trade = new ComboBox(); ComboBox branch = new ComboBox(); ComboBox year; ProgressBar progress = new ProgressBar(new Float(0.0)); Label status = new Label(); private int branchId; volatile double current; private double dataSize; public ThirteenthMonthUI() { setSizeFull(); setMargin(true); addComponent(buildForms()); HorizontalLayout h = new HorizontalLayout(); h.setWidthUndefined(); h.setSpacing(true); progress.setWidth("150px"); h.addComponent(progress); h.setComponentAlignment(progress, Alignment.MIDDLE_LEFT); status.setValue("0%"); h.addComponent(status); addComponent(h); } FormLayout buildForms() { FormLayout form = new FormLayout(); form.setWidth("50%"); corporation.setCaption("Corporation: "); corporation.addStyleName(ValoTheme.COMBOBOX_SMALL); trade.setCaption("Trade: "); trade.addStyleName(ValoTheme.COMBOBOX_SMALL); branch.setCaption("Branch: "); branch.addStyleName(ValoTheme.COMBOBOX_SMALL); corporation.addValueChangeListener(new CorporateComboBoxPropertyListener(trade, trade.getCaption())); form.addComponent(corporation); trade.addValueChangeListener(new CorporateComboBoxPropertyListener(branch, branch.getCaption())); form.addComponent(trade); branch.addValueChangeListener(branchPropertyChangeListener); form.addComponent(branch); HorizontalLayout h = new HorizontalLayout(); h.setCaption("Year: "); h.setWidth("100%"); h.setSpacing(true); h.addComponent(selectYear()); h.addComponent(button()); form.addComponent(h); return form; } ComboBox.ValueChangeListener branchPropertyChangeListener = (Property.ValueChangeEvent event) -> { if (event.getProperty().getValue() == null) { } else { branchId = (int) event.getProperty().getValue(); } }; int getBranchId() { return branchId; } ComboBox selectYear() { year = new ComboBox(); year.setWidth("100%"); year.setNullSelectionAllowed(false); year.addStyleName(ValoTheme.COMBOBOX_SMALL); Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); int y = cal.get(Calendar.YEAR); for (int i = y; i > 2011; i--) { year.addItem(String.valueOf(i)); } year.setValue(String.valueOf(y)); return year; } Button button() { Button button = new Button("ALPHA LIST"); button.setWidth("100%"); button.setIcon(FontAwesome.SPINNER); button.addStyleName(ValoTheme.BUTTON_PRIMARY); button.addStyleName(ValoTheme.BUTTON_SMALL); button.addClickListener((Button.ClickEvent event) -> { status.setValue(" Loading..."); current = 0.0; // dataSize = es.getEmployeeByBranch(getBranchId()).size(); // populateDataGrid(); }); return button; } }