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

import java.util.Arrays;

import com.vaadin.data.HasValue.ValueChangeListener;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractReindeerTestUI;
import com.vaadin.tests.util.TestUtils;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.v7.ui.TextField;

@SuppressWarnings("deprecation")
public class ThemeTestUI extends AbstractReindeerTestUI {

    private TextField customStyle;
    private Button setStyleName;
    private CheckBox readOnly;
    private ComboBox<String> bgColor;
    private TestSampler sampler;
    private String customStyleName = null;

    @Override
    protected void setup(VaadinRequest request) {
        getLayout().setSpacing(true);

        createCustomStyleStringField();

        HorizontalLayout selectors = new HorizontalLayout();

        selectors.addComponent(customStyle);
        selectors.addComponent(setStyleName);
        if (showAdditionalControlFields()) {
            selectors.addComponent(readOnly);
            selectors.setComponentAlignment(readOnly, Alignment.MIDDLE_LEFT);
            selectors.addComponent(bgColor);
        }

        addComponent(selectors);

        sampler = new TestSampler();
        if (showAdditionalControlFields()) {
            for (ValueChangeListener<Boolean> listener : sampler
                    .getReadOnlyChangeListeners()) {
                readOnly.addValueChangeListener(listener);
            }
        }
        addComponent(sampler);

        if (showAdditionalControlFields()) {
            TestUtils.injectCSS(getLayout().getUI(),
                    "body .v-app .yellow {background-color: yellow;}");
        }
    }

    protected boolean showAdditionalControlFields() {
        return false;
    }

    private void createCustomStyleStringField() {
        customStyle = new TextField();
        customStyle.setId("customstyle");
        setStyleName = new Button("Set stylename",
                event -> onCustomStyleNameChanged(customStyle.getValue()));
        setStyleName.setId("setcuststyle");

        if (showAdditionalControlFields()) {
            readOnly = new CheckBox("Set read-only");
            bgColor = new ComboBox<>(null, Arrays.asList(
                    "Default sampler background", "Yellow sampler background"));
            bgColor.setValue("Default sampler background");
            bgColor.setEmptySelectionAllowed(false);
            bgColor.setWidth("270px");
            bgColor.addValueChangeListener(event -> {
                if ("Yellow sampler background".equals(bgColor.getValue())) {
                    addStyleName("yellow");
                } else {
                    removeStyleName("yellow");
                }
            });
        }
    }

    private void onCustomStyleNameChanged(String newStyleName) {
        sampler.setCustomStyleNameToComponents(customStyleName, newStyleName);
        customStyleName = newStyleName;
    }

    @Override
    protected String getTestDescription() {
        return "Test Sampler application with support for changing themes and stylenames.";
    }

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

}