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.abstractclasses.AbstractWindow; import com.save.common.CommonComboBox; import com.save.model.Province; import com.save.service.AreaService; import com.save.area.serviceprovider.AreaServiceImpl; import com.vaadin.ui.Button; import com.vaadin.ui.ComboBox; import com.vaadin.ui.Notification; import com.vaadin.ui.TextField; import com.vaadin.ui.VerticalLayout; /** * * @author jetdario */ public class AddNewCityWindow extends AbstractWindow { AreaService as = new AreaServiceImpl(); CommonComboBox cbox = new CommonComboBox(); ComboBox province = cbox.provinces(); TextField cityField = new TextField("City/Town: "); public AddNewCityWindow() { setCaption("ADD CITY/TOWN"); setWidth("300px"); setResizable(false); setContent(getVlayout()); getContent().setHeightUndefined(); } VerticalLayout getVlayout() { VerticalLayout vlayout = new VerticalLayout(); vlayout.setSizeFull(); vlayout.setMargin(true); vlayout.setSpacing(true); province.setInputPrompt("Select Province.."); province.setWidth("100%"); vlayout.addComponent(province); cityField.setWidth("100%"); vlayout.addComponent(cityField); Button addCityBtn = new Button("ADD CITY"); addCityBtn.setWidth("100%"); addCityBtn.addClickListener(addCityBtnListener); vlayout.addComponent(addCityBtn); return vlayout; } Button.ClickListener addCityBtnListener = new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (province.getValue() == null) { Notification.show("Select a Province!", Notification.Type.ERROR_MESSAGE); return; } if (cityField.getValue().trim().isEmpty() || cityField.getValue() == null) { Notification.show("City Field is NULL!", Notification.Type.ERROR_MESSAGE); return; } if (as.isCityExist(cityField.getValue().toLowerCase().trim(), (int) province.getValue())) { Notification.show("City/Town already exist!", Notification.Type.ERROR_MESSAGE); return; } boolean result = as.addCity(cityField.getValue().toLowerCase().trim(), (int) province.getValue()); if (result) { close(); } } }; }