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
214
215
216
217
218
219
220
221
222
223
224
|
/*
* Copyright 2000-2016 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.tests;
import com.vaadin.server.ClassResource;
import com.vaadin.server.ErrorMessage;
import com.vaadin.server.ExternalResource;
import com.vaadin.server.UserError;
import com.vaadin.shared.ui.ContentMode;
import com.vaadin.tests.components.TestDateField;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.AbstractDateField;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Component.Listener;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Layout;
import com.vaadin.ui.Link;
import com.vaadin.ui.Panel;
import com.vaadin.ui.RichTextArea;
import com.vaadin.ui.Slider;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.Upload;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.v7.ui.NativeSelect;
import com.vaadin.v7.ui.OptionGroup;
import com.vaadin.v7.ui.ProgressIndicator;
import com.vaadin.v7.ui.Select;
import com.vaadin.v7.ui.Table;
import com.vaadin.v7.ui.TextField;
import com.vaadin.v7.ui.Tree;
import com.vaadin.v7.ui.TwinColSelect;
public class TestCaptionWrapper extends CustomComponent implements Listener {
VerticalLayout main = new VerticalLayout();
final String eventListenerString = "Component.Listener feedback: ";
Label eventListenerFeedback = new Label(
eventListenerString + " <no events occurred>");
int count = 0;
public TestCaptionWrapper() {
setCompositionRoot(main);
}
@Override
public void attach() {
super.attach();
createNewView();
}
public void createNewView() {
main.removeAllComponents();
main.addComponent(
new Label("Each Layout and their contained components should "
+ "have icon, caption, description, user error defined. "
+ "Eeach layout should contain similar components."));
main.addComponent(eventListenerFeedback);
main.addComponent(new Label("OrderedLayout"));
test(main);
populateLayout(main);
VerticalLayout panelLayout = new VerticalLayout();
panelLayout.setMargin(true);
final Panel panel = new Panel("Panel", panelLayout);
test(panel);
populateLayout(panelLayout);
final TabSheet tabsheet = new TabSheet();
test(tabsheet);
final VerticalLayout tab1 = new VerticalLayout();
tab1.addComponent(new Label("try tab2"));
final VerticalLayout tab2 = new VerticalLayout();
test(tab2);
populateLayout(tab2);
tabsheet.addTab(tab1, "TabSheet tab1", new ClassResource("m.gif"));
tabsheet.addTab(tab2, "TabSheet tab2", new ClassResource("m.gif"));
final VerticalLayout expandLayout = new VerticalLayout();
test(expandLayout);
populateLayout(expandLayout);
final GridLayout gridLayout = new GridLayout();
test(gridLayout);
populateLayout(gridLayout);
VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
final Window window = new Window("TEST: Window", layout);
test(window);
populateLayout(layout);
}
void populateLayout(Layout layout) {
final Button button = new Button("Button " + count++);
test(layout, button);
button.addListener(this);
final AbstractDateField<?, ?> df = new TestDateField(
"DateField " + count++);
test(layout, df);
final CheckBox cb = new CheckBox("Checkbox " + count++);
test(layout, cb);
final Embedded emb = new Embedded("Embedded " + count++);
test(layout, emb);
VerticalLayout panelLayout = new VerticalLayout();
panelLayout.setMargin(true);
final Panel panel = new Panel("Panel " + count++, panelLayout);
test(layout, panel);
final Label label = new Label("Label " + count++);
test(layout, label);
final Link link = new Link("Link " + count++,
new ExternalResource("www.vaadin.com"));
test(layout, link);
final NativeSelect nativeSelect = new NativeSelect(
"NativeSelect " + count++);
test(layout, nativeSelect);
final OptionGroup optionGroup = new OptionGroup(
"OptionGroup " + count++);
test(layout, optionGroup);
final ProgressIndicator pi = new ProgressIndicator();
test(layout, pi);
final RichTextArea rta = new RichTextArea();
test(layout, rta);
final Select select = new Select("Select " + count++);
test(layout, select);
final Slider slider = new Slider("Slider " + count++);
test(layout, slider);
final Table table = new Table("Table " + count++);
test(layout, table);
final TextField tf = new TextField("Textfield " + count++);
test(layout, tf);
final Tree tree = new Tree("Tree " + count++);
test(layout, tree);
final TwinColSelect twinColSelect = new TwinColSelect(
"TwinColSelect " + count++);
test(layout, twinColSelect);
final Upload upload = new Upload("Upload (non-functional)", null);
test(layout, upload);
// Custom components
layout.addComponent(new Label("<B>Below are few custom components</B>",
ContentMode.HTML));
final TestForUpload tfu = new TestForUpload();
layout.addComponent(tfu);
}
/**
* Stresses component by configuring it
*
* @param c
*/
void test(AbstractComponent c) {
final ClassResource res = new ClassResource("m.gif");
final ErrorMessage errorMsg = new UserError("User error " + c);
if ((c.getCaption() == null) || (c.getCaption().length() <= 0)) {
c.setCaption("Caption " + c);
}
c.setDescription("Description " + c);
c.setComponentError(errorMsg);
c.setIcon(res);
}
/**
* Stresses component by configuring it in a given layout
*
* @param c
*/
void test(Layout layout, AbstractComponent c) {
test(c);
layout.addComponent(c);
}
@Override
public void componentEvent(Event event) {
final String feedback = eventListenerString + " source="
+ event.getSource() + ", toString()=" + event.toString();
System.out.println("eventListenerFeedback: " + feedback);
eventListenerFeedback.setValue(feedback);
}
}
|