KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > calendar > ui > base > CalendarHelper


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//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().getTimeInMillis();
37         long endMillis = model.getEvent().getDtEnd().getTimeInMillis();
38         
39         ImmutableDateRange dr = new ImmutableDateRange(startMillis, endMillis,
40                 false, null, null);
41
42         // A recurring event
43
Activity act = new DefaultActivity(dr, model.getId());
44         act.setSummary(model.getEvent().getSummary());
45         act.setLocation(model.getEvent().getLocation());
46         act.setDescription(model.getEvent().getDescription());
47         IRecurrence columbaRecurrence = model.getEvent().getRecurrence();
48         if (columbaRecurrence != null && columbaRecurrence.getType() != IRecurrence.RECURRENCE_NONE) {
49             RecurrenceRule r = new RecurrenceRule();
50             r.setFrequency(Recurrence.toFrequency(columbaRecurrence.getType()));
51             r.setInterval(columbaRecurrence.getInterval());
52             if (columbaRecurrence.getEndType() == IRecurrence.RECURRENCE_END_MAXOCCURRENCES)
53                 r.setRepetitionCount(columbaRecurrence.getEndMaxOccurrences());
54             if (columbaRecurrence.getEndType() == IRecurrence.RECURRENCE_END_ENDDATE)
55                 r.setUntilDate(columbaRecurrence.getEndDate());
56             act.setRecurrence(r);
57         }
58                 
59         String JavaDoc calendar = model.getCalendar();
60         // this is for the calendar component and only used internally
61
act.setCategoryIDs(new Object JavaDoc[] { calendar });
62         
63         return act;
64     }
65
66     public static void updateDateRange(final Activity activity, IEvent model) {
67         DateRangeI dateRange = activity.getDateRangeForReading();
68         DateRange cRange = new DateRange(dateRange.getStartMillis(), dateRange
69                 .getEndMillis(false));
70
71         model.setDtStart(cRange.getStartTime());
72         model.setDtEnd(cRange.getEndTime());
73
74     }
75
76 }
77
Popular Tags