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

import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.util.Log;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.v7.ui.TextField;

public class TextFieldInputPromptAndClickShortcut extends TestBase {

    @Override
    protected void setup() {
        final Log log = new Log(5);

        final TextField textField = new TextField();
        Button button = new Button("Show Text",
                event -> log.log("Field value: " + textField.getValue()));
        button.setClickShortcut(KeyCode.ESCAPE);

        final CheckBox inputPromptSelection = new CheckBox("Input prompt");
        inputPromptSelection.addValueChangeListener(event -> {
            if (event.getValue()) {
                textField.setInputPrompt("Input prompt");
            } else {
                textField.setInputPrompt(null);
            }
            log.log("Set input prompt: " + textField.getInputPrompt());
        });

        addComponent(textField);
        addComponent(button);
        addComponent(inputPromptSelection);
        addComponent(log);
    }

    @Override
    protected String getDescription() {
        return "With the input propmpt enabled, enter something into the field, press enter, remove the entered text and press the button. The previous text is still reported as the value. Without the input prompt, the new value is instead reported as blank.";
    }

    @Override
    protected Integer getTicketNumber() {
        // TODO Auto-generated method stub
        return null;
    }

}