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.save.common; import com.save.model.Area; import com.save.model.City; import com.save.model.Employee; import com.save.model.Product; import com.save.model.Province; import com.save.service.AreaService; import com.save.service.EmployeeService; import com.save.service.ProductService; import com.save.area.serviceprovider.AreaServiceImpl; import com.save.employee.serviceprovider.EmployeeServiceImpl; import com.save.employee.serviceprovider.ProductServiceImpl; import com.save.model.Client; import com.save.service.ClientService; import com.save.serviceprovider.ClientServiceImpl; import com.save.utilities.CommonUtilities; import com.vaadin.data.Item; import com.vaadin.ui.ComboBox; import java.util.Calendar; import java.util.Date; /** * * @author jetdario */ public class CommonComboBox { public static ComboBox provinces() { ComboBox select = new ComboBox(); select.removeAllItems(); select.setWidth("100%"); select.setCaption("Provinces: "); select.setNullSelectionAllowed(false); select.addContainerProperty("y", String.class, ""); select.setItemCaptionPropertyId("y"); Item i; AreaService as = new AreaServiceImpl(); for (Province p : as.getAllProvinces()) { i = select.addItem(p.getProvinceId()); i.getItemProperty("y").setValue(p.getProvinceName()); } return select; } public static ComboBox areas() { ComboBox select = new ComboBox(); select.removeAllItems(); select.setWidth("100%"); select.setCaption("Areas: "); select.setNullSelectionAllowed(false); select.addContainerProperty("y", String.class, ""); select.setItemCaptionPropertyId("y"); Item i; AreaService as = new AreaServiceImpl(); for (Area a : as.getAllArea()) { i = select.addItem(a.getAreaId()); i.getItemProperty("y").setValue(a.getAreaCode()); } select.addStyleName("small"); select.setImmediate(true); return select; } public static ComboBox citiesByProvinceId(int provinceId, ComboBox select) { select.removeAllItems(); select.setWidth("100%"); select.setCaption("City: "); select.setNullSelectionAllowed(false); select.addContainerProperty("y", String.class, ""); select.setItemCaptionPropertyId("y"); Item i; AreaService as = new AreaServiceImpl(); for (City c : as.getCitiesByProvinceId(provinceId)) { i = select.addItem(c.getCityId()); i.getItemProperty("y").setValue(c.getCityName()); } return select; } public static ComboBox getFormType(String inputPrompt) { ComboBox select = new ComboBox(); select.setCaption("Form Type: "); select.setWidth("100%"); select.setInputPrompt(inputPrompt); select.setNullSelectionAllowed(false); select.addContainerProperty("y", String.class, ""); select.setItemCaptionPropertyId("y"); Item i = select.addItem(1); i.getItemProperty("y").setValue("maintenance"); i = select.addItem(2); i.getItemProperty("y").setValue("reimbursement"); select.addStyleName("small"); select.setImmediate(true); return select; } public static ComboBox employeeWithPosition(String position, String caption) { ComboBox select = new ComboBox(); select.setCaption(caption); select.setWidth("100%"); select.setNullSelectionAllowed(true); select.addContainerProperty("y", String.class, ""); select.setItemCaptionPropertyId("y"); Item i; EmployeeService es = new EmployeeServiceImpl(); for (Employee e : es.getEmployeeByPosition(position)) { i = select.addItem(e.getEmployeeId()); i.getItemProperty("y").setValue(e.getName()); } select.addStyleName("small"); select.setImmediate(true); return select; } public static ComboBox productItems() { ComboBox select = new ComboBox(); select.setCaption("Product Item: "); select.setWidth("100%"); select.setNullSelectionAllowed(false); select.addContainerProperty("y", String.class, ""); select.setItemCaptionPropertyId("y"); Item i; ProductService ps = new ProductServiceImpl(); for (Product p : ps.getAllProducts()) { i = select.addItem(p.getProductId()); i.getItemProperty("y").setValue(p.getProductItem()); } select.addStyleName("small"); select.setImmediate(true); return select; } public static ComboBox clientType() { ComboBox select = new ComboBox(); select.setCaption("Client Type: "); select.setWidth("100%"); select.setNullSelectionAllowed(false); for (String s : ConstantData.CLIENT_TYPE) { select.addItem(s); } select.addStyleName("small"); select.setImmediate(true); return select; } public static ComboBox getAllClients() { ComboBox select = new ComboBox(); select.setCaption("Clients: "); select.setWidth("100%"); select.setNullSelectionAllowed(false); select.addContainerProperty("y", String.class, ""); select.setItemCaptionPropertyId("y"); Item i; ClientService cs = new ClientServiceImpl(); for (Client c : cs.getAllClients()) { i = select.addItem(c.getClientId()); i.getItemProperty("y").setValue(c.getClientName()); } select.addStyleName("small"); select.setImmediate(true); return select; } public static ComboBox getAllEmpployees(String caption) { ComboBox select = new ComboBox(); select.setCaption(caption); select.setWidth("100%"); select.setNullSelectionAllowed(false); select.addContainerProperty("y", String.class, ""); select.setItemCaptionPropertyId("y"); Item i; EmployeeService es = new EmployeeServiceImpl(); for (Employee e : es.getAllEmployees()) { i = select.addItem(e.getEmployeeId()); i.getItemProperty("y").setValue(e.getName()); } select.addStyleName("small"); select.setImmediate(true); return select; } public static ComboBox employmentStatus(String caption) { ComboBox select = new ComboBox(); select.setCaption(caption); select.setInputPrompt("Select a Position.."); select.setWidth("100%"); select.setNullSelectionAllowed(false); select.setRequired(true); select.setRequiredError("Required Status"); for (String s : ConstantData.EMPLOYMENT_STATUS) { select.addItem(s); } select.addStyleName("small"); select.setImmediate(true); return select; } public static ComboBox yearList() { ComboBox select = new ComboBox(); select.setWidth("100%"); select.setNullSelectionAllowed(false); Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); for (int i = 2012; i < (cal.get(Calendar.YEAR) + 1); i++) { select.addItem(String.valueOf(i).replace(",", "")); } select.addStyleName("small"); select.setImmediate(true); return select; } }