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

import com.vaadin.annotations.Widgetset;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.Button;
import com.vaadin.ui.TextField;

@Widgetset("com.vaadin.DefaultWidgetSet")
public class TextFieldTestCursorPosition extends AbstractTestUI {

    static final String DEFAULT_TEXT = "So we have some text to select";
    static final String BUTTON_SETPOSITION = "buttonPos";
    static final String BUTTON_SETRANGE = "rS";
    static final String RANGE_LENGTH_TF = "rLTF";
    static final String CURSOR_POS_TF = "cpTF";
    static final int valueLength = DEFAULT_TEXT.length();
    final TextField textField = new TextField(
            "Set cursor position after the last character");
    final TextField textField1 = new TextField("Set Selection range");

    @Override
    protected void setup(VaadinRequest request) {
        textField.setValue(DEFAULT_TEXT);
        textField.setId(CURSOR_POS_TF);
        textField.setWidth("500px");

        Button posButton = new Button("Set Position to the last character");
        posButton.setId(BUTTON_SETPOSITION);
        posButton.addClickListener(
                c -> textField.setCursorPosition(valueLength));
        addComponent(textField);
        addComponent(posButton);

        textField1.setId(RANGE_LENGTH_TF);
        textField1.setValue(DEFAULT_TEXT);
        textField1.setWidth("500px");

        Button selButton = new Button("Set selection range");
        selButton.setId(BUTTON_SETRANGE);
        selButton.addClickListener(
                c -> textField1.setSelection(valueLength / 2, valueLength));
        addComponent(textField1);
        addComponent(selButton);
    }
}