aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/textfield/MultipleTextChangeEvents.java
blob: 24feab5cab80ed60b144d34a772bd278f8f2cb33 (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.event.Action;
import com.vaadin.event.Action.Handler;
import com.vaadin.event.FieldEvents.TextChangeEvent;
import com.vaadin.event.FieldEvents.TextChangeListener;
import com.vaadin.event.ShortcutAction;
import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.util.Log;
import com.vaadin.ui.AbstractTextField.TextChangeEventMode;
import com.vaadin.ui.TextField;

public class MultipleTextChangeEvents extends TestBase {

    private final Log log = new Log(5);

    @Override
    public void setup() {
        TextField tf = new TextField();
        tf.setTextChangeEventMode(TextChangeEventMode.TIMEOUT);
        tf.setTextChangeTimeout(500);
        tf.addListener(new TextChangeListener() {
            @Override
            public void textChange(TextChangeEvent event) {
                log.log("TextChangeEvent: " + event.getText());
            }
        });
        getMainWindow().addActionHandler(new MyHandler());

        addComponent(log);
        addComponent(tf);
    }

    class MyHandler implements Handler {
        private static final long serialVersionUID = 1L;
        Action actionenter = new ShortcutAction("Enter",
                ShortcutAction.KeyCode.ENTER, null);

        @Override
        public Action[] getActions(Object theTarget, Object theSender) {
            return new Action[] { actionenter };
        }

        @Override
        public void handleAction(Action theAction, Object theSender,
                Object theTarget) {
            log.log("Enter");
        }
    }

    @Override
    protected String getDescription() {
        return "Entering something into the textfield and quickly pressing enter should only send one TextChangeEvent";
    }

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