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

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

public class ContainerChangeWithPartlySamePropertyIds extends TestBase {

    @Override
    protected void setup() {
        getLayout().addComponent(new TableTestComponent());
    }

    @Override
    protected String getDescription() {
        return "The client side Table component messes up its internal "
                + "data structures (in header and footer) if the container changes and it has partly"
                + " the same properties (but in different order) than the old container.";
    }

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

    public static class TableTestComponent extends VerticalLayout {

        final TableTestComponent me = this;

        Table testTable;
        IndexedContainer containerA;
        IndexedContainer containerB;

        String property1 = "property1";
        String property2 = "property2";
        String property3 = "property3";
        String property4 = "property4";

        private void createContainers() {

            containerA = new IndexedContainer();
            containerA.addContainerProperty(property1, String.class, "");
            containerA.addContainerProperty(property2, String.class, "");
            containerA.addContainerProperty(property3, String.class, "");

            Item itemA = containerA.addItem(new Object());
            itemA.getItemProperty(property1).setValue("value1");
            itemA.getItemProperty(property2).setValue("value2");
            itemA.getItemProperty(property3).setValue("value3");

            containerB = new IndexedContainer();
            containerB.addContainerProperty(property4, String.class, "");
            containerB.addContainerProperty(property3, String.class, "");
            containerB.addContainerProperty(property2, String.class, "");

            Item itemB = containerB.addItem(new Object());
            itemB.getItemProperty(property4).setValue("value_prop4");
            itemB.getItemProperty(property3).setValue("value_prop3");
            itemB.getItemProperty(property2).setValue("value_prop2");
        }

        public TableTestComponent() {

            Button switchContainerButton = new Button("switch container");
            switchContainerButton.addClickListener(event -> {
                if (testTable.getContainerDataSource() == containerA) {
                    testTable.setContainerDataSource(containerB);
                } else {
                    testTable.setContainerDataSource(containerA);
                }
            });
            this.addComponent(switchContainerButton);

            Button clearButton = new Button("clear (click twice)");
            clearButton.addClickListener(event -> {
                try {
                    me.removeComponent(testTable);

                    testTable = new Table();
                    createContainers();
                    testTable.setContainerDataSource(containerA);

                    me.addComponent(testTable);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
            this.addComponent(clearButton);

            testTable = new Table();
            this.addComponent(testTable);

            createContainers();
            testTable.setContainerDataSource(containerA);
        }
    }

}