aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/components/table/TabletContextMenu.java
blob: e813150a069abc17fda286a67b022764850cdb98 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package com.vaadin.tests.components.table;

import com.vaadin.event.Action;
import com.vaadin.event.Action.Handler;
import com.vaadin.event.ShortcutAction;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractReindeerTestUI;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.v7.ui.Table;

/**
 * A test UI for context menus on different parts of a VSCrollTable.
 *
 * This UI has no attached unit test due to the poor support of touch events on
 * Selenium.
 *
 * @author Vaadin Ltd
 */
public class TabletContextMenu extends AbstractReindeerTestUI {

    /*
     * (non-Javadoc)
     *
     * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server.
     * VaadinRequest)
     */
    @Override
    protected void setup(VaadinRequest request) {
        setSizeFull();

        HorizontalLayout layout = new HorizontalLayout();
        layout.setSizeFull();
        layout.setSpacing(true);
        addComponent(layout);

        Table table1 = createTable("no scrolling, has context menu");
        addActionHandler(table1);
        table1.addItem();
        layout.addComponent(table1);

        Table table2 = createTable("should scroll, has context menu");
        for (int i = 0; i < 100; ++i) {
            table2.addItem();
        }
        addActionHandler(table2);
        layout.addComponent(table2);

        Table table3 = createTable("no scrolling, no context menu");
        table3.addItem();
        layout.addComponent(table3);

        Table table4 = createTable("should scroll, no context menu");
        for (int i = 0; i < 100; ++i) {
            table4.addItem();
        }
        layout.addComponent(table4);
    }

    private Table createTable(String caption) {
        Table table = new Table(caption);
        table.setImmediate(true);

        table.addContainerProperty("column1", String.class, "test");
        table.setSizeFull();
        table.setHeight("500px");
        table.setSelectable(true);

        return table;
    }

    private void addActionHandler(Table table) {
        table.addActionHandler(new Handler() {

            Action tabNext = new ShortcutAction("Shift",
                    ShortcutAction.KeyCode.TAB, null);
            Action tabPrev = new ShortcutAction("Shift+Tab",
                    ShortcutAction.KeyCode.TAB,
                    new int[] { ShortcutAction.ModifierKey.SHIFT });
            Action curDown = new ShortcutAction("Down",
                    ShortcutAction.KeyCode.ARROW_DOWN, null);
            Action curUp = new ShortcutAction("Up",
                    ShortcutAction.KeyCode.ARROW_UP, null);
            Action enter = new ShortcutAction("Enter",
                    ShortcutAction.KeyCode.ENTER, null);
            Action add = new ShortcutAction("Add Below",
                    ShortcutAction.KeyCode.A, null);
            Action delete = new ShortcutAction("Delete",
                    ShortcutAction.KeyCode.DELETE, null);

            @Override
            public void handleAction(Action action, Object sender,
                    Object target) {
                System.out.println(action.getCaption());
            }

            @Override
            public Action[] getActions(Object target, Object sender) {
                return new Action[] { tabNext, tabPrev, curDown, curUp, enter,
                        add, delete };
            }
        });
    }

    /*
     * (non-Javadoc)
     *
     * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
     */
    @Override
    protected String getTestDescription() {
        return "Make sure empty table parts have context menu on touch screen devices";
    }

    /*
     * (non-Javadoc)
     *
     * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber()
     */
    @Override
    protected Integer getTicketNumber() {
        return 13694;
    }

}