com.vaadin.ui.

Class Calendar

Since:

7.1

Author:

Vaadin Ltd.

See Also:

Serialized Form

    • Field Detail

      • currentTimeFormat

        protected Calendar.TimeFormat currentTimeFormat

        Defines currently active format for time. 12H/24H.

      • currentCalendar

        protected Calendar currentCalendar

        Internal calendar data source.

      • timezone

        protected TimeZone timezone

        Defines the component's active time zone.

      • startDate

        protected Date startDate

        Defines the calendar's date range starting point.

      • endDate

        protected Date endDate

        Defines the calendar's date range ending point.

      • events

        protected List<CalendarEvent> events

        Internal buffer for the events that are retrieved from the event provider.

      • df_date

        protected DateFormat df_date

        Date format that will be used in the UIDL for dates.

      • df_time

        protected DateFormat df_time

        Time format that will be used in the UIDL for time.

      • df_date_time

        protected DateFormat df_date_time

        Date format that will be used in the UIDL for both date and time.

    • Constructor Detail

      • Calendar

        public Calendar()

        Construct a Vaadin Calendar with a BasicEventProvider and no caption. Default date range is one week.

      • Calendar

        public Calendar(String caption)

        Construct a Vaadin Calendar with a BasicEventProvider and the provided caption. Default date range is one week.

        Parameters:

        caption -

      • Calendar

        public Calendar(CalendarEventProvider eventProvider)

        Construct a Vaadin Calendar with event provider. Event provider is obligatory, because calendar component will query active events through it.

        By default, Vaadin Calendar will show dates from the start of the current week to the end of the current week. Use setStartDate(Date) and setEndDate(Date) to change this.

        Parameters:

        eventProvider - Event provider, cannot be null.

      • Calendar

        public Calendar(String caption,
                        CalendarEventProvider eventProvider)

        Construct a Vaadin Calendar with event provider and a caption. Event provider is obligatory, because calendar component will query active events through it.

        By default, Vaadin Calendar will show dates from the start of the current week to the end of the current week. Use setStartDate(Date) and setEndDate(Date) to change this.

        Parameters:

        eventProvider - Event provider, cannot be null.

    • Method Detail

      • getLogger

        protected Logger getLogger()

        Returns the logger for the calendar

      • getState

        public CalendarState getState()

        Description copied from class: AbstractComponent

        Returns the shared state bean with information to be sent from the server to the client. Subclasses should override this method and set any relevant fields of the state returned by super.getState().

        Overrides:

        getState in class AbstractComponent

        Returns:

        updated component shared state

      • beforeClientResponse

        public void beforeClientResponse(boolean initial)

        Description copied from interface: ClientConnector

        Called before the shared state and RPC invocations are sent to the client. Gives the connector an opportunity to set computed/dynamic state values or to invoke last minute RPC methods depending on other component features.

        Specified by:

        beforeClientResponse in interface ClientConnector

        Overrides:

        beforeClientResponse in class AbstractComponent

        Parameters:

        initial - true if the client-side connector will be created and initialized after this method has been invoked. false if there is already an initialized client-side connector.

      • setDefaultHandlers

        protected void setDefaultHandlers()

        Set all the wanted default handlers here. This is always called after constructing this object. All other events have default handlers except range and event click.

      • getStartDate

        public Date getStartDate()

        Gets the calendar's start date.

        Returns:

        First visible date.

      • setStartDate

        public void setStartDate(Date date)

        Sets start date for the calendar. This and setEndDate(Date) control the range of dates visible on the component. The default range is one week.

        Parameters:

        date - First visible date to show.

      • getEndDate

        public Date getEndDate()

        Gets the calendar's end date.

        Returns:

        Last visible date.

      • setEndDate

        public void setEndDate(Date date)

        Sets end date for the calendar. Starting from startDate, only six weeks will be shown if duration to endDate is longer than six weeks. This and setStartDate(Date) control the range of dates visible on the component. The default range is one week.

        Parameters:

        date - Last visible date to show.

      • autoScaleVisibleHoursOfDay

        public void autoScaleVisibleHoursOfDay()

        Sets the displayed start and end time to fit all current events that were retrieved from the last call to getEvents().

        If no events exist, nothing happens.

        NOTE: triggering this method only does this once for the current events - events that are not in the current visible range, are ignored!

        See Also:

        setFirstVisibleHourOfDay(int), setLastVisibleHourOfDay(int)

      • getTimeFormat

        public Calendar.TimeFormat getTimeFormat()

        Gets currently active time format. Value is either TimeFormat.Format12H or TimeFormat.Format24H.

        Returns:

        TimeFormat Format for the time.

      • setTimeFormat

        public void setTimeFormat(Calendar.TimeFormat format)

        Example: setTimeFormat(TimeFormat.Format12H);
        Set to null, if you want the format being defined by the locale.

        Parameters:

        format - Set 12h or 24h format. Default is defined by the locale.

      • getTimeZone

        public TimeZone getTimeZone()

        Returns a time zone that is currently used by this component.

        Returns:

        Component's Time zone

      • setTimeZone

        public void setTimeZone(TimeZone zone)

        Set time zone that this component will use. Null value sets the default time zone.

        Parameters:

        zone - Time zone to use

      • getInternalCalendar

        public Calendar getInternalCalendar()

        Get the internally used Calendar instance. This is the currently used instance of Calendar but is bound to change during the lifetime of the component.

        Returns:

        the currently used java calendar

      • setFirstVisibleDayOfWeek

        public void setFirstVisibleDayOfWeek(int firstDay)

        This method restricts the weekdays that are shown. This affects both the monthly and the weekly view. The general contract is that firstDay < lastDay.

        Note that this only affects the rendering process. Events are still requested by the dates set by setStartDate(Date) and setEndDate(Date).

        Parameters:

        firstDay - the first day of the week to show, between 1 and 7

      • getFirstVisibleDayOfWeek

        public int getFirstVisibleDayOfWeek()

        Get the first visible day of the week. Returns the weekdays as integers represented by Calendar.DAY_OF_WEEK

        Returns:

        An integer representing the week day according to Calendar.DAY_OF_WEEK

      • setLastVisibleDayOfWeek

        public void setLastVisibleDayOfWeek(int lastDay)

        This method restricts the weekdays that are shown. This affects both the monthly and the weekly view. The general contract is that firstDay < lastDay.

        Note that this only affects the rendering process. Events are still requested by the dates set by setStartDate(Date) and setEndDate(Date).

        Parameters:

        lastDay - the first day of the week to show, between 1 and 7

      • getLastVisibleDayOfWeek

        public int getLastVisibleDayOfWeek()

        Get the last visible day of the week. Returns the weekdays as integers represented by Calendar.DAY_OF_WEEK

        Returns:

        An integer representing the week day according to Calendar.DAY_OF_WEEK

      • setFirstVisibleHourOfDay

        public void setFirstVisibleHourOfDay(int firstHour)

        This method restricts the hours that are shown per day. This affects the weekly view. The general contract is that firstHour < lastHour.

        Note that this only affects the rendering process. Events are still requested by the dates set by setStartDate(Date) and setEndDate(Date).

        You can use autoScaleVisibleHoursOfDay() for automatic scaling of the visible hours based on current events.

        Parameters:

        firstHour - the first hour of the day to show, between 0 and 23

        See Also:

        autoScaleVisibleHoursOfDay()

      • getFirstVisibleHourOfDay

        public int getFirstVisibleHourOfDay()

        Returns the first visible hour in the week view. Returns the hour using a 24h time format

      • setLastVisibleHourOfDay

        public void setLastVisibleHourOfDay(int lastHour)

        This method restricts the hours that are shown per day. This affects the weekly view. The general contract is that firstHour < lastHour.

        Note that this only affects the rendering process. Events are still requested by the dates set by setStartDate(Date) and setEndDate(Date).

        You can use autoScaleVisibleHoursOfDay() for automatic scaling of the visible hours based on current events.

        Parameters:

        lastHour - the first hour of the day to show, between 0 and 23

        See Also:

        autoScaleVisibleHoursOfDay()

      • getLastVisibleHourOfDay

        public int getLastVisibleHourOfDay()

        Returns the last visible hour in the week view. Returns the hour using a 24h time format

      • getWeeklyCaptionFormat

        public String getWeeklyCaptionFormat()

        Gets the date caption format for the weekly view.

        Returns:

        The pattern used in caption of dates in weekly view.

      • setWeeklyCaptionFormat

        public void setWeeklyCaptionFormat(String dateFormatPattern)

        Sets custom date format for the weekly view. This is the caption of the date. Format could be like "mmm MM/dd".

        Parameters:

        dateFormatPattern - The date caption pattern.

      • isClientChangeAllowed

        protected boolean isClientChangeAllowed()

        Is the user allowed to trigger events which alters the events

        Returns:

        true if the client is allowed to send changes to server

        See Also:

        isEventClickAllowed()

      • isEventClickAllowed

        @Deprecated
        protected boolean isEventClickAllowed()

        Deprecated. As of 7.4, override fireEventClick(Integer) instead.

        Is the user allowed to trigger click events. Returns true by default. Subclass can override this method to disallow firing event clicks got from the client side.

        Returns:

        true if the client is allowed to click events

        See Also:

        isClientChangeAllowed()

      • fireNavigationEvent

        protected void fireNavigationEvent(boolean forward)

        Fires an event when the user selecing moving forward/backward in the calendar.

        Parameters:

        forward - True if the calendar moved forward else backward is assumed.

      • fireEventMove

        protected void fireEventMove(int index,
                                     Date newFromDatetime)

        Fires an event move event to all server side move listerners

        Parameters:

        index - The index of the event in the events list

        newFromDatetime - The changed from date time

      • fireWeekClick

        protected void fireWeekClick(int week,
                                     int year)

        Fires event when a week was clicked in the calendar.

        Parameters:

        week - The week that was clicked

        year - The year of the week

      • fireEventClick

        protected void fireEventClick(Integer index)

        Fires event when a date was clicked in the calendar. Uses an existing event from the event cache.

        Parameters:

        index - The index of the event in the event cache.

      • fireDateClick

        protected void fireDateClick(Date date)

        Fires event when a date was clicked in the calendar. Creates a new event for the date and passes it to the listener.

        Parameters:

        date - The date and time that was clicked

      • fireRangeSelect

        protected void fireRangeSelect(Date from,
                                       Date to,
                                       boolean monthlyMode)

        Fires an event range selected event. The event is fired when a user highlights an area in the calendar. The highlighted areas start and end dates are returned as arguments.

        Parameters:

        from - The start date and time of the highlighted area

        to - The end date and time of the highlighted area

        monthlyMode - Is the calendar in monthly mode

      • fireEventResize

        protected void fireEventResize(int index,
                                       Date startTime,
                                       Date endTime)

        Fires an event resize event. The event is fired when a user resizes the event in the calendar causing the time range of the event to increase or decrease. The new start and end times are returned as arguments to this method.

        Parameters:

        index - The index of the event in the event cache

        startTime - The new start date and time of the event

        endTime - The new end date and time of the event

      • getDayNamesShort

        protected String[] getDayNamesShort()

        Localized display names for week days starting from sunday. Returned array's length is always 7.

        Returns:

        Array of localized weekday names.

      • getMonthNamesShort

        protected String[] getMonthNamesShort()

        Localized display names for months starting from January. Returned array's length is always 12.

        Returns:

        Array of localized month names.

      • getFirstDateForWeek

        protected Date getFirstDateForWeek(Date date)

        Gets a date that is first day in the week that target given date belongs to.

        Parameters:

        date - Target date

        Returns:

        Date that is first date in same week that given date is.

      • getLastDateForWeek

        protected Date getLastDateForWeek(Date date)

        Gets a date that is last day in the week that target given date belongs to.

        Parameters:

        date - Target date

        Returns:

        Date that is last date in same week that given date is.

      • expandStartDate

        protected Date expandStartDate(Date start,
                                       boolean expandToFullWeek)

        Finds the first day of the week and returns a day representing the start of that day

        Parameters:

        start - The actual date

        expandToFullWeek - Should the returned date be moved to the start of the week

        Returns:

        If expandToFullWeek is set then it returns the first day of the week, else it returns a clone of the actual date with the time set to the start of the day

      • expandEndDate

        protected Date expandEndDate(Date end,
                                     boolean expandToFullWeek)

        Finds the last day of the week and returns a day representing the end of that day

        Parameters:

        end - The actual date

        expandToFullWeek - Should the returned date be moved to the end of the week

        Returns:

        If expandToFullWeek is set then it returns the last day of the week, else it returns a clone of the actual date with the time set to the end of the day

      • setEventProvider

        public void setEventProvider(CalendarEventProvider calendarEventProvider)

        Set the CalendarEventProvider to be used with this calendar. The EventProvider is used to query for events to show, and must be non-null. By default a BasicEventProvider is used.

        Parameters:

        calendarEventProvider - the calendarEventProvider to set. Cannot be null.

      • setHandler

        protected void setHandler(String eventId,
                                  Class<?> eventType,
                                  EventListener listener,
                                  Method listenerMethod)

        Set the handler for the given type information. Mirrors addListener from AbstractComponent

        Parameters:

        eventId - A unique id for the event. Usually one of CalendarEventId

        eventType - The class of the event, most likely a subclass of CalendarComponentEvent

        listener - A listener that listens to the given event

        listenerMethod - The method on the lister to call when the event is triggered

      • getDropHandler

        public DropHandler getDropHandler()

        Get the currently active drop handler

        Specified by:

        getDropHandler in interface DropTarget

        Returns:

        the drop hanler that will receive the dragged data or null if drops are not currently accepted

      • setDropHandler

        public void setDropHandler(DropHandler dropHandler)

        Set the drop handler for the calendar See DropHandler for implementation details.

        Parameters:

        dropHandler - The drop handler to set

      • translateDropTargetDetails

        public TargetDetails translateDropTargetDetails(Map<String,Object> clientVariables)

        Description copied from interface: DropTarget

        Called before the DragAndDropEvent is passed to DropHandler. Implementation may for example translate the drop target details provided by the client side (drop target) to meaningful server side values. If null is returned the terminal implementation will automatically create a TargetDetails with raw client side data.

        Specified by:

        translateDropTargetDetails in interface DropTarget

        Parameters:

        clientVariables - data passed from the DropTargets client side counterpart.

        Returns:

        A DropTargetDetails object with the translated data or null to use a default implementation.

        See Also:

        DragSource.getTransferable(Map)

      • setContainerDataSource

        public void setContainerDataSource(Container.Indexed container)

        Sets a container as a data source for the events in the calendar. Equivalent for doing Calendar.setEventProvider(new ContainerEventProvider(container)) Use this method if you are adding a container which uses the default property ids like BeanItemContainer for instance. If you are using custom properties instead use setContainerDataSource(Container.Indexed, Object, Object, Object, Object, Object) Please note that the container must be sorted by date!

        Parameters:

        container - The container to use as a datasource

      • setContainerDataSource

        public void setContainerDataSource(Container.Indexed container,
                                           Object captionProperty,
                                           Object descriptionProperty,
                                           Object startDateProperty,
                                           Object endDateProperty,
                                           Object styleNameProperty)

        Sets a container as a data source for the events in the calendar. Equivalent for doing Calendar.setEventProvider(new ContainerEventProvider(container)) Please note that the container must be sorted by date!

        Parameters:

        container - The container to use as a data source

        captionProperty - The property that has the caption, null if no caption property is present

        descriptionProperty - The property that has the description, null if no description property is present

        startDateProperty - The property that has the starting date

        endDateProperty - The property that has the ending date

        styleNameProperty - The property that has the stylename, null if no stylname property is present

      • getEvents

        public List<CalendarEvent> getEvents(Date startDate,
                                             Date endDate)

        Description copied from interface: CalendarEventProvider

        Gets all available events in the target date range between startDate and endDate. The Vaadin Calendar queries the events from the range that is shown, which is not guaranteed to be the same as the date range that is set.

        For example, if you set the date range to be monday 22.2.2010 - wednesday 24.2.2010, the used Event Provider will be queried for events between monday 22.2.2010 00:00 and sunday 28.2.2010 23:59. Generally you can expect the date range to be expanded to whole days and whole weeks.

        Specified by:

        getEvents in interface CalendarEventProvider

        Parameters:

        startDate - Start date

        endDate - End date

        Returns:

        List of events

      • isMonthlyMode

        public boolean isMonthlyMode()

        Is the calendar in a mode where all days of the month is shown

        Returns:

        Returns true if calendar is in monthly mode and false if it is in weekly mode

      • removeActionHandler

        public void removeActionHandler(Action.Handler actionHandler)

        Description copied from interface: Action.Container

        Removes a previously registered action handler for the contents of this container.

        Specified by:

        removeActionHandler in interface Action.Container

        Parameters:

        actionHandler - the handler to be removed.

      • changeVariables

        public void changeVariables(Object source,
                                    Map<String,Object> variables)

        Description copied from interface: VariableOwner

        Called when one or more variables handled by the implementing class are changed.

        Specified by:

        changeVariables in interface VariableOwner

        Parameters:

        source - the Source of the variable change. This is the origin of the event. For example in Web Adapter this is the request.

        variables - the Mapping from variable names to new variable values.

      • paintContent

        public void paintContent(PaintTarget target)
                          throws PaintException

        Description copied from interface: LegacyComponent

        Paints the Paintable into a UIDL stream. This method creates the UIDL sequence describing it and outputs it to the given UIDL stream.

        It is called when the contents of the component should be painted in response to the component first being shown or having been altered so that its visual representation is changed.

        Specified by:

        paintContent in interface LegacyComponent

        Parameters:

        target - the target UIDL stream where the component should paint itself to.

        Throws:

        PaintException - if the paint operation failed.

      • setEventCaptionAsHtml

        public void setEventCaptionAsHtml(boolean eventCaptionAsHtml)

        Sets whether the event captions are rendered as HTML.

        If set to true, the captions are rendered in the browser as HTML and the developer is responsible for ensuring no harmful HTML is used. If set to false, the caption is rendered in the browser as plain text.

        The default is false, i.e. to render that caption as plain text.

        Parameters:

        captionAsHtml - true if the captions are rendered as HTML, false if rendered as plain text

      • isEventCaptionAsHtml

        public boolean isEventCaptionAsHtml()

        Checks whether event captions are rendered as HTML

        The default is false, i.e. to render that caption as plain text.

        Returns:

        true if the captions are rendered as HTML, false if rendered as plain text

      • readDesign

        public void readDesign(org.jsoup.nodes.Element design,
                               DesignContext designContext)

        Description copied from interface: Component

        Reads the component state from the given design.

        The component is responsible not only for updating its own state but also for ensuring that its children update their state based on the design.

        It is assumed that the component is in its default state when this method is called. Reading should only take into consideration attributes specified in the design and not reset any unspecified attributes to their defaults.

        This method must not modify the design.

        Specified by:

        readDesign in interface Component

        Overrides:

        readDesign in class AbstractComponent

        Parameters:

        design - The element to obtain the state from

        designContext - The DesignContext instance used for parsing the design

      • writeDesign

        public void writeDesign(org.jsoup.nodes.Element design,
                                DesignContext designContext)

        Description copied from interface: Component

        Writes the component state to the given design.

        The component is responsible not only for writing its own state but also for ensuring that its children write their state to the design.

        This method must not modify the component state.

        Specified by:

        writeDesign in interface Component

        Overrides:

        writeDesign in class AbstractComponent

        Parameters:

        design - The element to write the component state to. Any previous attributes or child nodes are not cleared.

        designContext - The DesignContext instance used for writing the design

      • getCustomAttributes

        protected Collection<String> getCustomAttributes()

        Description copied from class: AbstractComponent

        Returns a collection of attributes that should not be handled by the basic implementation of the readDesign and writeDesign methods. Typically these are handled in a custom way in the overridden versions of the above methods

        Overrides:

        getCustomAttributes in class AbstractComponent

        Returns:

        the collection of attributes that are not handled by the basic implementation

      • setFirstDayOfWeek

        public void setFirstDayOfWeek(Integer dayOfWeek)

        Allow setting first day of week independent of Locale. Set to null if you want first day of week being defined by the locale

        Parameters:

        dayOfWeek - any of java.util.Calendar.SUNDAY..java.util.Calendar.SATURDAY or null to revert to default first day of week by locale

        Since:

        7.6