aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/components/textfield/EnumTextField.java
blob: 3e74530ac0e6fb9a09a35692260d1c875ec1951d (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
package com.vaadin.tests.components.textfield;

import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUIWithLog;
import com.vaadin.v7.data.util.ObjectProperty;
import com.vaadin.v7.ui.TextField;

public class EnumTextField extends AbstractTestUIWithLog {

    public enum MyEnum {
        FIRST_VALUE, VALUE, THE_LAST_VALUE;
    }

    @Override
    protected void setup(VaadinRequest request) {
        final TextField tf = new TextField();
        tf.setNullRepresentation("");
        tf.addValueChangeListener(event -> {
            if (tf.isValid()) {
                log(tf.getValue() + " (valid)");
            } else {
                log(tf.getValue() + " (INVALID)");
            }
        });

        tf.setPropertyDataSource(new ObjectProperty<Enum>(MyEnum.FIRST_VALUE));
        addComponent(tf);
    }

}