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

import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TabSheet.Tab;

public class TabSheetIndexOperations extends TestBase {

    private int tabCounter = 1;

    @Override
    protected void setup() {
        final TabSheet tabs = new TabSheet();

        // Add some tabs
        tabs.addTab(new Label("Content 1"), "Tab 1", null);
        tabs.addTab(new Label("Content 2"), "Tab 2", null);
        tabs.addTab(new Label("Content 3"), "Tab 3", null);

        addComponent(tabs);

        Button addTab = new Button("Add tab at index 2",
                new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        tabs.addTab(new Label("Content " + tabCounter),
                                "Added Tab " + tabCounter, null, 2);
                        tabCounter++;
                    }
                });
        addComponent(addTab);

        Button setCaption = new Button("Invert tab caption at index 2",
                new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        Tab tab = tabs.getTab(2);
                        tab.setCaption(new StringBuffer(tab.getCaption())
                                .reverse().toString());
                    }
                });
        addComponent(setCaption);

        Button move = new Button("Move selected tab to index 2",
                new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        tabs.setTabPosition(tabs.getTab(tabs.getSelectedTab()),
                                2);
                    }
                });
        addComponent(move);

        Button getIndex = new Button("Get selected tab index",
                new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        getMainWindow().showNotification(
                                "Index: "
                                        + tabs.getTabPosition(tabs.getTab(tabs
                                                .getSelectedTab())));

                    }
                });
        addComponent(getIndex);
    }

    @Override
    protected String getDescription() {
        return "You can use indexes to add and reorder the TabSheet";
    }

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

}