aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/components/window/OpenModalWindowAndFocusField.java
blob: ee86fa91c925a096c5c9559b9d8664cefb001676 (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
package com.vaadin.tests.components.window;

import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUIWithLog;
import com.vaadin.ui.Button;
import com.vaadin.ui.Window;
import com.vaadin.v7.ui.TextArea;

public class OpenModalWindowAndFocusField extends AbstractTestUIWithLog {

    @Override
    protected void setup(VaadinRequest request) {
        Button button = new Button("Open modal and focus textarea");
        button.setId("openFocus");
        button.addClickListener(event -> open(true));
        addComponent(button);

        button = new Button("Only open modal");
        button.setId("open");
        button.addClickListener(event -> open(false));
        addComponent(button);
    }

    private void open(boolean focus) {
        Window wind = new Window();
        wind.setModal(true);
        TextArea ta = new TextArea();
        wind.setContent(ta);
        addWindow(wind);
        if (focus) {
            ta.focus();
        }
    }
}