001: package com.sun.portal.wireless.taglibs.cal;
002:
003: import com.sun.comclient.calendar.VEvent;
004: import com.sun.comclient.calendar.RecurrencePattern;
005:
006: public class EventBean extends SchedulingBean implements Comparable {
007:
008: private VEvent theEvent;
009: private String recurrenceModifier;
010:
011: public EventBean(VEvent event) {
012: super (event);
013: this .theEvent = event;
014: }
015:
016: public VEvent getEvent() {
017: return theEvent;
018: }
019:
020: /**
021: * Get the Event Location.
022: * <br><br>
023: *
024: * @return location of this event
025: */
026: public String getLocation() throws Exception {
027: return theEvent.getLocation();
028: }
029:
030: /**
031: * Set the Event Location.
032: * <br><br>
033: *
034: * @param location location of this event
035: */
036: public void setLocation(String location) throws Exception {
037: theEvent.setLocation(location);
038: }
039:
040: /**
041: * Test is the event is all day or not.
042: * <br><br>
043: *
044: * @return True if the event is all day.
045: */
046: public boolean isAllDay() throws Exception {
047: if (theEvent.getStart() != null) {
048: return theEvent.isAllDay();
049: }
050: return true;
051: }
052:
053: /**
054: * Sets whether the event is all day or not.
055: * <br><br>
056: *
057: * @param allday True if the event is all day.
058: */
059: public void setAllDay(boolean allday) throws Exception {
060: theEvent.setAllDay(allday);
061: }
062:
063: /**
064: * Gets if this calendarId is same as the Organizer's(it's calId)
065: * Used to identify if this guy is the organizer or an attendee
066: * @return true if the organizer's calid and this calenadrId are same
067: * false otherwise
068: *
069: *TBD#4510789 needs to be fixed for pimAdapter
070: */
071: public boolean isCalIdTheOrganizer() throws Exception {
072: boolean result = true;
073: if (!isNew()) {
074: String calId = theEvent.getCalID();
075: result = theEvent.isCalIdTheOrganizer(calId);
076: }
077: return result;
078: }
079:
080: /**
081: * Returns whether the theEvent is part of a recurrence.
082: * <br><br>
083: *
084: * @return true if the theEvent repeats
085: */
086: public boolean isRecurrence() throws Exception {
087: return theEvent.isRecurring();
088: }
089:
090: /**
091: * Returns the recurrence pattern for this theEvent.
092: * <br><br>
093: *
094: * @return the first recurrence pattern object,
095: * null if does not exist
096: */
097: public RecurrencePattern getRecurrencePattern() throws Exception {
098: if (theEvent.getRecurrenceRules() != null
099: && theEvent.getRecurrenceRules().length > 0) {
100: return theEvent.getRecurrenceRules()[0];
101: }
102: return null;
103: }
104:
105: /**
106: * Set the recurrence pattern for this theEvent.
107: * Beware: Removes all the existing rules
108: * and sets this rule as the first one
109: * <br><br>
110: *
111: * @param rPattern recurrence pattern for this theEvent
112: */
113: public void setRecurrencePattern(RecurrencePattern rPattern)
114: throws Exception {
115: //Presently we are supporting only one recurrenceRule from our GUI
116: RecurrencePattern[] rules = theEvent.getRecurrenceRules();
117: if (rules != null && rules.length > 0) {
118: theEvent.removeAllRecurrenceRules();
119: }
120: theEvent.addRecurrenceRule(rPattern);
121: }
122:
123: /**
124: * Gets the recurrenceModifier option set in the Event
125: * Used while updating this event.
126: * @return the string value of the recurrenceModifier
127: * that has been set before.
128: */
129:
130: public String getRecurrenceModifier() {
131: return recurrenceModifier;
132: }
133:
134: /**
135: * Gets the recurrenceModifier option set in the Event
136: * Used while updating this event.
137: * @return the string value of the recurrenceModifier
138: * that has been set before.
139: */
140: public String getModifier() {
141: return getRecurrenceModifier();
142: }
143:
144: /**
145: * Sets the recurrenceModifier option in the Event
146: * Used while updating this event.
147: * @param the string value of the recurrenceModifier
148: * that needs to be set.
149: */
150: public void setRecurrenceModifier(String mod) {
151: recurrenceModifier = mod;
152: ;
153: }
154:
155: /**
156: * Sets the recurrenceModifier option in the Event
157: * Used while updating this event.
158: * @param the string value of the recurrenceModifier
159: * that needs to be set.
160: */
161: public void setModifier(String mod) {
162: setRecurrenceModifier(mod);
163: }
164:
165: /**
166: * Test is the event has conflicting event
167: * This just checks for the property isConflict exist and if it is true
168: *
169: * <br><br>
170: *
171: * @return True if the event is conflict
172: */
173: public boolean isConflict() {
174: boolean conflicted = false;
175: if (theEvent.hasProperty("isConflict")) {
176: conflicted = new Boolean((String) theEvent
177: .getProperty("isConflict")).booleanValue();
178: }
179: return conflicted;
180: }
181:
182: /**
183: * Sets weather the event is conflict
184: * Invoked by Fetch to set it
185: * <br><br>
186: *
187: * @param conflict True if the event is conflict.
188: */
189: public void setConflict(boolean conflict) {
190: theEvent.setProperty("isConflict", String.valueOf(conflict));
191: }
192:
193: /**
194: * This is requied for comparable
195: */
196:
197: public int compareTo(Object o) {
198: int result = -1;
199: try {
200: if (o instanceof EventBean) {
201: EventBean eventObj = (EventBean) o;
202: if (getStart().before(eventObj.getStart())) {
203: result = -1;
204: //When returns 0 , TreeSet does not add to the Collection
205: } else {
206: result = 1;
207: }
208: }
209: } catch (Exception ex) {
210: ex.printStackTrace();
211: }
212: return result;
213: }
214:
215: }
|