aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/calendar/TestHideTimeAndSeparator.java
blob: 60e8720d4414ce58f778b4a6c0e97e79796d0886 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package com.vaadin.tests.components.calendar;

import com.vaadin.annotations.Theme;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.Calendar;
import com.vaadin.ui.components.calendar.event.CalendarEvent;
import com.vaadin.ui.components.calendar.event.CalendarEventProvider;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;

@Theme("tests-calendar")
public class TestHideTimeAndSeparator extends AbstractTestUI {

    class GenericEvent implements CalendarEvent {
        private final Date start;
        private final Date end;
        private final String caption;
        private final boolean hideTime;

        public GenericEvent(Date start, Date end, String caption,
                boolean hideTime) {
            this.start = start;
            this.end = end;
            this.caption = caption;
            this.hideTime = hideTime;
        }

        @Override
        public Date getStart() {
            return start;
        }

        @Override
        public Date getEnd() {
            return end;
        }

        @Override
        public String getCaption() {
            return caption;
        }

        @Override
        public String getDescription() {
            return "This is a " + caption;
        }

        @Override
        public String getStyleName() {
            return hideTime ? "hide-time" : null;
        }

        @Override
        public boolean isAllDay() {
            return false;
        }

    }

    CalendarEvent shortEventHidden = new GenericEvent(
            makeDate(2013, 1, 2, 8, 0), makeDate(2013, 1, 2, 8, 30),
            "Short event", true);
    CalendarEvent longEventHidden = new GenericEvent(
            makeDate(2013, 1, 2, 10, 0), makeDate(2013, 1, 2, 12, 0),
            "Long event", true);
    CalendarEvent shortEvent = new GenericEvent(makeDate(2013, 1, 3, 8, 0),
            makeDate(2013, 1, 3, 8, 30), "Short event", false);
    CalendarEvent longEvent = new GenericEvent(makeDate(2013, 1, 3, 10, 0),
            makeDate(2013, 1, 3, 12, 0), "Long event", false);

    @Override
    protected void setup(VaadinRequest request) {
        Calendar cal = new Calendar();
        cal.setWidth("100%");
        cal.setHeight("500px");

        cal.setLocale(Locale.US);

        cal.addEvent(shortEventHidden);
        cal.addEvent(longEventHidden);
        cal.addEvent(shortEvent);
        cal.addEvent(longEvent);

        cal.setStartDate(makeDate(2013, 1, 1));
        cal.setEndDate(makeDate(2013, 1, 7));
        cal.setFirstVisibleHourOfDay(7);

        addComponent(cal);
    }

    @Override
    protected String getTestDescription() {
        return "The time should be hideable by CSS";
    }

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

    private Date makeDate(int year, int month, int day, int hour, int minute) {
        java.util.Calendar juc = java.util.Calendar.getInstance();
        juc.set(year, month, day, hour, minute);
        return juc.getTime();
    }

    private Date makeDate(int year, int month, int day) {
        java.util.Calendar juc = java.util.Calendar.getInstance();
        juc.set(year, month, day);
        return juc.getTime();
    }
}