aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/optiongroup/OptionGroups.java
blob: c4c588d1eac0bfb48bfad58cc946605b5cf289da (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
package com.vaadin.tests.components.optiongroup;

import java.util.Collection;
import java.util.LinkedHashMap;

import com.vaadin.server.ThemeResource;
import com.vaadin.tests.components.select.AbstractSelectTestCase;
import com.vaadin.ui.OptionGroup;

public class OptionGroups extends AbstractSelectTestCase<OptionGroup> {

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

    @Override
    protected void createActions() {
        super.createActions();

        createDisabledItemsMultiToggle("Disabled items");
        createBooleanAction("HTML content allowed", CATEGORY_STATE, false,
                new Command<OptionGroup, Boolean>() {
                    @Override
                    public void execute(OptionGroup og, Boolean value,
                            Object data) {
                        og.setHtmlContentAllowed(value.booleanValue());
                    }
                });
        createIconToggle("Item icons");
    }

    private void createIconToggle(String string) {
        LinkedHashMap<String, ThemeResource> options = new LinkedHashMap<String, ThemeResource>();
        options.put("-", null);
        options.put("16x16", ICON_16_USER_PNG_CACHEABLE);
        options.put("32x32", ICON_32_ATTENTION_PNG_CACHEABLE);
        options.put("64x64", ICON_64_EMAIL_REPLY_PNG_CACHEABLE);

        createSelectAction(string, CATEGORY_DECORATIONS, options, options
                .keySet().iterator().next(),
                new Command<OptionGroup, ThemeResource>() {
                    @Override
                    public void execute(OptionGroup c, ThemeResource icon,
                            Object data) {
                        Collection<?> itemIds = c.getItemIds();
                        for (Object itemId : itemIds) {
                            c.setItemIcon(itemId, icon);
                        }
                    }
                });
    }

    private void createDisabledItemsMultiToggle(String category) {
        for (Object id : getComponent().getItemIds()) {
            createBooleanAction(id.toString() + " - enabled", category, true,
                    enabledItemCommand, id);
        }
    }

    private Command<OptionGroup, Boolean> enabledItemCommand = new Command<OptionGroup, Boolean>() {

        @Override
        public void execute(OptionGroup c, Boolean value, Object data) {
            c.setItemEnabled(data, value);

        }
    };

}