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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
package com.vaadin.tests.tickets;
import java.util.Iterator;
import com.vaadin.Application;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.util.MethodProperty;
import com.vaadin.server.SystemError;
import com.vaadin.server.ThemeResource;
import com.vaadin.shared.ui.AlignmentInfo.Bits;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.DateField;
import com.vaadin.ui.Form;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Layout;
import com.vaadin.ui.Layout.AlignmentHandler;
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.Panel;
import com.vaadin.ui.UI.LegacyWindow;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
public class Ticket1710 extends com.vaadin.Application {
@Override
public void init() {
setTheme("tests-tickets");
VerticalLayout lo = new VerticalLayout();
setMainWindow(new LegacyWindow("#1710", lo));
lo.setMargin(true);
lo.setSpacing(true);
lo.setWidth("100%");
// Hiding controls
HorizontalLayout hidingControls = new HorizontalLayout();
lo.addComponent(hidingControls);
// OrderedLayout
final VerticalLayout orderedLayout = new VerticalLayout();
LayoutTestingPanel oltp = new LayoutTestingPanel("OrderedLayout",
orderedLayout);
CheckBox cb = new CheckBox("OrderedLayout",
new MethodProperty<Boolean>(oltp, "visible"));
cb.setImmediate(true);
hidingControls.addComponent(cb);
lo.addComponent(oltp);
orderedLayout.setSpacing(false);
addFields(orderedLayout);
// GridLayout
GridLayout grid = new GridLayout(1, 1);
Panel g1tp = new LayoutTestingPanel("Gridlayout with 1 column", grid);
cb = new CheckBox("GridLayout (1col)", new MethodProperty<Boolean>(
g1tp, "visible"));
cb.setImmediate(true);
hidingControls.addComponent(cb);
g1tp.setVisible(false);
lo.addComponent(g1tp);
grid.setSpacing(true);
addFields(grid);
GridLayout grid2 = new GridLayout(2, 1);
Panel g2tp = new LayoutTestingPanel("Gridlayout with 2 columns", grid2);
cb = new CheckBox("GridLayout (2cols)", new MethodProperty<Boolean>(
g2tp, "visible"));
cb.setImmediate(true);
hidingControls.addComponent(cb);
g2tp.setVisible(false);
lo.addComponent(g2tp);
grid2.setSpacing(true);
addFields(grid2);
// ExpandLayout
VerticalLayout el = new VerticalLayout();
Panel elp = new LayoutTestingPanel(
"ExpandLayout width first component expanded", el);
cb = new CheckBox("ExpandLayout (vertical)",
new MethodProperty<Boolean>(elp, "visible"));
cb.setImmediate(true);
hidingControls.addComponent(cb);
elp.setVisible(false);
el.setHeight("700px");
addFields(el);
Component firstComponent = el.getComponentIterator().next();
firstComponent.setSizeFull();
el.setExpandRatio(firstComponent, 1);
lo.addComponent(elp);
HorizontalLayout elh = new HorizontalLayout();
Panel elhp = new LayoutTestingPanel(
"ExpandLayout width first component expanded; horizontal", elh);
cb = new CheckBox("ExpandLayout (horizontal)",
new MethodProperty<Boolean>(elhp, "visible"));
cb.setImmediate(true);
hidingControls.addComponent(cb);
elhp.setVisible(false);
elh.setWidth("2000px");
elh.setHeight("100px");
addFields(elh);
Component firstComponentElh = elh.getComponentIterator().next();
firstComponentElh.setSizeFull();
elh.setExpandRatio(firstComponentElh, 1);
lo.addComponent(elhp);
// CustomLayout
VerticalLayout cl = new VerticalLayout();
Panel clp = new LayoutTestingPanel("CustomLayout", cl);
cb = new CheckBox("CustomLayout", new MethodProperty<Boolean>(clp,
"visible"));
cb.setImmediate(true);
hidingControls.addComponent(cb);
clp.setVisible(false);
lo.addComponent(clp);
cl.addComponent(new Label("<<< Add customlayout testcase here >>>"));
// Form
Panel formPanel = new Panel("Form");
cb = new CheckBox("Form", new MethodProperty<Boolean>(formPanel,
"visible"));
cb.setImmediate(true);
hidingControls.addComponent(cb);
formPanel.setVisible(false);
formPanel.addComponent(getFormPanelExample());
lo.addComponent(formPanel);
for (Iterator<Component> i = hidingControls.getComponentIterator(); i
.hasNext();) {
((AbstractComponent) i.next()).setImmediate(true);
}
}
private Form getFormPanelExample() {
Form f = new Form();
f.setCaption("Test form");
CheckBox fb2 = new CheckBox("Test button", true);
fb2.setComponentError(new SystemError("Test error"));
f.addField("fb2", fb2);
TextField ft1 = new TextField("With caption");
ft1.setComponentError(new SystemError("Error"));
f.addField("ft1", ft1);
TextField ft2 = new TextField();
ft2.setComponentError(new SystemError("Error"));
ft2.setValue("Without caption");
f.addField("ft2", ft2);
TextField ft3 = new TextField("With caption and required");
ft3.setComponentError(new SystemError("Error"));
ft3.setRequired(true);
f.addField("ft3", ft3);
return f;
}
private void addFields(ComponentContainer lo) {
Button button = new Button("Test button");
button.setComponentError(new SystemError("Test error"));
lo.addComponent(button);
CheckBox b2 = new CheckBox("Test button");
b2.setComponentError(new SystemError("Test error"));
lo.addComponent(b2);
TextField t1 = new TextField("With caption");
t1.setComponentError(new SystemError("Error"));
lo.addComponent(t1);
TextField t2 = new TextField("With caption and required");
t2.setComponentError(new SystemError("Error"));
t2.setRequired(true);
lo.addComponent(t2);
TextField t3 = new TextField();
t3.setValue("Without caption");
t3.setComponentError(new SystemError("Error"));
lo.addComponent(t3);
lo.addComponent(new TextField("Textfield with no error in it"));
TextField tt1 = new TextField("100% wide Textfield with no error in it");
tt1.setWidth("100%");
lo.addComponent(tt1);
TextField tt2 = new TextField();
tt2.setWidth("100%");
tt2.setValue("100% wide Textfield with no error in it and no caption");
lo.addComponent(tt2);
TextField t4 = new TextField();
t4.setValue("Without caption, With required");
t4.setComponentError(new SystemError("Error"));
t4.setRequired(true);
lo.addComponent(t4);
TextField t5 = new TextField();
t5.setValue("Without caption, WIDE");
t5.setComponentError(new SystemError("Error"));
t5.setWidth("100%");
lo.addComponent(t5);
TextField t6 = new TextField();
t6.setValue("Without caption, With required, WIDE");
t6.setComponentError(new SystemError("Error"));
t6.setRequired(true);
t6.setWidth("100%");
lo.addComponent(t6);
TextField t7 = new TextField();
t7.setValue("With icon and required and icon");
t7.setComponentError(new SystemError("Error"));
t7.setRequired(true);
t7.setIcon(new ThemeResource("../runo/icons/16/ok.png"));
lo.addComponent(t7);
DateField d1 = new DateField(
"Datefield with caption and icon, next one without caption");
d1.setComponentError(new SystemError("Error"));
d1.setRequired(true);
d1.setIcon(new ThemeResource("../runo/icons/16/ok.png"));
lo.addComponent(d1);
DateField d2 = new DateField();
d2.setComponentError(new SystemError("Error"));
d2.setRequired(true);
lo.addComponent(d2);
}
public class LayoutTestingPanel extends Panel {
Layout testedLayout;
HorizontalLayout controls = new HorizontalLayout();
CheckBox marginLeft = new CheckBox("m-left", false);
CheckBox marginRight = new CheckBox("m-right", false);
CheckBox marginTop = new CheckBox("m-top", false);
CheckBox marginBottom = new CheckBox("m-bottom", false);
CheckBox spacing = new CheckBox("spacing", false);
VerticalLayout testPanelLayout = new VerticalLayout();
LayoutTestingPanel(String caption, Layout layout) {
super(caption);
VerticalLayout internalLayout = new VerticalLayout();
internalLayout.setWidth("100%");
setContent(internalLayout);
testedLayout = layout;
testPanelLayout.setWidth("100%");
Panel controlWrapper = new Panel();
controlWrapper.addComponent(controls);
controlWrapper.setWidth("100%");
controlWrapper.setStyleName("controls");
internalLayout.addComponent(controlWrapper);
Panel testPanel = new Panel(testPanelLayout);
testPanel.setStyleName("testarea");
testPanelLayout.addComponent(testedLayout);
internalLayout.addComponent(testPanel);
internalLayout.setMargin(true);
internalLayout.setSpacing(true);
controls.setSpacing(true);
controls.setMargin(false);
controls.addComponent(new Label("width"));
controls.addComponent(new TextField(new MethodProperty<Float>(
testedLayout, "width")));
controls.addComponent(new CheckBox("%",
new MethodProperty<Boolean>(this, "widthPercents")));
controls.addComponent(new Label("height"));
controls.addComponent(new TextField(new MethodProperty<Float>(
testedLayout, "height")));
controls.addComponent(new CheckBox("%",
new MethodProperty<Boolean>(this, "heightPercents")));
controls.addComponent(marginLeft);
controls.addComponent(marginRight);
controls.addComponent(marginTop);
controls.addComponent(marginBottom);
if (testedLayout instanceof Layout.SpacingHandler) {
controls.addComponent(spacing);
}
Property.ValueChangeListener marginSpacingListener = new Property.ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
updateMarginsAndSpacing();
}
};
marginBottom.addListener(marginSpacingListener);
marginTop.addListener(marginSpacingListener);
marginLeft.addListener(marginSpacingListener);
marginRight.addListener(marginSpacingListener);
spacing.addListener(marginSpacingListener);
updateMarginsAndSpacing();
addAlignmentControls();
testedLayout.setStyleName("tested-layout");
setStyleName("layout-testing-panel");
for (Iterator<Component> i = controls.getComponentIterator(); i
.hasNext();) {
((AbstractComponent) i.next()).setImmediate(true);
}
}
@SuppressWarnings("deprecation")
private void addAlignmentControls() {
if (!(testedLayout instanceof Layout.AlignmentHandler)) {
return;
}
@SuppressWarnings("unused")
final Layout.AlignmentHandler ah = (AlignmentHandler) testedLayout;
final NativeSelect vAlign = new NativeSelect();
final NativeSelect hAlign = new NativeSelect();
controls.addComponent(new Label("component alignment"));
controls.addComponent(hAlign);
controls.addComponent(vAlign);
hAlign.setNullSelectionAllowed(false);
vAlign.setNullSelectionAllowed(false);
vAlign.addItem(new Integer(Bits.ALIGNMENT_TOP));
vAlign.setItemCaption(new Integer(Bits.ALIGNMENT_TOP), "top");
vAlign.addItem(new Integer(Bits.ALIGNMENT_VERTICAL_CENTER));
vAlign.setItemCaption(new Integer(Bits.ALIGNMENT_VERTICAL_CENTER),
"center");
vAlign.addItem(new Integer(Bits.ALIGNMENT_BOTTOM));
vAlign.setItemCaption(new Integer(Bits.ALIGNMENT_BOTTOM), "bottom");
hAlign.addItem(new Integer(Bits.ALIGNMENT_LEFT));
hAlign.setItemCaption(new Integer(Bits.ALIGNMENT_LEFT), "left");
hAlign.addItem(new Integer(Bits.ALIGNMENT_HORIZONTAL_CENTER));
hAlign.setItemCaption(
new Integer(Bits.ALIGNMENT_HORIZONTAL_CENTER), "center");
hAlign.addItem(new Integer(Bits.ALIGNMENT_RIGHT));
hAlign.setItemCaption(new Integer(Bits.ALIGNMENT_RIGHT), "right");
Property.ValueChangeListener alignmentChangeListener = new Property.ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
Integer h = ((Integer) hAlign.getValue()).intValue();
int v = ((Integer) vAlign.getValue()).intValue();
updateAlignments(new Alignment(h + v));
}
};
hAlign.setValue(new Integer(Bits.ALIGNMENT_LEFT));
vAlign.addListener(alignmentChangeListener);
hAlign.addListener(alignmentChangeListener);
vAlign.setValue(new Integer(Bits.ALIGNMENT_TOP));
controls.addComponent(new Label("layout alignment"));
final NativeSelect lAlign = new NativeSelect();
controls.addComponent(lAlign);
lAlign.setNullSelectionAllowed(false);
lAlign.addItem(new Integer(Bits.ALIGNMENT_LEFT));
lAlign.setItemCaption(new Integer(Bits.ALIGNMENT_LEFT), "left");
lAlign.addItem(new Integer(Bits.ALIGNMENT_HORIZONTAL_CENTER));
lAlign.setItemCaption(
new Integer(Bits.ALIGNMENT_HORIZONTAL_CENTER), "center");
lAlign.addItem(new Integer(Bits.ALIGNMENT_RIGHT));
lAlign.setItemCaption(new Integer(Bits.ALIGNMENT_RIGHT), "right");
lAlign.addListener(new Property.ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
testPanelLayout.setComponentAlignment(
testedLayout,
new Alignment(((Integer) lAlign.getValue())
.intValue() + Bits.ALIGNMENT_TOP));
}
});
}
private void updateAlignments(Alignment a) {
for (Iterator<Component> i = testedLayout.getComponentIterator(); i
.hasNext();) {
((Layout.AlignmentHandler) testedLayout).setComponentAlignment(
i.next(), a);
}
}
private void updateMarginsAndSpacing() {
if (testedLayout instanceof Layout.MarginHandler) {
((Layout.MarginHandler) testedLayout).setMargin(new MarginInfo(
marginTop.getValue().booleanValue(), marginRight
.getValue().booleanValue(), marginBottom
.getValue().booleanValue(), marginLeft
.getValue().booleanValue()));
}
if (testedLayout instanceof Layout.SpacingHandler) {
((Layout.SpacingHandler) testedLayout).setSpacing(spacing
.getValue().booleanValue());
}
}
}
}
|