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

import com.vaadin.ui.AbstractSelect;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.DateField;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.ListSelect;
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.OptionGroup;
import com.vaadin.ui.TextField;

/**
 * Simple test helper to test Focusable.focus() method.
 * 
 */
public class FocusingComponents extends CustomComponent {
    GridLayout lo = new GridLayout(2, 1);

    public FocusingComponents() {

        setCompositionRoot(lo);
        lo.setSpacing(true);

        Focusable f;

        f = new Button();

        addFocusableTest(f);
        addFocusableTest(new ComboBox());
        addFocusableTest(new TextField());
        addFocusableTest(new DateField());
        addFocusableTest(new NativeSelect());
        addFocusableTest(new ListSelect());
        addFocusableTest(new OptionGroup());
        OptionGroup optionGroup = new OptionGroup();
        optionGroup.setMultiSelect(true);
        addFocusableTest(optionGroup);

    }

    private void addFocusableTest(final Focusable f) {

        f.setCaption(f.getClass().getSimpleName());
        lo.addComponent(f);

        if (f instanceof AbstractSelect) {
            AbstractSelect s = (AbstractSelect) f;
            s.addItem("Foo");
            s.addItem("Bar");
        }

        Button focus = new Button("focus");
        focus.addListener(new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                f.focus();
            }
        });
        lo.addComponent(focus);

    }

}