summaryrefslogtreecommitdiffstats
path: root/tests/testbench/com/vaadin/tests/tickets/Ticket2208.java
blob: f622f093ee2e1bfd713cfcc043ab7a3353fccfc1 (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
package com.vaadin.tests.tickets;

import com.vaadin.Application;
import com.vaadin.data.Item;
import com.vaadin.ui.Component;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI.LegacyWindow;
import com.vaadin.ui.Table;
import com.vaadin.ui.Table.CellStyleGenerator;
import com.vaadin.ui.Table.ColumnGenerator;

public class Ticket2208 extends Application.LegacyApplication {

    private Table t;

    @Override
    public void init() {
        LegacyWindow mainWindow = new LegacyWindow();
        setMainWindow(mainWindow);

        t = new Table("A table");
        t.addContainerProperty("col 1 (red)", String.class, "");
        t.addContainerProperty("col 2", String.class, "");

        t.setHeight("150px");
        t.addGeneratedColumn("col 3 (green)", new ColumnGenerator() {

            @Override
            public Component generateCell(Table source, Object itemId,
                    Object columnId) {
                Item item = source.getItem(itemId);
                String col1 = (String) item.getItemProperty("col 1 (red)")
                        .getValue();
                String col2 = (String) item.getItemProperty("col 2").getValue();
                return new Label(col1 + "-" + col2);
            }
        });

        t.addContainerProperty("col 4", String.class, "");
        t.setCellStyleGenerator(new CellStyleGenerator() {

            @Override
            public String getStyle(Object itemId, Object propertyId) {
                if ("col 1 (red)".equals(propertyId)) {
                    return "red";
                }

                if ("col 3 (green)".equals(propertyId)) {
                    return "green";
                }

                return null;
            }
        });

        t.addItem(new Object[] { "Col 1-1", "Col 2-1", "Col 4-1" },
                new Object());
        t.addItem(new Object[] { "Col 1-2", "Col 2-2", "Col 4-2" },
                new Object());
        t.addItem(new Object[] { "Col 1-3", "Col 2-3", "Col 4-3" },
                new Object());

        t.setColumnReorderingAllowed(true);
        t.setColumnCollapsingAllowed(true);
        setTheme("tests-tickets");
        mainWindow.addComponent(t);

    }

}