aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/elements/TestBenchElementRightClick.java
blob: bb26e5ecb284f3d213b521cb188b7e38192af55b (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
package com.vaadin.tests.elements;

import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.MouseEventDetails.MouseButton;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.Label;
import com.vaadin.v7.ui.Table;

public class TestBenchElementRightClick extends AbstractTestUI {

    Table table = new Table();
    Label labelEvent = new Label();
    private int COLUMNS = 4;
    private int ROWS = 10;

    @Override
    protected void setup(VaadinRequest request) {
        labelEvent.setId("label1");
        table.setId("id1");
        fillTable(table);
        addComponent(table);
        addComponent(labelEvent);
        labelEvent.setValue("InitialValue");
        table.addItemClickListener(event -> {
            if (event.getButton().equals(MouseButton.RIGHT)) {
                labelEvent.setValue("RightClick");
            } else if (event.isDoubleClick()) {
                labelEvent.setValue("DoubleClick");
            }
        });
    }

    @Override
    protected String getTestDescription() {
        return "Test double click and right click on TestBenchElement";
    }

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

    // set up the properties (columns)
    private void initProperties(Table table) {
        for (int i = 0; i < COLUMNS; i++) {
            table.addContainerProperty("property" + i, String.class,
                    "some value");
        }
    }

    // fill the table with some random data
    private void fillTable(Table table) {
        initProperties(table);
        for (int i = 0; i < ROWS; i++) {
            String[] line = new String[COLUMNS];
            for (int j = 0; j < COLUMNS; j++) {
                line[j] = "col=" + j + " row=" + i;
            }
            table.addItem(line, null);
        }
    }
}