aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldPopupClosingOnDetach.java
blob: 76dc416dd4f9dd8cb8b1505e2f3b193fda0ec08d (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.datefield;

import java.util.Timer;
import java.util.TimerTask;

import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractReindeerTestUI;
import com.vaadin.tests.components.TestDateField;
import com.vaadin.ui.AbstractLocalDateField;

public class DateFieldPopupClosingOnDetach extends AbstractReindeerTestUI {

    @Override
    protected void setup(VaadinRequest request) {
        // Use polling to notice the removal of DateField.
        getUI().setPollInterval(500);

        final AbstractLocalDateField df = new TestDateField();
        getLayout().addLayoutClickListener(event -> {
            // Use a background Thread to remove the DateField 1 second
            // after being clicked.
            TimerTask removeTask = new TimerTask() {

                @Override
                public void run() {
                    getUI().access(() -> removeComponent(df));
                }
            };
            new Timer(true).schedule(removeTask, 1000);
        });

        addComponent(df);
    }

    @Override
    protected String getTestDescription() {
        return "DateField popup should be removed if it's open while the DateField is removed. "
                + "Click the popup open and a background Thread will remove the DateField after 1 second.";
    }

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

}