aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/textfield/EnterShortcutMaySendInputPromptAsValue.java
blob: 938ecf60ce576f66cf9a85610a460b6134675e69 (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
package com.vaadin.tests.components.textfield;

import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.event.Action;
import com.vaadin.event.ShortcutAction;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;

public class EnterShortcutMaySendInputPromptAsValue extends TestBase {

    @Override
    protected String getDescription() {
        return "?";
    }

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

    @Override
    protected void setup() {

        final TextField testField = new TextField();
        testField.setInputPrompt("Enter a value");

        getMainWindow().addActionHandler(new Action.Handler() {

            final Action enter = new ShortcutAction("enter",
                    ShortcutAction.KeyCode.ENTER, null);

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

            @Override
            public void handleAction(Action action, Object sender, Object target) {
                if (action == enter) {

                }
            }

        });
        testField.addListener(new ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                String value = event.getProperty().getValue().toString();
                addComponent(new Label("TextField sent value: " + value));
                testField.setValue("");
            }
        });

        addComponent(testField);

    }

}