aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsLayoutExpand.java
blob: 54be39938d1f37ec9fa6c5e742b3d85993fce6fb (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
package com.vaadin.tests.components.grid;

import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.data.bean.Person;
import com.vaadin.ui.Grid;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;

/**
 * Tests the layouting of Grid's details row when it contains a HorizontalLayout
 * with expand ratios.
 *
 * @author Vaadin Ltd
 */
@SuppressWarnings("serial")
public class GridDetailsLayoutExpand extends SimpleGridUI {

    @Override
    protected void setup(VaadinRequest request) {
        Grid<Person> grid = createGrid();
        grid.setSizeFull();

        addComponent(grid);

        grid.setDetailsGenerator(item -> {
            final HorizontalLayout detailsLayout = new HorizontalLayout();
            detailsLayout.setSpacing(false);
            detailsLayout.setSizeFull();
            detailsLayout.setHeightUndefined();

            // Label 1 first element of the detailsLayout, taking 200 pixels
            final Label lbl1 = new Label("test1");
            lbl1.setWidth("200px");
            detailsLayout.addComponent(lbl1);

            // layout2 second element of the detailsLayout, taking the rest
            // of the available space
            final HorizontalLayout layout2 = new HorizontalLayout();
            layout2.setSpacing(false);
            layout2.setSizeFull();
            layout2.setHeightUndefined();
            detailsLayout.addComponent(layout2);
            detailsLayout.setExpandRatio(layout2, 1);

            // 2 Labels added to the layout2
            final Label lbl2 = new Label("test2");
            lbl2.setWidth("100%");
            lbl2.setId("lbl2");
            layout2.addComponent(lbl2);

            final Label lbl3 = new Label("test3");
            lbl3.setWidth("100%");
            lbl3.setId("lbl3");
            layout2.addComponent(lbl3);

            return detailsLayout;
        });

        grid.addItemClickListener(event -> {
            final Person itemId = event.getItem();
            grid.setDetailsVisible(itemId, !grid.isDetailsVisible(itemId));
        });
    }

    @Override
    protected Integer getTicketNumber() {
        return 18821;
    }

    @Override
    protected String getTestDescription() {
        return "Details row must be the same after opening another details row";
    }
}