aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/layouts/layouttester/GridLayoutTests.java
blob: 8da94feb7f0d95374a1e913a11ac7a41c20f0e85 (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
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
package com.vaadin.tests.layouts.layouttester;

import java.util.Date;

import com.vaadin.Application;
import com.vaadin.server.Resource;
import com.vaadin.server.SystemError;
import com.vaadin.server.ThemeResource;
import com.vaadin.server.UserError;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.AbstractField;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.DateField;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.InlineDateField;
import com.vaadin.ui.Label;
import com.vaadin.ui.Layout;
import com.vaadin.ui.Link;
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.Panel;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.Table;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.Reindeer;

public class GridLayoutTests extends AbstractLayoutTests {

    private AbstractComponent rc1, col1, col2, col3, row1, row2, row3, x3, x22;

    public GridLayoutTests(Application application) {
        super();
    }

    @Override
    protected Layout getAlignmentTests() {
        HorizontalLayout hlo = new HorizontalLayout();
        hlo.setSpacing(true);
        GridLayout glo = getTestGrid();
        glo.addStyleName(Reindeer.LAYOUT_WHITE);
        Alignment[] alignments = new Alignment[] { Alignment.BOTTOM_LEFT,
                Alignment.BOTTOM_CENTER, Alignment.BOTTOM_RIGHT,
                Alignment.MIDDLE_LEFT, Alignment.MIDDLE_CENTER,
                Alignment.MIDDLE_RIGHT, Alignment.TOP_LEFT,
                Alignment.TOP_CENTER, Alignment.TOP_RIGHT };

        glo.replaceComponent(col1, col1 = new TextField());
        glo.replaceComponent(col2, col2 = new TextField());
        glo.replaceComponent(col3, col3 = new TextField());
        ((TextField) col1).setValue("BOTTOM_RIGHT");
        ((TextField) col2).setValue("BOTTOM_LEFT");
        ((TextField) col3).setValue("BOTTOM_CENTER");
        glo.setComponentAlignment(col2, alignments[0]);
        glo.setComponentAlignment(col3, alignments[1]);
        glo.setComponentAlignment(col1, alignments[2]);

        glo.setComponentAlignment(row1, alignments[3]);
        glo.setComponentAlignment(row2, alignments[4]);
        glo.setComponentAlignment(row3, alignments[5]);
        hlo.addComponent(glo);
        glo = getTestGrid();
        glo.replaceComponent(row1, row1 = new DateField());
        glo.replaceComponent(row2, row2 = new DateField());
        glo.replaceComponent(row3, row3 = new DateField());
        ((DateField) row1).setResolution(DateField.RESOLUTION_SEC);
        ((DateField) row2).setResolution(DateField.RESOLUTION_SEC);
        ((DateField) row3).setResolution(DateField.RESOLUTION_SEC);
        glo.setComponentAlignment(col2, alignments[6]);
        glo.setComponentAlignment(col3, alignments[7]);
        glo.setComponentAlignment(col1, alignments[8]);
        hlo.addComponent(glo);
        return hlo;
    }

    @Override
    protected Layout getCaptionsTests() {
        GridLayout glo = getTestGrid();
        glo.setWidth("600px");
        String[] captions = new String[] {
                "",
                "abcdefghijklmnopq",
                "abc def hij klm nop qrs tuv xyz qaz wsx edc rfv tgb yhn ujm mko nji bhu vgy cft cde" };
        glo.replaceComponent(col1, col1 = new TextField());
        glo.replaceComponent(col2, col2 = new TextField());
        glo.replaceComponent(col3, col3 = new TextField());

        col1.setCaption(captions[0]);
        col2.setCaption(captions[1]);
        col3.setCaption(captions[2]);
        col3.setIcon(new ThemeResource(LOCK_16_PNG));

        glo.replaceComponent(row1, row1 = new Label());
        glo.replaceComponent(row2, row2 = new Label());
        glo.replaceComponent(row3, row3 = new Label());

        row1.setCaption(captions[0]);
        row2.setCaption(captions[1]);
        row3.setCaption(captions[2]);

        glo.replaceComponent(x3, x3 = getTestTabsheet());
        glo.replaceComponent(x22, x22 = getTestTable());
        x22.setComponentError(new UserError("component error, user error"));

        x3.setCaption(captions[1]);
        x22.setCaption(captions[2]);

        return glo;
    }

    @Override
    protected Layout getComponentAddReplaceMoveTests() {
        final GridLayout glo = getTestGrid();
        glo.setHeight("350px");
        Layout baseLayout = getBaseLayout();
        final Button button1 = new Button("Test add");
        final Button button2 = new Button("Test replace");
        final Button button3 = new Button("Test move");
        final Button button4 = new Button("Test remove comp 1,1");
        final Button button5 = new Button("Test remove row 0");
        final Button button6 = new Button("Test remove comp row3");

        baseLayout.addComponent(button1);
        baseLayout.addComponent(button2);
        baseLayout.addComponent(button3);
        baseLayout.addComponent(button4);
        baseLayout.addComponent(button5);
        baseLayout.addComponent(button6);
        baseLayout.addComponent(glo);
        button1.setEnabled(true);
        button2.setEnabled(false);
        button3.setEnabled(false);
        button4.setEnabled(false);
        button5.setEnabled(false);
        button6.setEnabled(false);

        final HorizontalLayout source = new HorizontalLayout();
        source.addComponent(new Label("MOVE LABEL 1"));
        source.addComponent(new Label("MOVE LABEL 2"));

        final AbstractComponent cc1 = getTestTabsheet();
        cc1.setCaption("ADDED COMPONENT");

        final AbstractComponent cc2 = getTestTabsheet();
        cc2.setCaption("REPLACEMENT COMPONENT");

        button1.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                glo.addComponent(cc1);
                button1.setEnabled(false);
                button2.setEnabled(true);
            }
        });
        button2.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                glo.replaceComponent(x22, cc2);
                button2.setEnabled(false);
                button3.setEnabled(true);
            }
        });
        button3.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                glo.moveComponentsFrom(source);
                button3.setEnabled(false);
                button4.setEnabled(true);
            }
        });
        button4.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                glo.removeComponent(1, 1);
                button4.setEnabled(false);
                button5.setEnabled(true);
            }
        });

        button5.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                glo.removeRow(0);
                button5.setEnabled(false);
                button6.setEnabled(true);
            }
        });
        button6.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                glo.removeComponent(row3);
                button6.setEnabled(false);
            }
        });

        return baseLayout;
    }

    @Override
    protected Layout getComponentSizingTests() {
        final GridLayout glo = getTestGrid();
        glo.setHeight("350px");
        Layout baseLayout = getBaseLayout();
        final Button button1 = new Button("full size, 3x1");
        final Button button2 = new Button("200 px width, 3x1");
        final Button button3 = new Button("200 px width, table");
        final Button button4 = new Button("undefined size+add, table");

        glo.replaceComponent(x22, x22 = getTestTable());

        baseLayout.addComponent(button1);
        baseLayout.addComponent(button2);
        baseLayout.addComponent(button3);
        baseLayout.addComponent(button4);
        baseLayout.addComponent(glo);
        button1.setEnabled(true);
        button2.setEnabled(false);
        button3.setEnabled(false);
        button4.setEnabled(false);

        button1.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                x3.setSizeFull();
                button1.setEnabled(false);
                button2.setEnabled(true);
            }
        });
        button2.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                x3.setWidth("200px");
                button2.setEnabled(false);
                button3.setEnabled(true);
            }
        });
        button3.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                x22.setWidth("200px");
                button3.setEnabled(false);
                button4.setEnabled(true);
            }
        });
        button4.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                x22.setSizeUndefined();
                ((Table) x22).addItem(new Object[] { "NEW ROW1" }, 3);
                ((Table) x22).addItem(new Object[] { "NEW ROW2" }, 4);
                button4.setEnabled(false);
            }
        });

        return baseLayout;
    }

    @Override
    protected Layout getExpandRatiosTests() {
        final GridLayout glo = getTestGrid();
        Layout baseLayout = getBaseLayout();
        final Button button1 = new Button("set col 3 expand 1");
        final Button button2 = new Button("set all cols expand 0.25");
        final Button button3 = new Button("set row 0 expand 0.5");
        final Button button4 = new Button("set row 3 expand 0.2");
        glo.setHeight("400px");
        glo.replaceComponent(x22, x22 = getTestTable());

        baseLayout.addComponent(button1);
        baseLayout.addComponent(button2);
        baseLayout.addComponent(button3);
        baseLayout.addComponent(button4);
        baseLayout.addComponent(glo);
        button1.setEnabled(true);
        button2.setEnabled(false);
        button3.setEnabled(false);
        button4.setEnabled(false);

        button1.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                glo.setColumnExpandRatio(3, 1);
                button1.setEnabled(false);
                button2.setEnabled(true);
            }
        });
        button2.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                glo.setColumnExpandRatio(0, 0.25f);
                glo.setColumnExpandRatio(1, 0.25f);
                glo.setColumnExpandRatio(2, 0.25f);
                glo.setColumnExpandRatio(3, 0.25f);
                button2.setEnabled(false);
                button3.setEnabled(true);
            }
        });
        button3.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                glo.setRowExpandRatio(0, 0.5f);
                button3.setEnabled(false);
                button4.setEnabled(true);
            }
        });
        button4.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                glo.setRowExpandRatio(3, 0.3f);
                button4.setEnabled(false);
            }
        });

        return baseLayout;
    }

    @Override
    protected Layout getIconsTests() {
        GridLayout glo = getTestGrid();
        glo.setWidth("600px");
        Resource[] icons = new Resource[] { new ThemeResource(CALENDAR_32_PNG),
                new ThemeResource(LOCK_16_PNG) };

        glo.replaceComponent(col1, col1 = new TextField("TEXTFIELD"));
        glo.replaceComponent(col2, col2 = new Label("LABEL"));
        glo.replaceComponent(col3, col3 = new Link("LINK", null));

        col1.setIcon(icons[0]);
        col2.setIcon(icons[1]);
        col3.setIcon(icons[0]);
        rc1.setIcon(icons[1]);
        col3.setCaption("long test caption bewucbwuebco or bmort b cbwecubw wbeucwe asdasd asdasda asdasd");
        col3.setComponentError(new UserError("component error, user error"));

        glo.replaceComponent(row1, row1 = new DateField());
        glo.replaceComponent(row2, row2 = new NativeSelect());
        glo.replaceComponent(row3, row3 = getTestTabsheet());

        row1.setIcon(icons[1]);
        row2.setIcon(icons[0]);
        row3.setIcon(icons[1]);

        glo.replaceComponent(x3, x3 = new CheckBox("CHECKBOX"));
        glo.replaceComponent(x22, x22 = new Panel("PANEL"));
        x22.setIcon(new ThemeResource(CALENDAR_32_PNG));

        x3.setIcon(icons[0]);
        x22.setIcon(icons[1]);

        return glo;
    }

    @Override
    protected Layout getLayoutSizingTests() {
        final GridLayout glo = getTestGrid();
        Layout baseLayout = getBaseLayout();
        baseLayout.setWidth("500px");
        baseLayout.setHeight("500px");
        final Button button1 = new Button("Set fixed height 350px");
        final Button button2 = new Button(
                "Set undefined size and add component");
        final Button button3 = new Button("Set fixed width and height 75%");
        final Button button4 = new Button("Set size full");

        glo.replaceComponent(x22, x22 = getTestTable());

        baseLayout.addComponent(button1);
        baseLayout.addComponent(button2);
        baseLayout.addComponent(button3);
        baseLayout.addComponent(button4);
        baseLayout.addComponent(glo);
        button1.setEnabled(true);
        button2.setEnabled(false);
        button3.setEnabled(false);
        button4.setEnabled(false);

        button1.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                glo.setHeight("350px");
                button1.setEnabled(false);
                button2.setEnabled(true);
            }
        });
        button2.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                glo.setSizeUndefined();
                glo.addComponent(new Label("--- NEW LABEL ---"));
                button2.setEnabled(false);
                button3.setEnabled(true);
            }
        });
        button3.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                glo.setWidth("75%");
                glo.setHeight("75%");
                button3.setEnabled(false);
                button4.setEnabled(true);
            }
        });
        button4.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                glo.setSizeFull();
                button4.setEnabled(false);
            }
        });

        return baseLayout;
    }

    @Override
    protected Layout getMarginSpacingTests() {
        final GridLayout glo = getTestGrid();
        Layout baseLayout = getBaseLayout();
        baseLayout.setWidth("500px");
        baseLayout.setHeight("500px");
        final Button button1 = new Button("Set margin on");
        final Button button2 = new Button("Set spacing on");
        final Button button3 = new Button("Set margin off");
        final Button button4 = new Button("Set spacing off");

        baseLayout.addComponent(button1);
        baseLayout.addComponent(button2);
        baseLayout.addComponent(button3);
        baseLayout.addComponent(button4);
        button1.setEnabled(true);
        button2.setEnabled(false);
        button3.setEnabled(false);
        button4.setEnabled(false);

        baseLayout.addComponent(glo);

        button1.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                glo.setMargin(true);
                button1.setEnabled(false);
                button2.setEnabled(true);
            }
        });
        button2.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                glo.setSpacing(true);
                button2.setEnabled(false);
                button3.setEnabled(true);
            }
        });
        button3.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                glo.setMargin(false);
                button3.setEnabled(false);
                button4.setEnabled(true);
            }
        });
        button4.addListener(new Button.ClickListener() {
            private static final long serialVersionUID = 7716267156088629379L;

            @Override
            public void buttonClick(ClickEvent event) {
                glo.setSpacing(false);
                button4.setEnabled(false);
            }
        });

        return baseLayout;
    }

    @Override
    protected Layout getRequiredErrorIndicatorsTests() {
        GridLayout glo = getTestGrid();
        glo.setWidth("600px");
        Resource[] icons = new Resource[] { new ThemeResource(CALENDAR_32_PNG),
                new ThemeResource(LOCK_16_PNG) };

        glo.replaceComponent(col1, col1 = new TextField("TEXTFIELD"));
        glo.replaceComponent(col2, col2 = new Label("LABEL"));
        glo.replaceComponent(col3, col3 = new Link("LINK", null));

        col1.setIcon(icons[0]);
        col1.setComponentError(new UserError("component error, user error"));
        col2.setComponentError(new SystemError("component error, system error"));
        col3.setComponentError(new UserError("component error, user error"));

        glo.replaceComponent(row1, row1 = new DateField());
        glo.replaceComponent(row2, row2 = new NativeSelect());
        glo.replaceComponent(row3, row3 = getTestTabsheet());

        ((AbstractField<?>) col1).setRequired(true);
        ((AbstractField<?>) col1).setValidationVisible(true);
        ((AbstractField<?>) col1).setRequiredError("required error");

        ((AbstractField<?>) row1).setRequired(true);
        ((AbstractField<?>) row1).setValidationVisible(true);
        ((AbstractField<?>) row1).setRequiredError("required error");

        ((AbstractField<?>) row2).setRequired(true);
        ((AbstractField<?>) row2).setValidationVisible(true);
        ((AbstractField<?>) row2).setRequiredError("required error");
        row2.setComponentError(new UserError("component error, user error"));

        row3.setComponentError(new UserError("component error, user error"));
        row3.setIcon(icons[1]);
        row3.setCaption("long test caption bewucbwuebco or bmort b cbwecubw wbeucwe asdasd asdasda asdasd");

        glo.replaceComponent(x3, x3 = new CheckBox("CHECKBOX"));
        glo.replaceComponent(x22, x22 = new Panel("PANEL"));

        x3.setComponentError(new UserError("component error, user error"));
        x22.setComponentError(new UserError("component error, user error"));
        x22.setIcon(icons[0]);

        return glo;
    }

    private GridLayout getTestGrid() {
        // Create a 4 by 4 grid layout.
        GridLayout grid = new GridLayout(4, 4);
        // Fill out the first row using the cursor.
        grid.addComponent(rc1 = new Button("R/C 1"));

        grid.addComponent(col1 = new Button("Col " + (grid.getCursorX() + 1)));
        grid.addComponent(col2 = new Button("Col " + (grid.getCursorX() + 1)));
        grid.addComponent(col3 = new Button("Col " + (grid.getCursorX() + 1)));

        // Fill out the first column using coordinates.

        grid.addComponent(row1 = new Button("Row " + 1), 0, 1);
        grid.addComponent(row2 = new Button("Row " + 2), 0, 2);
        grid.addComponent(row3 = new Button("Row " + 3), 0, 3);

        // Add some components of various shapes.
        grid.addComponent(x3 = new Button("3x1 button"), 1, 1, 3, 1);
        grid.addComponent(new Label("1x2 cell"), 1, 2, 1, 3);
        x22 = new InlineDateField("A 2x2 date field");
        ((InlineDateField) x22).setResolution(DateField.RESOLUTION_DAY);
        ((InlineDateField) x22).setValue(new Date(128028960000l));
        grid.addComponent(x22, 2, 2, 3, 3);
        grid.setWidth("450px");
        grid.setHeight("450px");
        return grid;
    }

    private VerticalLayout getBaseLayout() {
        VerticalLayout vlo = new VerticalLayout();
        vlo.setSizeUndefined();
        return vlo;
    }

    private AbstractComponent getTestTabsheet() {
        TabSheet tabsheet = new TabSheet();
        tabsheet.setSizeUndefined();
        tabsheet.addTab(new UndefWideLabel("TAB1"), "TAB1", new ThemeResource(
                GLOBE_16_PNG));
        tabsheet.addTab(new UndefWideLabel("TAB2"), "TAB2", null);
        return tabsheet;
    }

    private Table getTestTable() {
        Table t = new Table();
        t.setSizeUndefined();
        t.setPageLength(5);
        t.addContainerProperty("test", String.class, null);
        t.addItem(new Object[] { "qwertyuiop asdfghjklzxccvbnm,m,." }, 1);
        t.addItem(new Object[] { "YGVYTCTCTRXRXRXRX" }, 2);
        return t;
    }

}