aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/combobox/ComboBoxes2.java
blob: 867ef6b35c117fc849803e144a613fb8a273790f (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.vaadin.tests.components.combobox;

import java.util.LinkedHashMap;

import com.vaadin.server.Resource;
import com.vaadin.shared.ui.combobox.FilteringMode;
import com.vaadin.tests.components.select.AbstractSelectTestCase;
import com.vaadin.ui.ComboBox;

public class ComboBoxes2<T extends ComboBox> extends AbstractSelectTestCase<T> {

    private Command<T, String> inputPromptCommand = new Command<T, String>() {
        @Override
        public void execute(T c, String value, Object data) {
            c.setInputPrompt(value);
        }
    };
    private Command<T, FilteringMode> filteringModeCommand = new Command<T, FilteringMode>() {

        @Override
        public void execute(T c, FilteringMode value, Object data) {
            c.setFilteringMode(value);
        }
    };

    @Override
    protected Class<T> getTestClass() {
        return (Class<T>) ComboBox.class;
    }

    @Override
    protected void createActions() {
        super.createActions();
        createItemIconSelect(CATEGORY_DATA_SOURCE);
        createInputPromptAction(CATEGORY_FEATURES);
        createFilteringModeAction(CATEGORY_FEATURES);
        createNewItemsAllowedAction(CATEGORY_STATE);
        createTextInputAlowedAction(CATEGORY_STATE);
    }

    private void createTextInputAlowedAction(String category) {
        createBooleanAction("Text input allowed", category, true,
                new Command<T, Boolean>() {
                    @Override
                    public void execute(T c, Boolean value, Object data) {
                        c.setTextInputAllowed(value.booleanValue());
                    }
                });
    }

    private void createNewItemsAllowedAction(String category) {
        createBooleanAction("New items allowed", category, false,
                new Command<T, Boolean>() {
                    @Override
                    public void execute(T c, Boolean value, Object data) {
                        c.setNewItemsAllowed(value.booleanValue());
                    }
                });
    }

    private void createFilteringModeAction(String category) {
        LinkedHashMap<String, FilteringMode> options = new LinkedHashMap<String, FilteringMode>();
        options.put("Off", FilteringMode.OFF);
        options.put("Contains", FilteringMode.CONTAINS);
        options.put("Starts with", FilteringMode.STARTSWITH);

        createSelectAction("Filtering mode", category, options, "Contains",
                filteringModeCommand);

    }

    private void createInputPromptAction(String category) {
        LinkedHashMap<String, String> options = new LinkedHashMap<String, String>();
        options.put("-", null);
        options.put("Enter a value", "Enter a value");
        options.put("- Click here -", "- Click here -");
        createSelectAction("Input prompt", category, options, "-",
                inputPromptCommand);

    }

    private void createItemIconSelect(String category) {

        createSelectAction("Icon", category, createIconOptions(false), "-",
                new Command<T, Resource>() {

                    @Override
                    public void execute(T c, Resource value, Object data) {
                        for (Object id : c.getItemIds()) {
                            if (value == null) {
                                c.setItemIcon(id, null);
                            } else {
                                c.setItemIcon(id, value);
                            }
                        }
                    }
                });
    }

}