aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/fields/TabIndexes.java
blob: 179a512403337c3dab3788f6dd51804551f18c2d (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package com.vaadin.tests.fields;

import java.util.ArrayList;
import java.util.List;

import com.vaadin.annotations.Widgetset;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUIWithLog;
import com.vaadin.ui.Accordion;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.DateField;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.InlineDateField;
import com.vaadin.ui.Label;
import com.vaadin.ui.ListSelect;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.PasswordField;
import com.vaadin.ui.RichTextArea;
import com.vaadin.ui.Slider;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField;
import com.vaadin.ui.TreeGrid;
import com.vaadin.ui.TwinColSelect;
import com.vaadin.ui.VerticalLayout;

@Widgetset("com.vaadin.DefaultWidgetSet")
public class TabIndexes extends AbstractTestUIWithLog {

    public static final String FIELD_CONTAINER_ID = "field-container";
    private List<Focusable> fields = new ArrayList<>();

    @Override
    protected void setup(VaadinRequest request) {
        fields.add(new ComboBox());
        fields.add(new NativeSelect());
        fields.add(new ListSelect());
        fields.add(new TextField());
        fields.add(new DateField());
        fields.add(new InlineDateField());
        TreeGrid<String> tt = new TreeGrid<>();
        tt.addColumn(s -> s);
        tt.setItems("Foo", "Bar");

        fields.add(tt);
        fields.add(new TwinColSelect<String>());
        fields.add(new PasswordField());
        fields.add(new TextArea());
        fields.add(new RichTextArea());
        fields.add(new CheckBox());
        fields.add(new Slider());
        MenuBar menubar = new MenuBar();
        menubar.addItem("foo", item -> {
        });
        fields.add(menubar);
        TabSheet tabSheet = new TabSheet();
        tabSheet.addTab(new Label("Tab content"), "Tab 1");
        fields.add(tabSheet);
        Accordion accordion = new Accordion();
        accordion.addTab(new Label("Tab content"), "Tab 1");
        fields.add(accordion);

        HorizontalLayout buttonLayout = new HorizontalLayout();
        addComponent(buttonLayout);
        Button clearTabIndexes = new Button("Set all tab indexes to 0");
        clearTabIndexes.addClickListener(event -> {
            log("Setting tab indexes to 0");
            for (Focusable f : fields) {
                f.setTabIndex(0);
            }
            updateCaptions();
        });
        Button setTabIndexesToOne = new Button("Set all tab indexes to 1");
        setTabIndexesToOne.addClickListener(event -> {
            log("Setting tab indexes to 1");
            for (Focusable f : fields) {
                f.setTabIndex(1);
            }
            updateCaptions();
        });
        Button setTabIndexesInOrder = new Button("Set tab indexes to 1..N");
        setTabIndexesInOrder.addClickListener(event -> {
            int tabIndex = 1;
            log("Setting tab indexes to 1..N");
            for (Focusable f : fields) {
                f.setTabIndex(tabIndex++);
            }
            updateCaptions();
        });
        Button setTabIndexesInReverseOrder = new Button(
                "Set tab indexes to N..1");
        setTabIndexesInReverseOrder.addClickListener(event -> {
            int tabIndex = fields.size();
            log("Setting tab indexes to N..1");
            for (Focusable f : fields) {
                f.setTabIndex(tabIndex--);
            }
            updateCaptions();
        });

        clearTabIndexes.click();

        buttonLayout.addComponents(clearTabIndexes, setTabIndexesToOne,
                setTabIndexesInOrder, setTabIndexesInReverseOrder);

        VerticalLayout vl = new VerticalLayout();
        vl.setId(FIELD_CONTAINER_ID);
        for (Component f : fields) {
            f.setId("field-" + f.getClass().getSimpleName());
            vl.addComponent(f);
        }
        addComponent(vl);
    }

    protected void updateCaptions() {
        for (Focusable f : fields) {
            f.setCaption(f.getClass().getSimpleName() + " Tab index: "
                    + f.getTabIndex());
        }
    }

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

    @Override
    protected String getTestDescription() {
        return "Tab index should be propagated into html";
    }

}