Package org.vaadin.addon.customfield.demo

Source Code of org.vaadin.addon.customfield.demo.CityFieldExample

package org.vaadin.addon.customfield.demo;

import org.vaadin.addon.customfield.demo.data.City;
import org.vaadin.addon.customfield.demo.field.CityField;

import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.ui.Component;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;

/**
* Demonstrate a custom field which wraps another field and provides additional
* layout and control elements.
*/
public class CityFieldExample extends CustomComponent implements Component {

    private VerticalLayout layout;

    public CityFieldExample() {
        layout = new VerticalLayout();
        layout.setMargin(true);

        layout.addComponent(new Label("Custom field for selecting a city"));

        final CityField field = new CityField();
        field.setImmediate(true);
        layout.addComponent(field);

        field.addListener(new ValueChangeListener() {
            public void valueChange(ValueChangeEvent event) {
                Object value = event.getProperty().getValue();
                if (value instanceof City) {
                    layout.getWindow().showNotification(
                            "The selected city is " + value + ".");
                } else {
                    layout.getWindow().showNotification("No city selected.");
                }
            }
        });

        setCompositionRoot(layout);
    }

}
TOP

Related Classes of org.vaadin.addon.customfield.demo.CityFieldExample

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.