Class Calendars

  • All Implemented Interfaces:
    Serializable, Cloneable, org.zkoss.zk.ui.Component, org.zkoss.zk.ui.ext.Scope, org.zkoss.zk.ui.sys.ComponentCtrl

    public class Calendars
    extends org.zkoss.zul.impl.XulElement
    A complete calendar component to represent a calendar to support both molds, default and month, and multi-timezone. By default mold, it can change the days to show one day or a week (days equal to seven) on the calendar at the same time. In the month mold, seven days is always assumed.

    The Calendars component allows only one single toolbar as its child component, and now it can only manipulate the calendar item by a model named CalendarModel. And there are three events, onItemCreate, onItemEdit, and onItemUpdate that can be listened to operate the calendar event triggering by user action, in addition to there are two events onDayClick and onWeekClick to be triggered when user clicks on the caption of the day number and the week number within the current year. Besides, the calendar can also support the read-only display by invoking setReadonly(boolean).

    Author:
    jumperchen,jimmy
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.zkoss.zk.ui.HtmlBasedComponent

        org.zkoss.zk.ui.HtmlBasedComponent.ExtraCtrl
      • Nested classes/interfaces inherited from class org.zkoss.zk.ui.AbstractComponent

        org.zkoss.zk.ui.AbstractComponent.Children
    • Constructor Summary

      Constructors 
      Constructor Description
      Calendars()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void addDayItem​(CalendarItem ce)  
      void addTimeZone​(String label, String timezone)
      Adds the time zone to the calendar.
      void addTimeZone​(String label, TimeZone timezone)
      Adds the time zone to the calendar.
      protected void cleanEmptyZone()  
      Object clone()  
      Date getBeginDate()
      Deprecated.
      3.2.0
      LocalDateTime getBeginDateTime()
      Returns the beginning date of the current calendar view using Java 8's date-time API.
      int getBeginTime()
      Returns the beginning time.
      protected Calendar getCalendar()  
      CalendarItem getCalendarItemById​(String id)  
      String getCalendarItemId​(CalendarItem ce)  
      Date getCurrentDate()
      Deprecated.
      3.2.0
      LocalDateTime getCurrentDateTime()
      Returns the current date using Java 8's date-time API.
      DateFormatter getDateFormatter()
      Returns the date formatter.
      int getDays()
      Returns the days.
      protected static Comparator<CalendarItem> getDefaultBeginDateComparator()  
      TimeZone getDefaultTimeZone()
      Returns the current time zone of the calendar.
      Date getEndDate()
      Deprecated.
      3.2.0
      LocalDateTime getEndDateTime()
      Returns the end date of the current calendar view using Java 8's date-time API.
      int getEndTime()  
      int getFirstDayOfWeek()
      Gets what the first day of the week is; e.g., SUNDAY in the U.S., MONDAY in France.
      List<CalendarItem> getItem​(Date beginDate)
      Returns the unmodifiable list including all the calendar items matching from the specified date in the same date.
      protected String getItemKey​(Date date)  
      protected String getItemKey​(CalendarItem evt)  
      ItemRender getItemRender()
      Deprecated.
      As of release 2.0-RC Returns the item renderer used for CalendarItem to draw its outline (i.e.
      CalendarModel getModel()
      Returns the calendar model.
      int getTimeslots()  
      Map<TimeZone,​String> getTimeZones()
      Returns the unmodifiable map including all the timezone inside the calendar.
      org.zkoss.zul.Toolbar getToolbar()  
      int getWeekOfMonth()
      Returns the number of the week of the month in the current date.
      String getZclass()  
      protected void init()  
      protected void initDataListener()
      Initializes _dataListener and register the listener to the model
      boolean insertBefore​(org.zkoss.zk.ui.Component newChild, org.zkoss.zk.ui.Component refChild)  
      boolean isEscapeXML()
      Return whether the item content escape XML
      boolean isReadonly()
      Returns whether it is readonly.
      boolean isWeekOfYear()
      Returns whether enable to show the week number within the current year or not.
      void modifyDayItem​(CalendarItem ce)  
      protected void movePage​(int day)  
      protected void movePeriod​(int increment)
      Moves calendar by week or month based on current mold ZKCAL-106
      void nextPage()
      Navigates the current date to the next page, that is, when the getDays() is seven with default mold, the next page means the next week.
      void nextPeriod()
      Moves to next period (week in default mold, month in month mold) ZKCAL-106
      void onAddDayItemResponse()  
      void onInitRender()  
      void onModifyDayItemResponse()  
      void onRemoveDayItemResponse()  
      void previousPage()
      Navigates the current date to the previous page, that is, when the getDays() is seven with default mold, the previous page means the previous week.
      void previousPeriod()
      Moves to previous period (week in default mold, month in month mold) ZKCAL-106
      protected void readObject​(ObjectInputStream s)  
      void removeDayItem​(CalendarItem ce)  
      boolean removeTimeZone​(TimeZone timezone)
      Removes the time zone from the calendar
      protected void rendererDayData​(DateFormatter dfhandler, org.zkoss.zk.ui.sys.ContentRenderer renderer)  
      protected void rendererMonthData​(DateFormatter dfhandler, org.zkoss.zk.ui.sys.ContentRenderer renderer)  
      protected void renderProperties​(org.zkoss.zk.ui.sys.ContentRenderer renderer)  
      protected void reSendDateRange()  
      protected void reSendItemGroup()  
      void service​(org.zkoss.zk.au.AuRequest request, boolean everError)  
      void setBeginTime​(int beginTime)
      Sets the beginning time.
      void setCurrentDate​(Date curDate)
      Deprecated.
      3.2.0
      void setCurrentDateTime​(LocalDateTime localDateTime)
      Sets the date that determines which period (month/week) the calendar displays, using Java 8 date-time API.
      void setDateFormatter​(String clsnm)
      Sets the date formatter by a class name.
      void setDateFormatter​(DateFormatter dfmater)
      Sets the date formatter.
      void setDays​(int days)
      Sets the days, that is, how many columns should be displayed on the default mold.
      void setEndTime​(int endTime)  
      void setEscapeXML​(boolean escapeXML)
      Sets whether the item content escape XML
      void setFirstDayOfWeek​(int value)
      Sets what the first day of the week is; e.g., SUNDAY in the U.S., MONDAY in France.
      void setFirstDayOfWeek​(String day)
      Sets what the first day of the week is.
      void setItemRender​(ItemRender render)
      Deprecated.
      As of release 2.0-RC Sets the item renderer.
      void setModel​(CalendarModel model)
      Sets the calendar model.
      void setMold​(String mold)  
      void setReadonly​(boolean readonly)
      Sets whether it is readonly.
      void setTimeslots​(int timeslots)  
      void setTimeZone​(String timezone)
      Sets the time zone to the calendar, it is easily used for ZUL file.
      void setWeekOfYear​(boolean weekOfYear)
      Sets whether enable to show the week number within the current year or not.
      • Methods inherited from class org.zkoss.zul.impl.XulElement

        getContext, getCtrlKeys, getPopup, getPropertyAccess, getTooltip, setContext, setContext, setContextAttributes, setCtrlKeys, setPopup, setPopup, setPopupAttributes, setTooltip, setTooltip, setTooltipAttributes
      • Methods inherited from class org.zkoss.zk.ui.HtmlBasedComponent

        addSclass, evalCSSFlex, focus, getAction, getDraggable, getDroppable, getExtraCtrl, getHeight, getHflex, getLeft, getRenderdefer, getSclass, getStyle, getTabindex, getTabindexInteger, getTooltiptext, getTop, getVflex, getWidth, getZindex, getZIndex, removeSclass, removeSclass, setAction, setClass, setDraggable, setDroppable, setFocus, setHeight, setHeight0, setHeightDirectly, setHflex, setHflex0, setHflexDirectly, setLeft, setLeftDirectly, setRenderdefer, setSclass, setStyle, setTabindex, setTabindex, setTooltiptext, setTop, setTopDirectly, setVflex, setVflex0, setVflexDirectly, setWidth, setWidth0, setWidthDirectly, setZclass, setZindex, setZIndex, setZIndexDirectly
      • Methods inherited from class org.zkoss.zk.ui.AbstractComponent

        addAnnotation, addAnnotation, addCallback, addClientEvent, addEventHandler, addEventListener, addEventListener, addForward, addForward, addForward, addForward, addMoved, addRedrawCallback, addScopeListener, addShadowRoot, addShadowRootBefore, addSharedEventHandlerMap, appendChild, applyProperties, beforeChildAdded, beforeChildRemoved, beforeParentChanged, detach, didActivate, didActivate, didDeserialize, didDeserialize, disableBindingAnnotation, disableClientUpdate, enableBindingAnnotation, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotation, getAnnotations, getAnnotations, getAnnotations, getAttribute, getAttribute, getAttribute, getAttributeOrFellow, getAttributes, getAttributes, getAuService, getAutag, getCallback, getChildren, getClientAttribute, getClientDataAttribute, getClientEvents, getDefaultMold, getDefinition, getDesktop, getEventHandler, getEventHandlerNames, getEventListenerMap, getEventListeners, getFellow, getFellow, getFellowIfAny, getFellowIfAny, getFellows, getFirstChild, getId, getLastChild, getListenerIterator, getMold, getNextSibling, getPage, getParent, getPreviousSibling, getRedrawCallback, getRoot, getShadowFellowIfAny, getShadowRoots, getShadowVariable, getShadowVariable, getShadowVariable0, getSpaceOwner, getSpecialRendererOutput, getStubonly, getSubBindingAnnotationCount, getTemplate, getTemplateNames, getUuid, getWidgetAttribute, getWidgetAttributeNames, getWidgetClass, getWidgetListener, getWidgetListenerNames, getWidgetOverride, getWidgetOverrideNames, hasAttribute, hasAttribute, hasAttribute, hasAttributeOrFellow, hasBindingAnnotation, hasFellow, hasFellow, hasSubBindingAnnotation, invalidate, invalidatePartial, isChildable, isInitialized, isInvalidated, isListenerAvailable, isVisible, onChildAdded, onChildRemoved, onPageAttached, onPageDetached, onWrongValue, query, queryAll, redraw, redrawChildren, removeAttribute, removeAttribute, removeAttribute, removeCallback, removeChild, removeEventListener, removeForward, removeForward, removeRedrawCallback, removeScopeListener, removeShadowRoot, render, render, render, replace, response, response, response, service, sessionDidActivate, sessionWillPassivate, setAttribute, setAttribute, setAttribute, setAuService, setAutag, setClientAttribute, setClientDataAttribute, setDefinition, setDefinition, setId, setPage, setPageBefore, setParent, setStubonly, setStubonly, setSubBindingAnnotationCount, setTemplate, setVisible, setVisibleDirectly, setWidgetAttribute, setWidgetClass, setWidgetListener, setWidgetOverride, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdateWidgetListener, smartUpdateWidgetOverride, toString, updateByClient, updateSubBindingAnnotationCount, willPassivate, willPassivate, willSerialize, willSerialize
      • Methods inherited from interface org.zkoss.zk.ui.sys.ComponentCtrl

        invalidatePartial
    • Constructor Detail

      • Calendars

        public Calendars()
    • Method Detail

      • init

        protected void init()
      • setWeekOfYear

        public void setWeekOfYear​(boolean weekOfYear)
        Sets whether enable to show the week number within the current year or not.
      • isWeekOfYear

        public boolean isWeekOfYear()
        Returns whether enable to show the week number within the current year or not.

        Default: false

      • setReadonly

        public void setReadonly​(boolean readonly)
        Sets whether it is readonly.
      • isReadonly

        public boolean isReadonly()
        Returns whether it is readonly.

        Default: false.

      • setDateFormatter

        public void setDateFormatter​(DateFormatter dfmater)
        Sets the date formatter. In fact, there are five places in the calendar must have different date display.
        See Also:
        DateFormatter
      • getDateFormatter

        public DateFormatter getDateFormatter()
        Returns the date formatter.

        Note: never null.

      • setDays

        public void setDays​(int days)
        Sets the days, that is, how many columns should be displayed on the default mold.

        Default: 7. (i.e. one week), in month view, the attribute will be ignored.

      • getDays

        public int getDays()
        Returns the days.

        Default: 7

      • setFirstDayOfWeek

        public void setFirstDayOfWeek​(int value)
        Sets what the first day of the week is; e.g., SUNDAY in the U.S., MONDAY in France.

        Default: Calendar.SUNDAY

        Note: it is only allowed when days with 7 in the default mold or using the month mold.

        Parameters:
        value - the given first day of the week.
        See Also:
        getFirstDayOfWeek(), Calendar.setFirstDayOfWeek(int)
      • setFirstDayOfWeek

        public void setFirstDayOfWeek​(String day)
        Sets what the first day of the week is.

        Note: it is only allowed when days with 7 in the default mold or using the month mold.

        Parameters:
        day - SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, and SATURDAY. Case insensitive
      • onAddDayItemResponse

        public void onAddDayItemResponse()
      • onRemoveDayItemResponse

        public void onRemoveDayItemResponse()
      • onModifyDayItemResponse

        public void onModifyDayItemResponse()
      • modifyDayItem

        public void modifyDayItem​(CalendarItem ce)
      • removeDayItem

        public void removeDayItem​(CalendarItem ce)
      • cleanEmptyZone

        protected void cleanEmptyZone()
      • getCalendar

        protected Calendar getCalendar()
      • addTimeZone

        public void addTimeZone​(String label,
                                TimeZone timezone)
        Adds the time zone to the calendar.

        Note: the first added will be the default time zone of the calendar.

        Parameters:
        label - the description of the time zone.
        timezone - a time zone. (Cannot duplicate)
      • addTimeZone

        public void addTimeZone​(String label,
                                String timezone)
        Adds the time zone to the calendar.

        Note: the first added will be the default time zone of the calendar.

        Parameters:
        label - the description of the time zone.
        timezone - a id of time zone. (Cannot duplicate)
        See Also:
        TimeZone.getTimeZone(String), addTimeZone(String, TimeZone)
      • setTimeZone

        public void setTimeZone​(String timezone)
        Sets the time zone to the calendar, it is easily used for ZUL file. e.g.
         <calendars timeZone="Taiwan=GMT+8, Sweden=GMT+1,">
         
        Parameters:
        timezone -
      • removeTimeZone

        public boolean removeTimeZone​(TimeZone timezone)
        Removes the time zone from the calendar
      • getDefaultTimeZone

        public TimeZone getDefaultTimeZone()
        Returns the current time zone of the calendar.
      • getTimeZones

        public Map<TimeZone,​String> getTimeZones()
        Returns the unmodifiable map including all the timezone inside the calendar.
      • getItemKey

        protected String getItemKey​(Date date)
      • getItem

        public List<CalendarItem> getItem​(Date beginDate)
        Returns the unmodifiable list including all the calendar items matching from the specified date in the same date. e.g. "20090324" exclusive the time of the date "23:30".

        Note: never null.

      • getDefaultBeginDateComparator

        protected static final Comparator<CalendarItem> getDefaultBeginDateComparator()
      • previousPage

        public void previousPage()
        Navigates the current date to the previous page, that is, when the getDays() is seven with default mold, the previous page means the previous week. In the month mold, it means the previous month.
      • nextPage

        public void nextPage()
        Navigates the current date to the next page, that is, when the getDays() is seven with default mold, the next page means the next week. In the month mold, it means the next month.
      • movePage

        protected void movePage​(int day)
      • nextPeriod

        public void nextPeriod()
        Moves to next period (week in default mold, month in month mold) ZKCAL-106
        Since:
        3.2.0
      • previousPeriod

        public void previousPeriod()
        Moves to previous period (week in default mold, month in month mold) ZKCAL-106
        Since:
        3.2.0
      • movePeriod

        protected void movePeriod​(int increment)
        Moves calendar by week or month based on current mold ZKCAL-106
        Parameters:
        increment - Number of periods to move (positive=forward, negative=backward)
        Since:
        3.2.0
      • getBeginDate

        public Date getBeginDate()
        Deprecated.
        3.2.0
        Returns the beginning date of the current calendar view based on getCurrentDate(). JS widget renders this date as the first day of a week or a month. The behavior depends on the current mold and days settings:

        For Month View (mold="month"): - Sets calendar to first day of the month - Adjusts to first day of week based on getFirstDayOfWeek()

        For Week View (days longer or equal to 7): - Based on getCurrentDate(), return the day according to getFirstDayOfWeek(). By default, find the closest Sun.

        For Custom Days View (days less than 7): - Uses the current date as beginning date

        In all cases, the time portion is set to 00:00:00.000

        Returns:
        The beginning Date of the current view, or null if current date is not set
        See Also:
        getBeginDateTime()
      • getBeginDateTime

        public LocalDateTime getBeginDateTime()
        Returns the beginning date of the current calendar view using Java 8's date-time API. The behavior matches getBeginDate() but returns a LocalDateTime instead.
        Returns:
        The beginning LocalDateTime of the current view, or null if current date is not set
        Since:
        3.2.0
      • getEndDate

        public Date getEndDate()
        Deprecated.
        3.2.0
        Returns the end date, which is based on getCurrentDate() in the current view depended on which AbstractComponent.getMold() is using.
        See Also:
        getEndDateTime()
      • getEndDateTime

        public LocalDateTime getEndDateTime()
        Returns the end date of the current calendar view using Java 8's date-time API. The behavior matches getEndDate() but returns a LocalDateTime instead.
        Returns:
        The end LocalDateTime of the current view, or null if current date is not set
        Since:
        3.2.0
      • setCurrentDate

        public void setCurrentDate​(Date curDate)
        Deprecated.
        3.2.0
        Sets the date that determines which period (month/week) the calendar displays.

        For Month View (mold="month"): - Calendar displays the month containing this date

        For Week/Day View (mold="default"): - Calendar displays the week/days containing this date - Number of days shown depends on getDays()

        To change which month/week is displayed, set a date within the desired period.

        Default: today (in calendar's timezone) ZKCAL-84

        Parameters:
        curDate - The date determining which period to display, cannot be null
        Throws:
        NullPointerException - if curDate is null
        See Also:
        setCurrentDateTime(LocalDateTime)
      • setCurrentDateTime

        public void setCurrentDateTime​(LocalDateTime localDateTime)
        Sets the date that determines which period (month/week) the calendar displays, using Java 8 date-time API.

        For Month View (mold="month"): - Calendar displays the month containing this date

        For Week/Day View (mold="default"): - Calendar displays the week/days containing this date - Number of days shown depends on getDays()

        To change which month/week is displayed, set a date within the desired period.

        Default: today (in calendar's timezone) ZKCAL-84

        Parameters:
        localDateTime - The date determining which period to display, cannot be null
        Throws:
        NullPointerException - if localDateTime is null
        Since:
        3.2.0
      • getCurrentDate

        public Date getCurrentDate()
        Deprecated.
        3.2.0
        Returns the current date.

        Default: today (depend on which timezone the calendar is using).

        See Also:
        getCurrentDateTime()
      • getCurrentDateTime

        public LocalDateTime getCurrentDateTime()
        Returns the current date using Java 8's date-time API.

        Default: today (depend on which timezone the calendar is using).

        Since:
        3.2.0
      • setBeginTime

        public void setBeginTime​(int beginTime)
        Sets the beginning time.

        Default: 0.

        Since:
        2.1.0
      • getBeginTime

        public int getBeginTime()
        Returns the beginning time.

        Default: 0.

        Since:
        2.1.0
      • setEndTime

        public void setEndTime​(int endTime)
        Since:
        2.1.0 Sets the end time.

        Default: 24.

      • getEndTime

        public int getEndTime()
        Since:
        2.1.0 Returns the end time.

        Default: 24.

      • setTimeslots

        public void setTimeslots​(int timeslots)
        Since:
        2.1.0 Sets the time slot per hour.

        Default: 2.

      • getTimeslots

        public int getTimeslots()
        Since:
        2.1.0 Returns the time slot per hour.

        Default: 2.

      • reSendDateRange

        protected void reSendDateRange()
      • getWeekOfMonth

        public int getWeekOfMonth()
        Returns the number of the week of the month in the current date.
      • reSendItemGroup

        protected void reSendItemGroup()
      • onInitRender

        public void onInitRender()
      • getToolbar

        public org.zkoss.zul.Toolbar getToolbar()
      • getModel

        public CalendarModel getModel()
        Returns the calendar model.
      • setModel

        public void setModel​(CalendarModel model)
        Sets the calendar model.
      • initDataListener

        protected void initDataListener()
        Initializes _dataListener and register the listener to the model
      • setMold

        public void setMold​(String mold)
        Specified by:
        setMold in interface org.zkoss.zk.ui.Component
        Overrides:
        setMold in class org.zkoss.zk.ui.AbstractComponent
      • setEscapeXML

        public void setEscapeXML​(boolean escapeXML)
        Sets whether the item content escape XML
        Parameters:
        escapeXML -
      • isEscapeXML

        public boolean isEscapeXML()
        Return whether the item content escape XML
        Returns:
        boolean
      • getZclass

        public String getZclass()
        Overrides:
        getZclass in class org.zkoss.zk.ui.HtmlBasedComponent
      • insertBefore

        public boolean insertBefore​(org.zkoss.zk.ui.Component newChild,
                                    org.zkoss.zk.ui.Component refChild)
        Specified by:
        insertBefore in interface org.zkoss.zk.ui.Component
        Overrides:
        insertBefore in class org.zkoss.zk.ui.AbstractComponent
      • clone

        public Object clone()
        Specified by:
        clone in interface org.zkoss.zk.ui.Component
        Overrides:
        clone in class org.zkoss.zul.impl.XulElement
      • service

        public void service​(org.zkoss.zk.au.AuRequest request,
                            boolean everError)
        Specified by:
        service in interface org.zkoss.zk.ui.sys.ComponentCtrl
        Overrides:
        service in class org.zkoss.zk.ui.HtmlBasedComponent
      • renderProperties

        protected void renderProperties​(org.zkoss.zk.ui.sys.ContentRenderer renderer)
                                 throws IOException
        Overrides:
        renderProperties in class org.zkoss.zul.impl.XulElement
        Throws:
        IOException
      • getItemRender

        public ItemRender getItemRender()
        Deprecated.
        As of release 2.0-RC Returns the item renderer used for CalendarItem to draw its outline (i.e. HTML), like the DSP renderer of ZK component.

        Note: never null.

      • setItemRender

        public void setItemRender​(ItemRender render)
        Deprecated.
        As of release 2.0-RC Sets the item renderer.