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.area; import com.save.model.City; import com.save.service.AreaService; import com.save.area.serviceprovider.AreaServiceImpl; import com.vaadin.shared.ui.MarginInfo; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; import com.vaadin.ui.ComboBox; import com.vaadin.ui.ComponentContainer; import com.vaadin.ui.HorizontalSplitPanel; import com.vaadin.ui.Table; import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Window; /** * * @author jetdario */ public class AreaUI extends HorizontalSplitPanel { AreaService as = new AreaServiceImpl(); HorizontalSplitPanel hsplit = new HorizontalSplitPanel(); ComboBox city = new ComboBox("City/Town: "); ComboBox province = new ComboBox("Province: "); private Table table = new AreaDataPropertiesTable(); Window sub = new Window(); public AreaUI() { setLocked(true); setSplitPosition(70, Unit.PERCENTAGE); setFirstComponent(areaListTable()); setSecondComponent(getHlayoutWithBtn()); } public Table areaListTable() { table.removeAllItems(); int i = 0; for (City cb : as.getAllCityProvinceArea()) { table.addItem(new Object[] { cb.getAreaCode(), cb.getProvinceName(), cb.getCityName() }, i); i++; } // table.addItemClickListener(areaTableListener); return table; } ComponentContainer getHlayoutWithBtn() { VerticalLayout buttonsLayout = new VerticalLayout(); buttonsLayout.setMargin(new MarginInfo(true, false, false, false)); Button addBtn = new AreaButton("ADD LOCATION TO AREA"); buttonsLayout.addComponent(addBtn); addBtn.addClickListener(actionBtnListener); buttonsLayout.setComponentAlignment(addBtn, Alignment.MIDDLE_LEFT); Button createBtn = new AreaButton("CREATE NEW AREA"); buttonsLayout.addComponent(createBtn); createBtn.addClickListener(actionBtnListener); buttonsLayout.setComponentAlignment(createBtn, Alignment.MIDDLE_LEFT); Button editBtn = new AreaButton("EDIT AREA"); buttonsLayout.addComponent(editBtn); editBtn.addClickListener(actionBtnListener); buttonsLayout.setComponentAlignment(editBtn, Alignment.MIDDLE_LEFT); Button deleteBtn = new AreaButton("DELETE AREA"); buttonsLayout.addComponent(deleteBtn); deleteBtn.addClickListener(actionBtnListener); buttonsLayout.setComponentAlignment(deleteBtn, Alignment.MIDDLE_LEFT); Button addProvinceBtn = new AreaButton("ADD PROVINCE"); buttonsLayout.addComponent(addProvinceBtn); addProvinceBtn.addClickListener(actionBtnListener); buttonsLayout.setComponentAlignment(addProvinceBtn, Alignment.MIDDLE_LEFT); Button addCityBtn = new AreaButton("ADD CITY"); buttonsLayout.addComponent(addCityBtn); addCityBtn.addClickListener(actionBtnListener); buttonsLayout.setComponentAlignment(addCityBtn, Alignment.MIDDLE_LEFT); return buttonsLayout; } Button.ClickListener actionBtnListener = new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (event.getButton().getCaption().equals("EDIT AREA")) { sub = new EditAreaWindow(); UI.getCurrent().addWindow(sub); } else if (event.getButton().getCaption().equals("ADD LOCATION TO AREA")) { sub = new AddLocationToAreaWindow(); UI.getCurrent().addWindow(sub); } else if (event.getButton().getCaption().equals("CREATE NEW AREA")) { sub = new CreateNewAreaWindow(); UI.getCurrent().addWindow(sub); } else if (event.getButton().getCaption().equals("DELETE AREA")) { sub = new DeleteAreaWindow(); UI.getCurrent().addWindow(sub); } else if (event.getButton().getCaption().equals("ADD PROVINCE")) { sub = new AddNewProvinceWindow(); UI.getCurrent().addWindow(sub); } else { sub = new AddNewCityWindow(); UI.getCurrent().addWindow(sub); } sub.addCloseListener(subCloseListener); } }; Window.CloseListener subCloseListener = new Window.CloseListener() { @Override public void windowClose(Window.CloseEvent e) { areaListTable(); } }; }