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

import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.*;

import java.util.HashMap;
import java.util.Map;

public class FirstTabNotVisibleWhenTabsheetNotClipped extends AbstractTestUI {

    private TabSheet.Tab firstNotClippedTab;
    private TabSheet.Tab firstClippedTab;

    @Override
    protected void setup(VaadinRequest request) {
        addButton("Toggle first not clipped tab", new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                firstNotClippedTab.setVisible(!firstNotClippedTab.isVisible());
            }
        });
        addComponent(createNotClippedTabSheet());

        addButton("Toggle first clipped tab", new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                firstClippedTab.setVisible(!firstClippedTab.isVisible());
            }
        });
        addComponent(createClippedTabSheet());

        addComponent(new Label("VerticalLayout:"));
        addBlock(new VerticalLayout());
        addComponent(new Label("HorizontalLayout:"));
        addBlock(new HorizontalLayout());
    }

    private TabSheet createNotClippedTabSheet() {
        TabSheet notClippedTabSheet = new TabSheet();
        for (int i = 0; i < 2; i++) {
            notClippedTabSheet.addTab(createTabContent(i), "Tab " + i);
        }
        firstNotClippedTab = notClippedTabSheet.getTab(0);
        return notClippedTabSheet;
    }

    private TabSheet createClippedTabSheet() {
        TabSheet clippedTabSheet = new TabSheet();
        for (int i = 0; i < 50; i++) {
            clippedTabSheet.addTab(createTabContent(i), "Tab " + i);
        }
        firstClippedTab = clippedTabSheet.getTab(0);
        return clippedTabSheet;
    }

    private VerticalLayout createTabContent(int index) {
        VerticalLayout layout = new VerticalLayout();
        layout.addComponent(new Label("Tab " + index + " Content"));
        return layout;
    }

    private void addBlock(Layout layout) {
        layout.setWidth("300px");

        TabSheet tabsheet = new TabSheet();
        String[] letters = { "A", "B", "C", "D" };
        HashMap<String, TabSheet.Tab> tabMap = new HashMap<String, TabSheet.Tab>();

        for (String letter : letters) {
            VerticalLayout vLayout = new VerticalLayout();
            vLayout.addComponent(new Label(letter + 1));
            vLayout.addComponent(new Label(letter + 2));
            vLayout.addComponent(new Label(letter + 3));

            tabsheet.addTab(vLayout);
            tabsheet.getTab(vLayout).setCaption("tab " + letter);

            tabMap.put("tab " + letter, tabsheet.getTab(vLayout));
        }

        VerticalLayout vtabLayout = new VerticalLayout();

        for (String letter : letters) {
            Button btntab = new Button("show tab " + letter);
            btntab.setId("tab " + letter);
            btntab.addClickListener(createTabListener(tabMap, tabsheet));
            vtabLayout.addComponent(btntab);
        }

        layout.addComponent(vtabLayout);
        layout.addComponent(tabsheet);
        addComponent(layout);
    }

    private Button.ClickListener createTabListener(
            final HashMap<String, TabSheet.Tab> map, final TabSheet tabsheet) {

        Button.ClickListener clickListener = new Button.ClickListener() {

            @Override
            public void buttonClick(Button.ClickEvent event) {
                // id of the button is the same as the tab's caption
                String tabName = event.getComponent().getId();

                for (Map.Entry<String, TabSheet.Tab> entry : map.entrySet()) {
                    TabSheet.Tab tab = entry.getValue();

                    if (entry.getKey().equals(tabName)) {
                        tab.setVisible(true);
                        tabsheet.setSelectedTab(tab.getComponent());
                    } else {
                        tab.setVisible(false);
                    }
                }
            }
        };
        return clickListener;
    }

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

    @Override
    public String getDescription() {
        return "TabSheet should display re-shown tab if there's room for it";
    }
}