aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/tickets/Ticket2431.java
blob: 5654a062ddd97b09b1c9511ffefd307183e0f52c (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
package com.vaadin.tests.tickets;

import com.vaadin.LegacyApplication;
import com.vaadin.event.Action;
import com.vaadin.event.Action.Handler;
import com.vaadin.event.ShortcutAction;
import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.event.ShortcutAction.ModifierKey;
import com.vaadin.ui.Label;
import com.vaadin.ui.LegacyWindow;

public class Ticket2431 extends LegacyApplication {

    @Override
    public void init() {

        LegacyWindow w = new LegacyWindow();
        setMainWindow(w);
        Label help = new Label(
                "Use CTRL X to fire action, CTRL C to remove it (fails before fix)");

        w.addComponent(help);

        w.addActionHandler(new Handler() {

            final ShortcutAction a1 = new ShortcutAction("action", KeyCode.X,
                    new int[] { ModifierKey.CTRL });
            final ShortcutAction a2 = new ShortcutAction("action", KeyCode.C,
                    new int[] { ModifierKey.CTRL });

            Action[] actions = new Action[] { a1, a2 };

            @Override
            public Action[] getActions(Object target, Object sender) {
                return actions;
            }

            @Override
            public void handleAction(Action action, Object sender, Object target) {
                if (action == a1) {
                    getMainWindow().addComponent(new Label("CTRL X hit"));
                } else {
                    actions = new Action[] { a2 };
                    // annoyance, we need to repaint the panel or detect the
                    // action in presence in handler
                    getMainWindow().removeActionHandler(this);
                    getMainWindow().addActionHandler(this);
                }
            }
        });

    }

}