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 + ".");