aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxSelecting.java
blob: 259e3026dc6e55513d8afd36f195556e3cf86db6 (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
51
52
53
54
55
56
package com.vaadin.tests.components.combobox;

import java.util.ArrayList;
import java.util.List;

import com.vaadin.annotations.Widgetset;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractReindeerTestUI;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;

@Widgetset("com.vaadin.DefaultWidgetSet")
public class ComboBoxSelecting extends AbstractReindeerTestUI {
    protected ComboBox<String> comboBox;
    protected List<String> items = new ArrayList<>();

    @Override
    protected void setup(VaadinRequest request) {
        for (char c = 'a'; c <= 'z'; c++) {
            for (int i = 0; i < 100; i++) {
                items.add("" + c + i);
            }
        }
        comboBox = new ComboBox<>(null, items);
        final Label label = new Label();
        label.setId("value");

        comboBox.setTextInputAllowed(true);
        comboBox.setEmptySelectionAllowed(true);

        comboBox.addValueChangeListener(event -> {
            String value = event.getValue();
            if (value != null) {
                label.setValue(value);
            } else {
                label.setValue("null");
            }
        });

        // Had to add an extra text field for our old Firefox browsers, because
        // tab will otherwise send the focus to address bar and FF 24 won't fire
        // a key event properly. Nice!
        addComponents(comboBox, label, new TextField());
    }

    @Override
    protected String getTestDescription() {
        return "Clearing the filter and hitting enter should select the null item";
    }

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