001: /*--------------------------------------------------------------------------*
002: | Copyright (C) 2006 Christopher Kohlhaas |
003: | |
004: | This program is free software; you can redistribute it and/or modify |
005: | it under the terms of the GNU General Public License as published by the |
006: | Free Software Foundation. A copy of the license has been included with |
007: | these distribution in the COPYING file, if not go to www.fsf.org |
008: | |
009: | As a special exception, you are granted the permissions to link this |
010: | program with every library, which license fulfills the Open Source |
011: | Definition as published by the Open Source Initiative (OSI). |
012: *--------------------------------------------------------------------------*/
013: package org.rapla.plugin.periodview;
014:
015: import java.util.Calendar;
016: import java.util.Date;
017: import java.util.Iterator;
018: import java.util.Set;
019:
020: import org.rapla.components.calendarview.Block;
021: import org.rapla.components.calendarview.html.AbstractHTMLView;
022: import org.rapla.components.calendarview.html.HTMLPeriodView;
023: import org.rapla.components.util.DateTools;
024: import org.rapla.entities.domain.Period;
025: import org.rapla.facade.PeriodModel;
026: import org.rapla.framework.RaplaContext;
027: import org.rapla.framework.RaplaException;
028: import org.rapla.gui.CalendarModel;
029: import org.rapla.gui.CalendarOptions;
030: import org.rapla.plugin.abstractcalendar.AbstractHTMLCalendarPage;
031: import org.rapla.plugin.abstractcalendar.AbstractRaplaBlock;
032: import org.rapla.plugin.abstractcalendar.GroupAllocatablesStrategy;
033: import org.rapla.plugin.abstractcalendar.RaplaBuilder;
034:
035: public class HTMLPeriodViewPage extends AbstractHTMLCalendarPage {
036: public HTMLPeriodViewPage(RaplaContext context,
037: CalendarModel calendarModel) throws RaplaException {
038: super (context, calendarModel);
039: }
040:
041: protected AbstractHTMLView createCalendarView() {
042: HTMLPeriodView periodView = new HTMLPeriodView() {
043: public Block sameAppointment(int day, Block bl) {
044: Iterator it2 = slots[day].iterator();
045: Block b;
046: while (it2.hasNext()) {
047: b = (Block) it2.next();
048: if (((AbstractRaplaBlock) b).getAppointment() == ((AbstractRaplaBlock) bl)
049: .getAppointment()) {
050: return b;
051: }
052: }
053: return null;
054: }
055: };
056: CalendarOptions opt = getCalendarOptions();
057: Set excludeDays = opt.getExcludeDays();
058:
059: periodView.setExcludeDays(excludeDays);
060: periodView.setLocale(getRaplaLocale().getLocale());
061: periodView.setTimeZone(getRaplaLocale().getTimeZone());
062:
063: Date start = model.getStartDate();
064: Date end = model.getEndDate();
065: Date selectedDate = model.getSelectedDate();
066: PeriodModel periodModel = getPeriodModel();
067: Period selectedPeriod = periodModel
068: .getNearestPeriodForStartDate(start, end);
069:
070: /*
071: * If the user does not change the start date then
072: * the choosen period is displayed.
073: * If the user choose another date, then 7 weeks are displayed.
074: */
075: if (start == null) {
076: start = getQuery().today();
077: end = DateTools.addDays(start, 7 * 7);
078: } else {
079: if (selectedPeriod == null
080: || selectedPeriod.getStart().getTime() != selectedDate
081: .getTime()) {
082: end = DateTools.addDays(selectedDate, 7 * 7);
083: } else {
084: start = selectedPeriod.getStart();
085: end = selectedPeriod.getEnd();
086: }
087: }
088:
089: periodView.setToDate(start);
090: periodView.setEndDate(end);
091:
092: return periodView;
093: }
094:
095: protected RaplaBuilder createBuilder() throws RaplaException {
096: RaplaBuilder builder = super .createBuilder();
097:
098: GroupAllocatablesStrategy strategy = new GroupAllocatablesStrategy(
099: getRaplaLocale().getLocale());
100: boolean compactColumns = getCalendarOptions()
101: .isCompactColumns()
102: || builder.getAllocatables().size() == 0;
103: strategy.setFixedSlotsEnabled(!compactColumns);
104: builder.setBuildStrategy(strategy);
105:
106: return builder;
107: }
108:
109: protected int getIncrementSize() {
110: return Calendar.WEEK_OF_YEAR;
111: }
112:
113: }
|