aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxAutoresetValue.java
blob: 5a146432918375eab1c73b0bcc8dae3ef101a2e3 (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
package com.vaadin.tests.components.combobox;

import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUIWithLog;
import com.vaadin.ui.ComboBox;

public class ComboBoxAutoresetValue extends AbstractTestUIWithLog {

    public static final String RESET = "Reset";
    public static final String CHANGE = "Change to something else";
    public static final String SOMETHING = "Something else";

    @Override
    protected void setup(VaadinRequest request) {
        ComboBox<String> comboBox = new ComboBox<>();
        comboBox.setItems(RESET, CHANGE, SOMETHING);
        comboBox.addValueChangeListener(event -> {
            String value = event.getValue();
            log("Value changed to " + value);

            if (event.isUserOriginated()) {
                if (RESET.equals(value)) {
                    event.getSource().setValue(null);
                } else if (CHANGE.equals(value)) {
                    event.getSource().setValue(SOMETHING);
                }
            }
        });
        addComponent(comboBox);
    }

    @Override
    public String getDescription() {
        return "Changing the ComboBox value in its own value change listener should work";
    }

}