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

import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Component;
import com.vaadin.ui.Label;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
import com.vaadin.ui.TabSheet.SelectedTabChangeListener;

public class PreventTabChange extends TestBase implements
        SelectedTabChangeListener {

    private TabSheet tabSheet;

    private Component lastTab;

    private Label tab1;
    private Label tab2;
    private Label tab3;

    @Override
    protected String getDescription() {
        return "Tests prevention of selecting certain tabs. Selecting the tabs in order (1-2-3-1) should work, while selecting out of order should cause the current tab to remain selected. The selected tab will actually first be changed (by the client) and then changed back (on the server response).";
    }

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

    @Override
    protected void setup() {
        tabSheet = new TabSheet();
        tabSheet.setId("tabsheet");
        tabSheet.addSelectedTabChangeListener(this);
        tab1 = new Label("Tab 1 contents");
        tab2 = new Label("Tab 2 contents");
        tab3 = new Label("Tab 3 contents");

        tabSheet.addTab(tab1, "The first tab", null);
        tabSheet.addTab(tab2, "The second tab", null);
        tabSheet.addTab(tab3, "The third tab", null);

        lastTab = tab1;
        tabSheet.setSelectedTab(tab1);

        addComponent(tabSheet);
    }

    @Override
    public void selectedTabChange(SelectedTabChangeEvent event) {
        TabSheet tabsheet = event.getTabSheet();

        if (lastTab == tab1) {
            if (tabsheet.getSelectedTab() != tab2) {
                tabsheet.setSelectedTab(lastTab);
            }
        } else if (lastTab == tab2) {
            if (tabsheet.getSelectedTab() != tab3) {
                tabsheet.setSelectedTab(lastTab);
            }
        } else if (lastTab == tab3) {
            if (tabsheet.getSelectedTab() != tab1) {
                tabsheet.setSelectedTab(lastTab);
            }
        }

        lastTab = tabsheet.getSelectedTab();
    }
}