All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vaadin.v7.ui.components.calendar.event.BasicEventProvider Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2000-2024 Vaadin Ltd
 *
 * This program is available under Vaadin Commercial License and Service Terms.
 *
 * See  for the full
 * license.
 */
package com.vaadin.v7.ui.components.calendar.event;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.vaadin.v7.ui.components.calendar.event.CalendarEvent.EventChangeEvent;
import com.vaadin.v7.ui.components.calendar.event.CalendarEvent.EventChangeListener;
import com.vaadin.v7.ui.components.calendar.event.CalendarEventProvider.EventSetChangeNotifier;

/**
 * 

* Simple implementation of * {@link CalendarEventProvider}. Use {@link #addEvent(CalendarEvent)} and * {@link #removeEvent(CalendarEvent)} to add / remove events. *

* *

* {@link EventSetChangeNotifier} and {@link EventChangeListener} * EventChangeListener} are also implemented, so the Calendar is notified when * an event is added, changed or removed. *

* * @since 7.1.0 * @author Vaadin Ltd. */ @Deprecated public class BasicEventProvider implements CalendarEditableEventProvider, EventSetChangeNotifier, CalendarEvent.EventChangeListener { protected List eventList = new ArrayList(); private List listeners = new ArrayList(); /* * (non-Javadoc) * * @see * com.vaadin.addon.calendar.event.CalendarEventProvider#getEvents(java. * util.Date, java.util.Date) */ @Override public List getEvents(Date startDate, Date endDate) { List activeEvents = new ArrayList(); for (CalendarEvent ev : eventList) { long from = startDate.getTime(); long to = endDate.getTime(); if (ev.getStart() != null && ev.getEnd() != null) { long f = ev.getStart().getTime(); long t = ev.getEnd().getTime(); // Select only events that overlaps with startDate and // endDate. if ((f <= to && f >= from) || (t >= from && t <= to) || (f <= from && t >= to)) { activeEvents.add(ev); } } } return activeEvents; } /** * Does this event provider container this event. * * @param event * The event to check for * @return If this provider has the event then true is returned, else false */ public boolean containsEvent(BasicEvent event) { return eventList.contains(event); } /* * (non-Javadoc) * * @see com.vaadin.addon.calendar.ui.CalendarComponentEvents. * EventSetChangeNotifier #addListener * (com.vaadin.addon.calendar.ui.CalendarComponentEvents. * EventSetChangeListener ) */ @Override public void addEventSetChangeListener(EventSetChangeListener listener) { listeners.add(listener); } /* * (non-Javadoc) * * @see com.vaadin.addon.calendar.ui.CalendarComponentEvents. * EventSetChangeNotifier #removeListener * (com.vaadin.addon.calendar.ui.CalendarComponentEvents. * EventSetChangeListener ) */ @Override public void removeEventSetChangeListener(EventSetChangeListener listener) { listeners.remove(listener); } /** * Fires a eventsetchange event. The event is fired when either an event is * added or removed to the event provider */ protected void fireEventSetChange() { EventSetChangeEvent event = new EventSetChangeEvent(this); for (EventSetChangeListener listener : listeners) { listener.eventSetChange(event); } } /* * (non-Javadoc) * * @see * com.vaadin.addon.calendar.ui.CalendarComponentEvents.EventChangeListener * #eventChange * (com.vaadin.addon.calendar.ui.CalendarComponentEvents.EventSetChange) */ @Override public void eventChange(EventChangeEvent changeEvent) { // naive implementation fireEventSetChange(); } /* * (non-Javadoc) * * @see * com.vaadin.addon.calendar.event.CalendarEditableEventProvider#addEvent * (com.vaadin.addon.calendar.event.CalendarEvent) */ @Override public void addEvent(CalendarEvent event) { eventList.add(event); if (event instanceof BasicEvent) { ((BasicEvent) event).addEventChangeListener(this); } fireEventSetChange(); } /* * (non-Javadoc) * * @see * com.vaadin.addon.calendar.event.CalendarEditableEventProvider#removeEvent * (com.vaadin.addon.calendar.event.CalendarEvent) */ @Override public void removeEvent(CalendarEvent event) { eventList.remove(event); if (event instanceof BasicEvent) { ((BasicEvent) event).removeEventChangeListener(this); } fireEventSetChange(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy