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.service.AreaService; import com.save.area.serviceprovider.AreaServiceImpl; import com.vaadin.data.Property; 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 EditAreaWindow extends AbstractWindow { AreaService as = new AreaServiceImpl(); CommonComboBox cbox = new CommonComboBox(); ComboBox area = cbox.areas(); TextField areaField = new TextField("Edit Area: "); Button editAreaBtn = new Button("UPDATE AREA"); public EditAreaWindow() { setCaption("EDIT AREA"); setWidth("300px"); setResizable(false); setContent(getVlayout()); getContent().setHeightUndefined(); } VerticalLayout getVlayout() { VerticalLayout vlayout = new VerticalLayout(); vlayout.setSizeFull(); vlayout.setMargin(true); vlayout.setSpacing(true); area.setInputPrompt("Select Area.."); area.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { areaField.setValue(area.getItemCaption(event.getProperty().getValue())); } }); vlayout.addComponent(area); areaField.setWidth("100%"); vlayout.addComponent(areaField); editAreaBtn.setWidth("100%"); editAreaBtn.addClickListener(editBtnListener); vlayout.addComponent(editAreaBtn); return vlayout; } Button.ClickListener editBtnListener = new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (as.isAreaExist(areaField.getValue())) { Notification.show("Area already exist!", Notification.Type.ERROR_MESSAGE); return; } boolean result = as.updateArea(areaField.getValue().trim().toLowerCase(), area.getItemCaption(area.getValue())); if (result) { close(); } } }; }