summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/themes/LegacyComponentThemeChange.java
blob: 0a57b77aa3f5137d1a9d07ad5e667d5ae1f50cbd (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
101
102
103
104
105
/*
 * Copyright 2000-2013 Vaadin Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.vaadin.tests.themes;

import com.vaadin.annotations.Theme;
import com.vaadin.event.Action;
import com.vaadin.event.Action.Handler;
import com.vaadin.server.ThemeResource;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUIWithLog;
import com.vaadin.tests.util.PersonContainer;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.MenuBar.MenuItem;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;

@Theme("reindeer")
public class LegacyComponentThemeChange extends AbstractTestUIWithLog {

    @Override
    protected void setup(VaadinRequest request) {
        VerticalLayout vl = new VerticalLayout();
        vl.setCaption("Change theme by clicking a button");
        HorizontalLayout hl = new HorizontalLayout();
        for (final String theme : new String[] { "reindeer", "runo" }) {
            Button b = new Button(theme);
            b.setId(theme + "");
            b.addClickListener(new ClickListener() {

                @Override
                public void buttonClick(ClickEvent event) {
                    getUI().setTheme(theme);
                }
            });
            hl.addComponent(b);
        }
        vl.addComponent(hl);

        // Always wants to use icon from Runo, even if we change theme
        ThemeResource alwaysTheSameIconImage = new ThemeResource(
                "../runo/icons/16/ok.png");
        ThemeResource varyingIcon = new ThemeResource("menubar-theme-icon.png");
        MenuBar bar = new MenuBar();
        bar.addItem("runo", alwaysTheSameIconImage, null);
        bar.addItem("selectedtheme", varyingIcon, null);
        MenuItem sub = bar.addItem("sub menu", null);
        sub.addItem("runo", alwaysTheSameIconImage, null);
        sub.addItem("selectedtheme", varyingIcon, null);

        vl.addComponent(bar);

        ComboBox cb = new ComboBox("ComboBox");
        cb.addItem("No icon");
        cb.addItem("Icon");
        cb.setItemIcon("Icon", new ThemeResource("comboboxicon.png"));
        cb.setValue("Icon");

        vl.addComponent(cb);

        Embedded e = new Embedded("embedded");
        e.setMimeType("application/x-shockwave-flash");
        e.setType(Embedded.TYPE_OBJECT);
        e.setSource(new ThemeResource("embedded.src"));
        vl.addComponent(e);

        Table t = new Table();
        t.addActionHandler(new Handler() {
            @Override
            public void handleAction(Action action, Object sender, Object target) {
            }

            @Override
            public Action[] getActions(Object target, Object sender) {
                return new Action[] { new Action("Theme icon",
                        new ThemeResource("action-icon.png")) };
            }
        });
        PersonContainer pc = PersonContainer.createWithTestData();
        pc.addNestedContainerBean("address");
        t.setContainerDataSource(pc);
        vl.addComponent(t);

        addComponent(vl);
    }

}