aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/datefield/DynamicallyChangeDateRange.java
blob: fb0fb2a5463bad08c85c366442c251ea7dbdd631 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.vaadin.tests.components.datefield;

import java.util.Date;
import java.util.Locale;

import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.DateField;
import com.vaadin.ui.InlineDateField;
import com.vaadin.ui.PopupDateField;
import com.vaadin.ui.VerticalLayout;

/**
 * Main UI class
 */
@SuppressWarnings("serial")
public class DynamicallyChangeDateRange extends AbstractTestUI {

    @Override
    protected void setup(VaadinRequest request) {
        setLocale(Locale.ENGLISH);
        final VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        setContent(layout);

        final PopupDateField df = new PopupDateField();
        df.setValue(new Date(2012 - 1900, 5 - 1, 12));
        setRange(df, 5);
        layout.addComponent(df);

        final InlineDateField df2 = new InlineDateField();
        df2.setValue(new Date(2012 - 1900, 11 - 1, 16));

        setRange(df2, 5);
        // layout.addComponent(df2);

        Button button1 = new Button("Set Range Now+/-5d");
        button1.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                setRange(df, 5);
                setRange(df2, 5);
            }
        });
        layout.addComponent(button1);

        Button button2 = new Button("Set Range Now+/-10d");
        button2.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                setRange(df, 10);
                setRange(df2, 10);
            }
        });
        layout.addComponent(button2);
    }

    /**
     * @since
     * @param df
     * @param i
     */
    private void setRange(DateField df, int days) {
        df.setRangeStart(new Date(df.getValue().getTime() - days * 24 * 60 * 60
                * 1000));
        df.setRangeEnd(new Date(df.getValue().getTime() + days * 24 * 60 * 60
                * 1000));

    }

    /*
     * (non-Javadoc)
     * 
     * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
     */
    @Override
    protected String getTestDescription() {
        return "Verifies that the allowed date range can be updated dynamically";
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber()
     */
    @Override
    protected Integer getTicketNumber() {
        return 11940;
    }

}