aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/components/table/RowUpdateShouldRetainContextMenu.java
blob: 03eeb7048fb802a32a8d1dd21997015a95898ced (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.event.Action;
import com.vaadin.tests.components.TestBase;
import com.vaadin.v7.ui.ProgressIndicator;
import com.vaadin.v7.ui.Table;

public class RowUpdateShouldRetainContextMenu extends TestBase {

    private ProgressIndicator indicator = new ProgressIndicator();
    private Table table = new Table();

    private int ctr = 0;

    @Override
    protected void setup() {
        indicator.setWidth("200px");
        indicator.addValueChangeListener(event -> {
            // Do some changes to the table
            table.setColumnHeader("Column", "Column " + ctr);
            table.getItem(2).getItemProperty("Column")
                    .setValue("Test " + ctr++);
        });
        Thread updater = new Thread() {
            private float progress = 0;

            @Override
            public void run() {
                while (true) {
                    try {
                        sleep(1000);
                    } catch (InterruptedException ie) {
                    }
                    getContext().lock();
                    try {
                        indicator.setValue(progress += 0.01);
                    } finally {
                        getContext().unlock();
                    }
                }
            }
        };
        updater.start();

        addComponent(indicator);

        table.setWidth("200px");
        table.setHeight("200px");

        table.addActionHandler(new Action.Handler() {
            @Override
            public void handleAction(Action action, Object sender,
                    Object target) {
            }

            @Override
            public Action[] getActions(Object target, Object sender) {
                return new Action[] { new Action("Action 1"),
                        new Action("Action 2"), };
            }
        });

        table.addContainerProperty("Column", String.class, "");

        table.addItem();
        for (int i = 0; i < 15; ++i) {
            table.addItem(new String[] { "Row " + ctr++, }, ctr);
        }

        addComponent(table);
    }

    @Override
    protected String getDescription() {
        return "Open context menu is closed if a row is updated via e.g. server push";
    }

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

}