01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //limitations under the License.
10: //
11: //The Original Code is "The Columba Project"
12: //
13: //The Initial Developers of the Original Code are Frederik Dietz and Timo
14: // Stich.
15: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16: //
17: //All Rights Reserved.
18: package org.columba.calendar.ui.base;
19:
20: import org.columba.calendar.model.DateRange;
21: import org.columba.calendar.model.Recurrence;
22: import org.columba.calendar.model.api.IEvent;
23: import org.columba.calendar.model.api.IEventInfo;
24: import org.columba.calendar.model.api.IRecurrence;
25:
26: import com.miginfocom.calendar.activity.Activity;
27: import com.miginfocom.calendar.activity.DefaultActivity;
28: import com.miginfocom.calendar.activity.recurrence.RecurrenceRule;
29: import com.miginfocom.util.dates.DateRangeI;
30: import com.miginfocom.util.dates.ImmutableDateRange;
31:
32: public class CalendarHelper {
33:
34: public static Activity createActivity(IEventInfo model) {
35:
36: long startMillis = model.getEvent().getDtStart()
37: .getTimeInMillis();
38: long endMillis = model.getEvent().getDtEnd().getTimeInMillis();
39:
40: ImmutableDateRange dr = new ImmutableDateRange(startMillis,
41: endMillis, false, null, null);
42:
43: // A recurring event
44: Activity act = new DefaultActivity(dr, model.getId());
45: act.setSummary(model.getEvent().getSummary());
46: act.setLocation(model.getEvent().getLocation());
47: act.setDescription(model.getEvent().getDescription());
48: IRecurrence columbaRecurrence = model.getEvent()
49: .getRecurrence();
50: if (columbaRecurrence != null
51: && columbaRecurrence.getType() != IRecurrence.RECURRENCE_NONE) {
52: RecurrenceRule r = new RecurrenceRule();
53: r.setFrequency(Recurrence.toFrequency(columbaRecurrence
54: .getType()));
55: r.setInterval(columbaRecurrence.getInterval());
56: if (columbaRecurrence.getEndType() == IRecurrence.RECURRENCE_END_MAXOCCURRENCES)
57: r.setRepetitionCount(columbaRecurrence
58: .getEndMaxOccurrences());
59: if (columbaRecurrence.getEndType() == IRecurrence.RECURRENCE_END_ENDDATE)
60: r.setUntilDate(columbaRecurrence.getEndDate());
61: act.setRecurrence(r);
62: }
63:
64: String calendar = model.getCalendar();
65: // this is for the calendar component and only used internally
66: act.setCategoryIDs(new Object[] { calendar });
67:
68: return act;
69: }
70:
71: public static void updateDateRange(final Activity activity,
72: IEvent model) {
73: DateRangeI dateRange = activity.getDateRangeForReading();
74: DateRange cRange = new DateRange(dateRange.getStartMillis(),
75: dateRange.getEndMillis(false));
76:
77: model.setDtStart(cRange.getStartTime());
78: model.setDtEnd(cRange.getEndTime());
79:
80: }
81:
82: }
|