aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/table/TableRowHeight.java
blob: eb5efbc4f320b13cf41408d4bd74f44862394fa9 (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
package com.vaadin.tests.components.table;

import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Component;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Table;
import com.vaadin.ui.Table.ColumnGenerator;

public class TableRowHeight extends TestBase {

    @Override
    protected String getDescription() {
        return "This test case contains 5 tables in various configurations. All tables have a pageLength of "
                + PAGELENGTH
                + " and thus should show as many rows without any scrollbars (height is undefined for all tables).";

    }

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

    private static final int PAGELENGTH = 2;

    @Override
    public void setup() {
        Table table1 = initTable(PAGELENGTH, false, false, false);
        addComponent(new Label("Plain table"));
        addComponent(table1);

        Table table2 = initTable(PAGELENGTH, true, false, false);
        addComponent(new Label("Table with label component in generated column"));
        addComponent(table2);

        Table table3 = initTable(PAGELENGTH, false, true, false);
        addComponent(new Label(
                "Table with layout component in generated column"));
        addComponent(table3);

        Table table4 = initTable(PAGELENGTH, true, true, false);
        addComponent(new Label(
                "Table with both label and layout component in generated column"));
        addComponent(table4);

        Table table5 = initTable(PAGELENGTH, false, false, true);
        addComponent(new Label("Table with label horizontal scrollbar"));
        addComponent(table5);

    }

    private Table initTable(int pageLength, boolean addLabelColGen,
            boolean addLayoutColGen, boolean fixedColWidths) {
        Table table = new Table();
        table.setWidth("100%");
        table.setPageLength(pageLength);

        IndexedContainer idx = new IndexedContainer();
        idx.addContainerProperty("firstname", String.class, null);
        idx.addContainerProperty("lastname", String.class, null);
        Item i = idx.addItem(1);
        i.getItemProperty("firstname").setValue("John");
        i.getItemProperty("lastname").setValue("Johnson");
        i = idx.addItem(2);
        i.getItemProperty("firstname").setValue("Jane");
        i.getItemProperty("lastname").setValue("Janeine");

        table.setContainerDataSource(idx);

        table.setColumnHeader("firstname", "FirstName");
        table.setColumnHeader("lastname", "LastName");
        if (addLabelColGen) {
            table.addGeneratedColumn("name1", new LabelColumnGenerator());
        }
        if (addLayoutColGen) {
            table.addGeneratedColumn("name2", new LayoutColumnGenerator());
        }
        if (fixedColWidths) {
            table.setWidth("400px");
            table.setColumnWidth("firstname", 200);
            table.setColumnWidth("lastname", 300);
        }

        return table;
    }

    public class LabelColumnGenerator implements ColumnGenerator {

        @Override
        public Component generateCell(Table source, Object itemId,
                Object columnId) {
            Item item = source.getItem(itemId);
            String firstname = (String) item.getItemProperty("firstname")
                    .getValue();
            String lastname = (String) item.getItemProperty("lastname")
                    .getValue();
            Label label = new Label(firstname + " " + lastname);
            return label;
        }

    }

    public class LayoutColumnGenerator implements ColumnGenerator {

        @Override
        public Component generateCell(Table source, Object itemId,
                Object columnId) {
            Item item = source.getItem(itemId);
            GridLayout layout = new GridLayout(1, 2);
            String firstname = (String) item.getItemProperty("firstname")
                    .getValue();
            String lastname = (String) item.getItemProperty("lastname")
                    .getValue();
            layout.addComponent(new Label(firstname), 0, 0);
            layout.addComponent(new Label(lastname), 0, 1);
            return layout;
        }

    }

}