aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/button/ButtonEnterWithWindowShortcut.java
blob: 0d4981a441a1cd7f855f83171610b29b77f7aee9 (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
package com.vaadin.tests.components.button;

import com.vaadin.event.Action;
import com.vaadin.event.Action.Handler;
import com.vaadin.event.ShortcutAction;
import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.util.Log;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;

public class ButtonEnterWithWindowShortcut extends TestBase {
    Log log = new Log(5);

    @Override
    protected void setup() {
        getMainWindow().addActionHandler(new Handler() {
            private static final long serialVersionUID = -4976129418325394913L;

            @Override
            public void handleAction(Action action, Object sender, Object target) {
                log.log(action.getCaption() + " pressed in window");
            }

            @Override
            public Action[] getActions(Object target, Object sender) {
                ShortcutAction enter = new ShortcutAction("enter",
                        ShortcutAction.KeyCode.ENTER, null);
                ShortcutAction space = new ShortcutAction("space",
                        ShortcutAction.KeyCode.SPACEBAR, null);
                return new Action[] { enter, space };
            }
        });

        Button button = new Button("Focus me and press enter",
                new ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        log.log("button click listener fired");
                    }
                });
        button.focus();

        addComponent(log);
        addComponent(button);
    }

    @Override
    protected String getDescription() {
        return "Pressing enter or space with the button focused should trigger the button click listener and not the shortcut action on the window.";
    }

    @Override
    protected Integer getTicketNumber() {
        return Integer.valueOf(5433);
    }

}