2 * Copyright 2000-2018 Vaadin Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
16 package com.vaadin.v7.ui.components.calendar.handler;
18 import java.util.Calendar;
19 import java.util.Date;
20 import java.util.GregorianCalendar;
22 import com.vaadin.v7.ui.components.calendar.CalendarComponentEvents.WeekClick;
23 import com.vaadin.v7.ui.components.calendar.CalendarComponentEvents.WeekClickHandler;
26 * Implements basic functionality needed to change to week view when a week
32 @SuppressWarnings("serial")
34 public class BasicWeekClickHandler implements WeekClickHandler {
40 * com.vaadin.addon.calendar.ui.CalendarComponentEvents.WeekClickHandler
42 * (com.vaadin.addon.calendar.ui.CalendarComponentEvents.WeekClick)
45 public void weekClick(WeekClick event) {
46 int week = event.getWeek();
47 int year = event.getYear();
49 // set correct year and month
50 Calendar javaCalendar = event.getComponent().getInternalCalendar();
51 javaCalendar.set(GregorianCalendar.YEAR, year);
52 javaCalendar.set(GregorianCalendar.WEEK_OF_YEAR, week);
54 // starting at the beginning of the week
55 javaCalendar.set(GregorianCalendar.DAY_OF_WEEK,
56 javaCalendar.getFirstDayOfWeek());
57 Date start = javaCalendar.getTime();
59 // ending at the end of the week
60 javaCalendar.add(GregorianCalendar.DATE, 6);
61 Date end = javaCalendar.getTime();
63 setDates(event, start, end);
65 // times are automatically expanded, no need to worry about them
69 * Set the start and end dates for the event.
72 * The event that the start and end dates should be set
78 protected void setDates(WeekClick event, Date start, Date end) {
79 event.getComponent().setStartDate(start);
80 event.getComponent().setEndDate(end);