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

import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.v7.data.util.IndexedContainer;
import com.vaadin.v7.ui.Table;

@SuppressWarnings("serial")
public class ModifyContainerProperty extends TestBase {

    private Table table = new Table();
    private IndexedContainer ic = new IndexedContainer();

    @Override
    protected void setup() {
        addComponent(table);

        ic.addContainerProperty("one", String.class, "one");
        ic.addContainerProperty("two", String.class, "two");

        ic.addItem("foo");

        ic.getContainerProperty("foo", "one").setValue("bar");
        ic.getContainerProperty("foo", "two").setValue("baz");

        table.setContainerDataSource(ic);
        addComponent(new Button("Remove container property",
                event -> ic.removeContainerProperty("one")));
        addComponent(new Button("Add container property", event -> {
            boolean added = ic.addContainerProperty("three", String.class,
                    "three");
            if (added) {
                Object[] current = table.getVisibleColumns();
                Object[] vis = new Object[current.length + 1];
                for (int i = 0; i < current.length; i++) {
                    vis[i] = current[i];
                }
                vis[current.length] = "three";
                table.setVisibleColumns(vis);
            }
        }));
    }

    @Override
    protected String getDescription() {
        return "Clicking on \"Add container property\" adds a property to the container and sets it visible. The table should then show a \"three\" column in addition to the others. Clicking on \"Remove container property\" should remove column \"two\" from the table.";
    }

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