aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/customfield/AddressFormExample.java
blob: e5ac67b32ee348a9710586f457859214215f777a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.vaadin.tests.components.customfield;

import java.util.Locale;

import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.util.Address;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Notification;

/**
 * Demonstrate a custom field which is a form, and contains another custom field
 * for the selection of a city.
 */
public class AddressFormExample extends TestBase {

    @Override
    protected void setup() {
        getMainWindow().setLocale(Locale.ENGLISH);
        Address address = new Address("Ruukinkatu 2-4", 20540, "Turku");
        final AddressField field = new AddressField();
        field.setValue(address);
        field.setRequired(true);

        addComponent(field);

        Button commitButton = new Button("Save", new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                field.commit();
                Address address = field.getValue();
                Notification.show("Address saved: "
                        + address.getStreetAddress() + ", "
                        + address.getPostalCode() + ", " + address.getCity());
            }
        });
        addComponent(commitButton);
    }

    @Override
    protected String getDescription() {
        return "Custom field for editing an Address";
    }

    @Override
    protected Integer getTicketNumber() {
        return null;
    }

}