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

import com.vaadin.event.ShortcutAction;
import com.vaadin.event.ShortcutListener;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractReindeerTestUI;
import com.vaadin.ui.ComboBox;

public class ComboBoxReadOnlyPopup extends AbstractReindeerTestUI {

    static final String[] ITEMS = { "First", "Second", "Third" };

    @Override
    protected void setup(VaadinRequest request) {
        String boxLabel = String
                .format("Press 'Q' to toggle ComboBox's read-only mode");
        final ComboBox<String> comboBox = new ComboBox<>(boxLabel);

        comboBox.setItems(ITEMS);
        comboBox.setSelectedItem(ITEMS[0]);

        ShortcutListener shortcutListener = new ShortcutListener("", null,
                ShortcutAction.KeyCode.Q) {
            @Override
            public void handleAction(Object sender, Object target) {
                comboBox.setReadOnly(!comboBox.isReadOnly());
            }
        };
        comboBox.addShortcutListener(shortcutListener);

        addComponents(comboBox);
    }

    @Override
    protected String getTestDescription() {
        return "ComboBox that turns to read-only mode while expanded "
                + "should have its popup set to hidden.";
    }

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

}