1 package com.vaadin.tests.components.tabsheet;
3 import java.util.HashMap;
6 import com.vaadin.server.VaadinRequest;
7 import com.vaadin.tests.components.AbstractTestUI;
8 import com.vaadin.ui.Button;
9 import com.vaadin.ui.HorizontalLayout;
10 import com.vaadin.ui.Label;
11 import com.vaadin.ui.Layout;
12 import com.vaadin.ui.TabSheet;
13 import com.vaadin.ui.VerticalLayout;
15 public class FirstTabNotVisibleWhenTabsheetNotClipped extends AbstractTestUI {
17 private TabSheet.Tab firstNotClippedTab;
18 private TabSheet.Tab firstClippedTab;
21 protected void setup(VaadinRequest request) {
22 addButton("Toggle first not clipped tab", new Button.ClickListener() {
24 public void buttonClick(Button.ClickEvent event) {
25 firstNotClippedTab.setVisible(!firstNotClippedTab.isVisible());
28 addComponent(createNotClippedTabSheet());
30 addButton("Toggle first clipped tab", new Button.ClickListener() {
32 public void buttonClick(Button.ClickEvent event) {
33 firstClippedTab.setVisible(!firstClippedTab.isVisible());
36 addComponent(createClippedTabSheet());
38 addComponent(new Label("VerticalLayout:"));
39 addBlock(new VerticalLayout());
40 addComponent(new Label("HorizontalLayout:"));
41 addBlock(new HorizontalLayout());
44 private TabSheet createNotClippedTabSheet() {
45 TabSheet notClippedTabSheet = new TabSheet();
46 for (int i = 0; i < 2; i++) {
47 notClippedTabSheet.addTab(createTabContent(i), "Tab " + i);
49 firstNotClippedTab = notClippedTabSheet.getTab(0);
50 return notClippedTabSheet;
53 private TabSheet createClippedTabSheet() {
54 TabSheet clippedTabSheet = new TabSheet();
55 for (int i = 0; i < 50; i++) {
56 clippedTabSheet.addTab(createTabContent(i), "Tab " + i);
58 firstClippedTab = clippedTabSheet.getTab(0);
59 return clippedTabSheet;
62 private VerticalLayout createTabContent(int index) {
63 VerticalLayout layout = new VerticalLayout();
64 layout.addComponent(new Label("Tab " + index + " Content"));
68 private void addBlock(Layout layout) {
69 layout.setWidth("300px");
71 TabSheet tabsheet = new TabSheet();
72 String[] letters = { "A", "B", "C", "D" };
73 HashMap<String, TabSheet.Tab> tabMap = new HashMap<>();
75 for (String letter : letters) {
76 VerticalLayout vLayout = new VerticalLayout();
77 vLayout.addComponent(new Label(letter + 1));
78 vLayout.addComponent(new Label(letter + 2));
79 vLayout.addComponent(new Label(letter + 3));
81 tabsheet.addTab(vLayout);
82 tabsheet.getTab(vLayout).setCaption("tab " + letter);
84 tabMap.put("tab " + letter, tabsheet.getTab(vLayout));
87 VerticalLayout vtabLayout = new VerticalLayout();
89 for (String letter : letters) {
90 Button btntab = new Button("show tab " + letter);
91 btntab.setId("tab " + letter);
92 btntab.addClickListener(createTabListener(tabMap, tabsheet));
93 vtabLayout.addComponent(btntab);
96 layout.addComponent(vtabLayout);
97 layout.addComponent(tabsheet);
101 private Button.ClickListener createTabListener(
102 final HashMap<String, TabSheet.Tab> map, final TabSheet tabsheet) {
104 Button.ClickListener clickListener = new Button.ClickListener() {
107 public void buttonClick(Button.ClickEvent event) {
108 // id of the button is the same as the tab's caption
109 String tabName = event.getComponent().getId();
111 for (Map.Entry<String, TabSheet.Tab> entry : map.entrySet()) {
112 TabSheet.Tab tab = entry.getValue();
114 if (entry.getKey().equals(tabName)) {
115 tab.setVisible(true);
116 tabsheet.setSelectedTab(tab.getComponent());
118 tab.setVisible(false);
123 return clickListener;
127 protected Integer getTicketNumber() {
132 public String getDescription() {
133 return "TabSheet should display re-shown tab if there's room for it";