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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
package com.vaadin.tests.components.tabsheet;
import java.util.LinkedHashMap;
import com.vaadin.server.Resource;
import com.vaadin.tests.components.AbstractComponentContainerTest;
import com.vaadin.ui.Component;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TabSheet.CloseHandler;
import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
import com.vaadin.ui.TabSheet.SelectedTabChangeListener;
import com.vaadin.ui.TabSheet.Tab;
public class TabSheetTest<T extends TabSheet> extends
AbstractComponentContainerTest<T> implements SelectedTabChangeListener {
private Command<T, Integer> setTabCaption = new Command<T, Integer>() {
@Override
public void execute(T c, Integer value, Object data) {
c.getTab(value).setCaption((String) data);
}
};
private Command<T, Integer> setTabIcon = new Command<T, Integer>() {
@Override
public void execute(T c, Integer value, Object data) {
c.getTab(value).setIcon((Resource) data, "tabicon");
}
};
private Command<T, Integer> setTabClosable = new Command<T, Integer>() {
@Override
public void execute(T c, Integer value, Object data) {
c.getTab(value).setClosable((Boolean) data);
}
};
private Command<T, Boolean> setCloseHandlerListener = new Command<T, Boolean>() {
@Override
public void execute(T c, Boolean value, Object data) {
if (value) {
c.setCloseHandler(new CloseHandler() {
@Override
public void onTabClose(TabSheet tabsheet, Component c) {
tabClosed(tabsheet, tabsheet.getTab(c));
tabsheet.removeComponent(c);
}
});
} else {
c.setCloseHandler(new CloseHandler() {
@Override
public void onTabClose(TabSheet tabsheet, Component c) {
tabsheet.removeComponent(c);
}
});
}
}
};
private Command<T, Boolean> setSelectedTabListener = new Command<T, Boolean>() {
@Override
public void execute(T c, Boolean value, Object data) {
if (value) {
c.addListener((SelectedTabChangeListener) TabSheetTest.this);
} else {
c.removeListener((SelectedTabChangeListener) TabSheetTest.this);
}
}
};
private Command<T, Integer> selectTab = new Command<T, Integer>() {
@Override
public void execute(T c, Integer index, Object data) {
c.setSelectedTab(c.getTab(index).getComponent());
}
};
private Command<T, Boolean> hideTabs = new Command<T, Boolean>() {
@Override
public void execute(T c, Boolean value, Object data) {
c.hideTabs(value);
}
};
@SuppressWarnings("unchecked")
@Override
protected Class<T> getTestClass() {
return (Class<T>) TabSheet.class;
}
@Override
protected void createActions() {
super.createActions();
createSetTabCaptionIcon(CATEGORY_FEATURES);
createSelectTab(CATEGORY_FEATURES);
createClosableToggle(CATEGORY_FEATURES);
createCloseHandlerToggle(CATEGORY_LISTENERS);
createSelectListenerToggle(CATEGORY_LISTENERS);
createHideTabsToggle(CATEGORY_FEATURES);
// TODO
// Insert tab at x
}
private void createHideTabsToggle(String category) {
createBooleanAction("Hide tabs", category, false, hideTabs);
}
private void createSelectListenerToggle(String category) {
createBooleanAction("Selected tab listener", category, false,
setSelectedTabListener);
}
private void createCloseHandlerToggle(String category) {
createBooleanAction("Close event listener (handler)", category, false,
setCloseHandlerListener);
}
private void createClosableToggle(String category) {
String closableCategory = "Set tab closable";
createCategory(closableCategory, category);
for (int i = 0; i < 20; i++) {
String tabClosableCategory = "Tab " + i + " closable";
createCategory(tabClosableCategory, closableCategory);
createClickAction("true", tabClosableCategory, setTabClosable, i,
true);
createClickAction("false", tabClosableCategory, setTabClosable, i,
false);
}
}
private void createSelectTab(String category) {
String selectTabCategory = "Select tab";
createCategory(selectTabCategory, category);
for (int i = 0; i < 20; i++) {
createClickAction("Select tab " + i, selectTabCategory, selectTab,
i);
}
}
private void createSetTabCaptionIcon(String category) {
String captionCategory = "Set tab caption";
String iconCategory = "Set tab icon";
createCategory(captionCategory, category);
createCategory(iconCategory, category);
String captionOptions[] = new String[] { "", "{id}", "Tab {id}",
"A long caption for tab {id}" };
LinkedHashMap<String, Resource> iconOptions = new LinkedHashMap<String, Resource>();
iconOptions.put("-", null);
iconOptions.put("16x16 (cachable)", ICON_16_USER_PNG_CACHEABLE);
iconOptions.put("16x16 (uncachable)", ICON_16_USER_PNG_UNCACHEABLE);
iconOptions.put("32x32 (cachable)", ICON_32_ATTENTION_PNG_CACHEABLE);
iconOptions
.put("32x32 (uncachable)", ICON_32_ATTENTION_PNG_UNCACHEABLE);
iconOptions.put("64x64 (cachable)", ICON_64_EMAIL_REPLY_PNG_CACHEABLE);
iconOptions.put("64x64 (uncachable)",
ICON_64_EMAIL_REPLY_PNG_UNCACHEABLE);
for (int i = 0; i < 20; i++) {
String tabCaptionCategory = "Tab " + i + " caption";
String tabIconCategory = "Tab " + i + " icon";
createCategory(tabCaptionCategory, captionCategory);
createCategory(tabIconCategory, iconCategory);
createClickAction("(null)", tabCaptionCategory, setTabCaption,
Integer.valueOf(i), null);
createClickAction("(null)", tabIconCategory, setTabIcon,
Integer.valueOf(i), null);
for (String option : captionOptions) {
option = option.replace("{id}", String.valueOf(i));
createClickAction(option, tabCaptionCategory, setTabCaption,
Integer.valueOf(i), option);
}
for (String option : iconOptions.keySet()) {
Resource icon = iconOptions.get(option);
createClickAction(option, tabIconCategory, setTabIcon,
Integer.valueOf(i), icon);
}
}
}
private void tabClosed(TabSheet tabSheet, Tab tab) {
log("Tab " + tabSheet.getTabPosition(tab) + " closed");
}
@Override
public void selectedTabChange(SelectedTabChangeEvent event) {
TabSheet ts = event.getTabSheet();
log("Tab " + ts.getTabPosition(ts.getTab(ts.getSelectedTab()))
+ " selected");
}
}
|