com.dlsc.flexgantt.model.calendar
Class TimeGranularityCalendarModel<T extends IGanttChartNode,S extends AbstractCalendarEntry>

java.lang.Object
  extended by com.dlsc.flexgantt.model.calendar.AbstractCalendarModel<T,S>
      extended by com.dlsc.flexgantt.model.calendar.AbstractEntryCalendarModel<T,S>
          extended by com.dlsc.flexgantt.model.calendar.TimeGranularityCalendarModel<T,S>
Type Parameters:
T - the type of the Gantt chart node
S - the type of the calendar entries
All Implemented Interfaces:
ICalendarModel<T,S>

public class TimeGranularityCalendarModel<T extends IGanttChartNode,S extends AbstractCalendarEntry>
extends AbstractEntryCalendarModel<T,S>

A calendar model implementation that is based on TimeGranularity. It is capable of returning information on weekends and holidays. The holidays can be floating or annual holidays. The model requires that the currently used dateline model is an instance of TimeGranularityDatelineModel.

Since:
1.0
Author:
Dirk Lemmermann

Constructor Summary
TimeGranularityCalendarModel()
          Constructs a new calendar model.
 
Method Summary
 void addHoliday(java.util.Calendar calendar, boolean annual)
          Adds a holiday at the given time.
 void addHoliday(java.util.Date date, boolean annual)
          Adds a holiday at the given date.
 void addHoliday(int month, int day)
          Adds an annual holiday to the calendar.
 void addHoliday(int year, int month, int day)
          Adds a floating holiday to the calendar.
 void addHoliday(long time, boolean annual)
          Adds a holiday at the given time point.
protected  java.util.List<S> calculateEntries(IDatelineModel model, ITimeSpan span)
          Performs the actual calculation of the calendar entries that are located within the given time span.
protected  void fireCalendarModelChanged()
          Informs all listeners that the calendar model has been changed (e.g. a holiday has been added).
 java.util.Iterator<S> getCalendarEntries(IDatelineModel model, ITimeSpan span)
          Returns an iterator for iterating over all calendar entries within the given time span.
 java.util.Iterator<S> getCalendarEntries(IDatelineModel model, T node, ITimeSpan span)
          Returns an iterator for iterating over all calendar entries of the given node within the given time span.
 java.util.Date[] getHolidays(boolean annual)
          Returns the holidays that are defined in the model.
 int[] getWeekendDays()
          Returns the weekend days supported by the calendar.
protected  boolean isGranularityShowingCalendarEntries(TimeGranularity tg)
          Determines whether the given time granularity is suitable for displaying calendar entries.
 boolean isHoliday(java.util.Calendar calendar, boolean annual)
          Determines whether the given calendar object represents a holiday.
 boolean isHoliday(java.util.Date date, boolean annual)
          Determines whether the given date object represents a holiday.
 boolean isWeekendDay(int day)
          Checks whether the given value is stored in the list of weekend days.
 void removeHoliday(java.util.Calendar calendar, boolean annual)
          Removes a holiday from the calendar.
 void removeHoliday(java.util.Date date, boolean annual)
          Removes a holiday from the calendar.
 void removeHoliday(long time, boolean annual)
          Removes a holiday from the calendar.
 void setWeekendDays(int[] days)
          Sets the weekend days.
 
Methods inherited from class com.dlsc.flexgantt.model.calendar.AbstractEntryCalendarModel
getCalendarEntryTimeSpan
 
Methods inherited from class com.dlsc.flexgantt.model.calendar.AbstractCalendarModel
addCalendarListener, removeCalendarListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeGranularityCalendarModel

public TimeGranularityCalendarModel()
Constructs a new calendar model. The weekend days get initialized with Calendar.SATURDAY and Calendar.SUNDAY.

Since:
1.0
Method Detail

getCalendarEntries

public java.util.Iterator<S> getCalendarEntries(IDatelineModel model,
                                                ITimeSpan span)
Description copied from interface: ICalendarModel
Returns an iterator for iterating over all calendar entries within the given time span. The currently used dateline model gets also passed to this method as computations performed in this method are often dependent on it. Calendar entries returned by this method have a global character and are valid for the entire chart (for example weekend days or company holidays).

Parameters:
model - the currently used dateline model
span - the time span for which to return calendar entries
Returns:
an iterator over all calendar entries within the given time span

getCalendarEntries

public java.util.Iterator<S> getCalendarEntries(IDatelineModel model,
                                                T node,
                                                ITimeSpan span)
Description copied from interface: ICalendarModel
Returns an iterator for iterating over all calendar entries of the given node within the given time span. The currently used dateline model gets also passed to this method as computations performed in this method are often dependent on it. Calendar entries returned by this method are only relevant for the given node (example: a resource node might have entries indicating scheduled down time). This method should never return entries that are already returned by the more generic / global method ICalendarModel.getCalendarEntries(IDatelineModel, ITimeSpan).

Parameters:
model - the currently used dateline model
node - the tree node / Gantt chart node for which to return calendar entries
span - the time span for which to return calendar entries
Returns:
an iterator over all calendar entries within the given time span

calculateEntries

protected java.util.List<S> calculateEntries(IDatelineModel model,
                                             ITimeSpan span)
Performs the actual calculation of the calendar entries that are located within the given time span. This protected method allows subclasses of this calendar model to reuse the calculation.

Parameters:
model - the currently used dateline model
span - the time span for which to return a list of calendar entries
Returns:
a list of calendar entries for the given time span
Since:
1.0

isGranularityShowingCalendarEntries

protected boolean isGranularityShowingCalendarEntries(TimeGranularity tg)
Determines whether the given time granularity is suitable for displaying calendar entries. The default implementation will only show entries if the granularity is inside [DAY_SHORT, DAY_TINY]. Subclasses are free to override.

Parameters:
tg - the granularity to check for its suitability for showing calendar entries
Returns:
TRUE if the given granularity is suitable for displaying calendar entries
Since:
1.0

isWeekendDay

public boolean isWeekendDay(int day)
Checks whether the given value is stored in the list of weekend days. The value is based on Calendar.SATURDAY, Calendar.SUNDAY, Calendar.FRIDAY, etc...

Parameters:
day - the day of the week to check
Returns:
TRUE if the given day of the week is a weekend day
Since:
1.0

setWeekendDays

public void setWeekendDays(int[] days)
Sets the weekend days. Any day of the week can be a weekend day. All calendar day of week fields such as Calendar.SATURDAY, Calendar.SUNDAY, Calendar.FRIDAY, and so on, can be used as values

Parameters:
days - the days that represent weekend days
Since:
1.0

getWeekendDays

public int[] getWeekendDays()
Returns the weekend days supported by the calendar.

Returns:
the weekend days
Since:
1.0

addHoliday

public void addHoliday(long time,
                       boolean annual)
Adds a holiday at the given time point.

Parameters:
time - the time at which the holiday is located
annual - determines whether the holiday is a floating or an annual holiday
Since:
1.0
See Also:
addHoliday(Calendar, boolean), addHoliday(Date, boolean)

addHoliday

public void addHoliday(java.util.Date date,
                       boolean annual)
Adds a holiday at the given date.

Parameters:
date - the date at which the holiday is located
annual - determines whether the holiday is a floating or an annual holiday
Since:
1.0
See Also:
addHoliday(Calendar, boolean), addHoliday(long, boolean)

addHoliday

public void addHoliday(java.util.Calendar calendar,
                       boolean annual)
Adds a holiday at the given time.

Parameters:
calendar - the time at which the holiday is located
annual - determines whether the holiday is a floating or an annual holiday
Since:
1.0
See Also:
addHoliday(long, boolean), addHoliday(Date, boolean)

addHoliday

public void addHoliday(int year,
                       int month,
                       int day)
Adds a floating holiday to the calendar.

Parameters:
year - the year
month - the month (0 based, e.g. 0 for January, 1 for February)
day - the day of the months
Since:
1.0

addHoliday

public void addHoliday(int month,
                       int day)
Adds an annual holiday to the calendar.

Parameters:
month - the month (0 based, e.g. 0 for January, 1 for February)
day - the day of the months
Since:
1.0

removeHoliday

public void removeHoliday(long time,
                          boolean annual)
Removes a holiday from the calendar.

Parameters:
time - the time at which the holiday is located
annual - determines whether the holiday is a floating or an annual holiday
Since:
1.0
See Also:
removeHoliday(Calendar, boolean), removeHoliday(Date, boolean)

removeHoliday

public void removeHoliday(java.util.Date date,
                          boolean annual)
Removes a holiday from the calendar.

Parameters:
date - the date at which the holiday is located
annual - determines whether the holiday is a floating or an annual holiday
Since:
1.0
See Also:
removeHoliday(Calendar, boolean), removeHoliday(long, boolean)

removeHoliday

public void removeHoliday(java.util.Calendar calendar,
                          boolean annual)
Removes a holiday from the calendar.

Parameters:
calendar - the time at which the holiday is located
annual - determines whether the holiday is a floating or an annual holiday
Since:
1.0
See Also:
removeHoliday(long, boolean), removeHoliday(Date, boolean)

getHolidays

public java.util.Date[] getHolidays(boolean annual)
Returns the holidays that are defined in the model.

Parameters:
annual - determines whether the method will return the annual or the floating holidays
Returns:
an array of the currently defined holidays
Since:
1.0

isHoliday

public boolean isHoliday(java.util.Calendar calendar,
                         boolean annual)
Determines whether the given calendar object represents a holiday.

Parameters:
calendar - the calendar object that will be checked
annual - if TRUE the calendar object will be checked for annual holiday
Returns:
TRUE if the given calendar object represents a holiday
Since:
1.0

isHoliday

public boolean isHoliday(java.util.Date date,
                         boolean annual)
Determines whether the given date object represents a holiday.

Parameters:
date - the date object that will be checked
annual - if TRUE the date object will be checked for annual holiday
Returns:
TRUE if the given date object represents a holiday
Since:
1.0

fireCalendarModelChanged

protected void fireCalendarModelChanged()
Description copied from class: AbstractCalendarModel
Informs all listeners that the calendar model has been changed (e.g. a holiday has been added).

Overrides:
fireCalendarModelChanged in class AbstractCalendarModel<T extends IGanttChartNode,S extends AbstractCalendarEntry>