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.service.AreaService; import com.save.area.serviceprovider.AreaServiceImpl; import com.vaadin.ui.Button; import com.vaadin.ui.Notification; import com.vaadin.ui.TextField; import com.vaadin.ui.VerticalLayout; /** * * @author jetdario */ public class AddNewProvinceWindow extends AbstractWindow { AreaService as = new AreaServiceImpl(); TextField provinceField = new TextField("Province: "); public AddNewProvinceWindow() { setCaption("ADD PROVINCE"); setWidth("300px"); setResizable(false); setContent(getVlayout()); getContent().setHeightUndefined(); } VerticalLayout getVlayout() { VerticalLayout vlayout = new VerticalLayout(); vlayout.setSizeFull(); vlayout.setMargin(true); vlayout.setSpacing(true); provinceField.setWidth("100%"); vlayout.addComponent(provinceField); Button provinceBtn = new Button("ADD PROVINCE"); provinceBtn.setWidth("100%"); provinceBtn.addClickListener(addProvinceBtnListener); vlayout.addComponent(provinceBtn); return vlayout; } Button.ClickListener addProvinceBtnListener = new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (provinceField.getValue().trim().isEmpty() || provinceField.getValue() == null) { Notification.show("Province Field is NULL!", Notification.Type.ERROR_MESSAGE); return; } boolean isProvinceExist = as.isProvinceExist(provinceField.getValue().toLowerCase().trim()); if (isProvinceExist) { Notification.show("Province already exist!", Notification.Type.ERROR_MESSAGE); return; } boolean result = as.addProvince(provinceField.getValue().toLowerCase().trim()); if (result) { close(); } } }; }