aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/components/textfield/CompatibilityTextFieldShortcut.java
blob: 9ad6fbd264958d678c113cbbf8de03fec353ae46 (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
package com.vaadin.tests.components.textfield;

import com.vaadin.event.ShortcutAction;
import com.vaadin.event.ShortcutListener;
import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.Registration;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.v7.ui.TextField;

@SuppressWarnings("deprecation")
public class CompatibilityTextFieldShortcut extends AbstractTestUI {

    Registration listenerRegistration;

    @Override
    protected void setup(VaadinRequest request) {
        TextField textField = new TextField("F8 shortcut when focused");
        ShortcutListener c = new ShortcutListener("ShortcutForMAMedRemarks",
                ShortcutAction.KeyCode.F8, null) {

            @Override
            public void handleAction(Object sender, Object target) {
                Notification.show("Received F8: " + textField.getValue());
            }
        };

        textField.addFocusListener(e -> {
            listenerRegistration = textField.addShortcutListener(c);
            Label label = new Label("Focused");
            label.addStyleName("focus-label");
            addComponent(label);
        });

        textField.addBlurListener(e -> {
            listenerRegistration.remove();
        });

        Label label = new Label(
                "F8 will have an effect only if the following component is focused.");
        Button button = new Button("focus");
        button.addClickListener(event -> {
            textField.focus();
        });
        addComponents(label, textField, button);
    }
}