com.save.area.AddLocationToAreaWindow.java Source code

Java tutorial

Introduction

Here is the source code for com.save.area.AddLocationToAreaWindow.java

Source

/*
 * 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.ui.Button;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Notification;
import com.vaadin.ui.VerticalLayout;

/**
 *
 * @author jetdario
 */
public class AddLocationToAreaWindow extends AbstractWindow {

    AreaService as = new AreaServiceImpl();
    CommonComboBox cbox = new CommonComboBox();

    ComboBox area = cbox.areas();
    ComboBox province = cbox.provinces();
    ComboBox city = new ComboBox("Cities: ");

    public AddLocationToAreaWindow() {
        setCaption("ADD LOCATION TO AREA");
        setWidth("300px");
        setModal(true);
        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.setNullSelectionAllowed(false);
        vlayout.addComponent(area);

        province.setInputPrompt("Select Province..");
        province.addValueChangeListener(new ProvincePropertyChangeListener(city));
        vlayout.addComponent(province);

        city.setInputPrompt("Select City..");
        city.setWidth("100%");
        vlayout.addComponent(city);

        Button addBtn = new Button("ADD LOCATION TO AREA");
        addBtn.setWidth("100%");
        addBtn.addClickListener(addBtnListener);
        vlayout.addComponent(addBtn);

        return vlayout;
    }

    Button.ClickListener addBtnListener = new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {

            if (area.getValue() == null) {
                Notification.show("No AREA was selected!", Notification.Type.ERROR_MESSAGE);
                return;
            }

            boolean result = as.updateLocationToArea(area.getItemCaption(area.getValue()),
                    (int) province.getValue(), (int) city.getValue());
            if (result) {
                close();
            } else {
                Notification.show("ERROR ON SQL!", Notification.Type.ERROR_MESSAGE);
            }
        }
    };
}