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

import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Layout;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.v7.ui.Table;

public class ScrollDetachSynchronization extends TestBase {

    @Override
    public void setup() {
        getMainWindow().setContent(buildLayout());
    }

    @Override
    protected String getDescription() {
        return "Scrolling, then detaching, a table causes out of sync on IE";
    }

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

    private Layout buildLayout() {
        final VerticalLayout mainLayout = new VerticalLayout();
        mainLayout.setSizeFull();

        HorizontalLayout buttonBar = new HorizontalLayout();
        buttonBar.setSizeUndefined();
        Button first = new Button("First layout");
        Button second = new Button("Second layout");
        first.setId("FirstButton");
        second.setId("SecondButton");
        buttonBar.addComponent(first);
        buttonBar.addComponent(second);
        mainLayout.addComponent(buttonBar);

        final HorizontalLayout firstLayout = buildTestLayout(true);
        final HorizontalLayout secondLayout = buildTestLayout(false);

        mainLayout.addComponent(firstLayout);
        mainLayout.setExpandRatio(firstLayout, 1);

        first.addClickListener(event -> {
            if (mainLayout.getComponent(1).equals(secondLayout)) {
                mainLayout.replaceComponent(secondLayout, firstLayout);
                mainLayout.setExpandRatio(firstLayout, 1);
            }
        });
        second.addClickListener(event -> {
            if (mainLayout.getComponent(1).equals(firstLayout)) {
                mainLayout.replaceComponent(firstLayout, secondLayout);
                mainLayout.setExpandRatio(secondLayout, 1);
            }
        });
        return mainLayout;
    }

    private HorizontalLayout buildTestLayout(boolean first) {
        String which = first ? "First" : "Second";

        HorizontalLayout hl = new HorizontalLayout();
        hl.setSizeFull();
        hl.setId(which + "Layout");

        Table t = new Table();
        t.addContainerProperty("name", String.class, null);
        for (int i = 0; i < 10; i++) {
            String id = which + " " + i;
            t.addItem(new String[] { id }, id);
        }
        t.setId(which + "Table");
        t.setItemCaptionPropertyId("name");
        t.setSizeFull();

        hl.addComponent(t);

        return hl;
    }
}