/* * Copyright 2000-2016 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.vaadin.tests.components.calendar; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Locale; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUIWithLog; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.GridLayout; import com.vaadin.ui.Notification; import com.vaadin.v7.ui.Calendar; import com.vaadin.v7.ui.components.calendar.CalendarComponentEvents.DateClickEvent; import com.vaadin.v7.ui.components.calendar.CalendarComponentEvents.DateClickHandler; import com.vaadin.v7.ui.components.calendar.event.BasicEvent; import com.vaadin.v7.ui.components.calendar.event.CalendarEvent; import com.vaadin.v7.ui.components.calendar.event.CalendarEventProvider; public class CalendarNotifications extends AbstractTestUIWithLog { private DummyEventProvider provider; private static class DummyEventProvider implements CalendarEventProvider { private int index; private List<CalendarEvent> events = new ArrayList<>(); public void addEvent(Date date) { BasicEvent e = new BasicEvent(); e.setAllDay(true); e.setStart(date); e.setEnd(date); e.setCaption("Some event " + ++index); events.add(e); } @Override public List<CalendarEvent> getEvents(Date startDate, Date endDate) { return events; } } @Override protected void setup(VaadinRequest request) { GridLayout content = new GridLayout(1, 2); content.setSizeFull(); content.setRowExpandRatio(1, 1.0f); addComponent(content); final Button btn = new Button("Show working notification", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { Notification.show( "This will disappear when you move your mouse!"); } }); content.addComponent(btn); provider = new DummyEventProvider(); final Calendar cal = new Calendar(provider); cal.setLocale(Locale.US); cal.setSizeFull(); cal.setHandler(new DateClickHandler() { @Override public void dateClick(DateClickEvent event) { provider.addEvent(event.getDate()); log("Opening a notification"); Notification .show("This should disappear when the mouse is moved."); // this requestRepaint call interferes with the notification cal.markAsDirty(); } }); content.addComponent(cal); java.util.Calendar javaCal = java.util.Calendar.getInstance(); javaCal.set(java.util.Calendar.YEAR, 2000); javaCal.set(java.util.Calendar.MONTH, 0); javaCal.set(java.util.Calendar.DAY_OF_MONTH, 1); Date start = javaCal.getTime(); javaCal.set(java.util.Calendar.DAY_OF_MONTH, 31); Date end = javaCal.getTime(); cal.setStartDate(start); cal.setEndDate(end); } @Override protected String getTestDescription() { return "Notifications should be opened and then closed after the user has moved the mouse."; } @Override protected Integer getTicketNumber() { return 6769; } }