001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/calendar/tags/sakai_2-4-1/calendar-tool/tool/src/java/org/sakaiproject/calendar/tool/CalendarActionState.java $
003: * $Id: CalendarActionState.java 8050 2006-04-20 17:39:55Z ggolden@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.calendar.tool;
021:
022: import java.util.HashMap;
023: import java.util.Iterator;
024: import java.util.List;
025: import java.util.Map;
026: import java.util.Set;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030: import org.sakaiproject.calendar.api.CalendarEventEdit;
031: import org.sakaiproject.cheftool.ControllerState;
032: import org.sakaiproject.entity.cover.EntityManager;
033: import org.sakaiproject.site.api.Site;
034: import org.sakaiproject.util.CalendarUtil;
035: import org.sakaiproject.tool.api.SessionBindingEvent;
036: import org.sakaiproject.tool.api.SessionBindingListener;
037:
038: /**
039: * Maintains user interface state for the MyCalendar action class.
040: */
041: public class CalendarActionState extends ControllerState implements
042: SessionBindingListener {
043: /** Our logger. */
044: private static Log M_log = LogFactory
045: .getLog(CalendarActionState.class);
046:
047: private List wizardImportedEvents;
048:
049: private String importWizardType;
050:
051: private String importWizardState;
052:
053: private CalendarFilter calendarFilter = new CalendarFilter();
054:
055: private int m_currentday;
056: private String eventId = "";
057: private String selectedCalendarReference = "";
058: private int m_currentyear;
059: private int m_currentmonth;
060:
061: private boolean m_isNewCal = true;
062:
063: // this attachment list is never set to null!
064: private List m_attachments = EntityManager.newReferenceList();
065: private int m_newday;
066:
067: private String m_nextDate = "";
068: private String m_prevDate = "";
069: private CalendarUtil m_scalObj;
070: private String m_primaryCalendarReference = null;
071: private String PrevState = "";
072:
073: private String m_AttachmentFlag = "false";
074: private LocalEvent savedData = new LocalEvent();
075: private boolean m_IsPastAlertOff = true;
076:
077: private boolean m_DelfieldAlertOff = true;
078:
079: private String m_state = "";
080: private String currentpage = "second";
081:
082: private String m_returnState;
083: private CalendarEventEdit m_primaryCalendarEdit;
084:
085: private String m_addfields = "";
086:
087: public String getAddfields() {
088: return m_addfields;
089: }
090:
091: public String getState() {
092: return m_state;
093: }
094:
095: public void setState(String state) {
096: m_state = state;
097: }
098:
099: public String getReturnState() {
100: return m_returnState;
101: }
102:
103: public void setReturnState(String returnState) {
104: m_returnState = returnState;
105: }
106:
107: /**
108: * Get edit The edit object
109: */
110: public void setPrimaryCalendarEdit(CalendarEventEdit edit) {
111: m_primaryCalendarEdit = edit;
112: }
113:
114: /**
115: * Get edit object
116: * @return m_edit The edit object
117: */
118: public CalendarEventEdit getPrimaryCalendarEdit() {
119: return m_primaryCalendarEdit;
120: }
121:
122: public void setCurrentPage(String page) {
123: currentpage = page;
124: }
125:
126: public String getCurrentPage() {
127: return currentpage;
128: }
129:
130: public String getfromAttachmentFlag() {
131: return m_AttachmentFlag;
132: }
133:
134: public void setfromAttachmentFlag(String flag) {
135: m_AttachmentFlag = flag;
136: }
137:
138: /**
139: * Get
140: */
141: public List getAttachments() {
142:
143: return m_attachments;
144:
145: } // getAttachment
146:
147: /**
148: * Set
149: */
150: public void setAttachments(List attachments) {
151: if (attachments != null) {
152: m_attachments = EntityManager.newReferenceList(attachments);
153: } else {
154: m_attachments.clear();
155: }
156: } // setAttachments
157:
158: /**
159: * Get the status of preview: true - view new created; false - view revised existed
160: * @return The current status
161: */
162: public boolean getIsNewCalendar() {
163: return m_isNewCal;
164:
165: } // gsetIsCalendar
166:
167: /**
168: * Set the status of preview: true - view new created; false - view revised existed
169: * @param preview_status The status of preview: true - view new created; false - view revised existed
170: */
171: public void setIsNewCalendar(boolean isNewcal) {
172: // if there's a change
173: if (isNewcal != m_isNewCal) {
174: // remember the new
175: m_isNewCal = isNewcal;
176: }
177:
178: } // setIsNewCalendar
179:
180: /**
181: * Get the status of past alert off: true - no alert shown; false - alert shown
182: * @return IsPastAlertOff
183: */
184: public boolean getIsPastAlertOff() {
185: return m_IsPastAlertOff;
186:
187: } // getIsPastAlertOff
188:
189: /**
190: * Get the status of delfield alert off: true - no alert shown; false - alert shown
191: * @return DelfieldAlertOff
192: */
193: public boolean getDelfieldAlertOff() {
194: return m_DelfieldAlertOff;
195:
196: } // getDelfieldAlertOff
197:
198: /**
199: * Gets the main calendar ID associated with the event list. Many calendars may be merged into this list, but there is only one one calendar that is used for adding/modifying events.
200: */
201: public String getPrimaryCalendarReference() {
202: return m_primaryCalendarReference;
203: }
204:
205: /**
206: * Set the status of past alert off: true - no alert shown; false - alert shown
207: * @param IsPastAlertOff The status of past alert off: true - no alert shown; false - alert shown
208: */
209: public void setIsPastAlertOff(boolean IsPastAlertOff) {
210: m_IsPastAlertOff = IsPastAlertOff;
211:
212: } // setIsPastAlertOff
213:
214: /**
215: * Set the status of delfield alert off: true - no alert shown; false - alert shown
216: * @param DelfieldAlertOff The status of delfield alert off: true - no alert shown; false - alert shown
217: */
218: public void setDelfieldAlertOff(boolean DelfieldAlertOff) {
219: m_DelfieldAlertOff = DelfieldAlertOff;
220:
221: } // setDelfieldAlertOff
222:
223: /**
224: * Sets the main calendar ID associated with the event list. Many calendars may be merged into this
225: * list, but there is only one one calendar that is used for adding/modifying events/
226: */
227: public void setPrimaryCalendarReference(String reference) {
228: m_primaryCalendarReference = reference;
229: }
230:
231: public void setCalendarEventId(String calendarReference,
232: String eventId) {
233: this .eventId = eventId;
234: setSelectedCalendarReference(calendarReference);
235: }
236:
237: public String getCalendarEventId() {
238: return eventId;
239: }
240:
241: public void setNewData(String calendarReference, String title,
242: String description, int month, int day, String year,
243: int hour, int minute, int dhour, int dminute, String type,
244: String Am, String location, Map addfieldsMap,
245: String intentionStr) {
246: savedData = new LocalEvent();
247: savedData.setData(calendarReference, title, description, month,
248: day, year, hour, minute, dhour, dminute, type, Am,
249: location, addfieldsMap, intentionStr);
250: }
251:
252: public void clearData() {
253: savedData = new LocalEvent();
254: }
255:
256: public LocalEvent getNewData() {
257: return savedData;
258: }
259:
260: public void setcurrentDate(int currentday) {
261: m_currentday = currentday;
262: }
263:
264: public int getcurrentDate() {
265: return m_currentday;
266: }
267:
268: public void setnewDate(int newday) {
269: m_newday = newday;
270: }
271:
272: public int getnewDate() {
273: return m_newday;
274: }
275:
276: public void setnextDate(String nextDate) {
277: m_nextDate = nextDate;
278: }
279:
280: public String getnextDate() {
281: return m_nextDate;
282: }
283:
284: public void setprevDate(String prevDate) {
285: m_prevDate = prevDate;
286: }
287:
288: public String getprevDate() {
289: return m_prevDate;
290: }
291:
292: public CalendarUtil getCalObj() {
293: return m_scalObj;
294: }
295:
296: public void setCalObj(CalendarUtil calObj) {
297: m_scalObj = calObj;
298: }
299:
300: public void setPrevState(String state) {
301: PrevState = state;
302: }
303:
304: public String getPrevState() {
305: return PrevState;
306: }
307:
308: public void setcurrentDay(int currentday) {
309: m_currentday = currentday;
310: }
311:
312: public void setcurrentMonth(int currentmonth) {
313: m_currentmonth = currentmonth;
314: }
315:
316: public void setcurrentYear(int currentyear) {
317: m_currentyear = currentyear;
318: }
319:
320: public int getcurrentDay() {
321: return m_currentday;
322: }
323:
324: public int getcurrentMonth() {
325: return m_currentmonth;
326: }
327:
328: public int getcurrentYear() {
329: return m_currentyear;
330: }
331:
332: public CalendarActionState() {
333: init();
334: }
335:
336: /* (non-Javadoc)
337: * @see org.chefproject.core.ControllerState#recycle()
338: */
339: public void recycle() {
340: super .recycle();
341: init();
342:
343: } // recycle
344:
345: /* (non-Javadoc)
346: * @see org.chefproject.core.ControllerState#init()
347: */
348: protected void init() {
349: m_state = "week";
350: m_scalObj = new CalendarUtil();
351: m_currentday = m_scalObj.getDayOfMonth();
352: m_currentyear = m_scalObj.getYear();
353: m_currentmonth = m_scalObj.getMonthInteger();
354:
355: calendarFilter.setListViewDateRangeToDefault();
356: }
357:
358: /* (non-Javadoc)
359: * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
360: */
361: public void update(java.util.Observable observable,
362: java.lang.Object obj) {
363: }
364:
365: /**
366: * Used in the MyCalendar action and associated Velocity templates to store
367: * a single calendar event in an arbitrary calendar, not necessary the current
368: * primary calendar.
369: */
370: public class LocalEvent {
371: private String title;
372: private String description;
373: private int month;
374: private String year;
375: private int day;
376: private int hour;
377: private int minute;
378: private int durationHour;
379: private int durationMinute;
380: private String type;
381: private String am;
382: private String location;
383: private String calendarReference;
384: private String intentionStr;
385:
386: // This is a map of additional properties. These are dynamic and not like title, location, etc.
387: private Map addFieldsMap;
388:
389: /**
390: * Default constructor
391: */
392: public LocalEvent() {
393: title = null;
394: description = null;
395: month = 0;
396: day = 0;
397: year = "0";
398: hour = 0;
399: minute = -1;
400: durationHour = -1;
401: durationMinute = -1;
402: type = null;
403: am = null;
404: location = "";
405: calendarReference = null;
406: addFieldsMap = new HashMap();
407: intentionStr = "";
408: }
409:
410: /**
411: * @param fieldsMap Map of additional properties
412: */
413: public void setData(String calendarReference, String title,
414: String description, int month, int day, String year,
415: int hour, int minute, int dhour, int dminute,
416: String type, String am, String location, Map fieldsMap,
417: String intentionStr) {
418: this .title = title;
419: this .description = description;
420: this .month = month;
421: this .day = day;
422: this .year = year;
423: this .hour = hour;
424: this .minute = minute;
425: this .durationHour = dhour;
426: this .durationMinute = dminute;
427: this .type = type;
428: this .am = am;
429: this .location = location;
430: this .calendarReference = calendarReference;
431: this .addFieldsMap = fieldsMap;
432: this .intentionStr = intentionStr;
433: }
434:
435: public String getTitle() {
436: return title;
437: }
438:
439: public String getDescription() {
440: return description;
441: }
442:
443: public int getMonth() {
444: return month;
445: }
446:
447: public int getDay() {
448: return day;
449: }
450:
451: public String getYear() {
452: return year;
453: }
454:
455: public int getYearInt() {
456: return new Integer(year).intValue();
457: }
458:
459: public int getHour() {
460: return hour;
461: }
462:
463: public int getMinute() {
464: return minute;
465: }
466:
467: public int getDurationHour() {
468: return durationHour;
469: }
470:
471: public int getDurationMinute() {
472: return durationMinute;
473: }
474:
475: public String getType() {
476: return type;
477: }
478:
479: public String getAm() {
480: return am;
481: }
482:
483: public String getLocation() {
484: return location;
485: }
486:
487: /**
488: * Gets the value for one of the additional attribute fields.
489: */
490: public String getAddfieldValue(String fieldname) {
491: Set addfieldsKey = addFieldsMap.keySet();
492:
493: Iterator it = addfieldsKey.iterator();
494: String prop_name = "";
495: String prop_value = "";
496:
497: while (it.hasNext()) {
498: prop_name = (String) it.next();
499: if (prop_name.equals(fieldname)) {
500: prop_value = (String) addFieldsMap.get(prop_name);
501: return prop_value;
502: }
503: }
504: return prop_value;
505: }
506:
507: public String getIntentionStr() {
508: return intentionStr;
509: } // getIntentionStr
510:
511: } // localEvent
512:
513: /**
514: * Gets the currently selected calendar.
515: */
516: public String getSelectedCalendarReference() {
517: return selectedCalendarReference;
518: }
519:
520: /**
521: * Sets the currently selected calendar.
522: */
523: public void setSelectedCalendarReference(String string) {
524: selectedCalendarReference = string;
525: }
526:
527: /**
528: * Returns the calendar filter that is currently being used for the list
529: * view and printing.
530: */
531: public CalendarFilter getCalendarFilter() {
532: return calendarFilter;
533: }
534:
535: public void setImportWizardState(String importWizardState) {
536: this .importWizardState = importWizardState;
537: }
538:
539: public String getImportWizardState() {
540: return importWizardState;
541: }
542:
543: public void setImportWizardType(String importWizardType) {
544: this .importWizardType = importWizardType;
545: }
546:
547: public String getImportWizardType() {
548: return importWizardType;
549: }
550:
551: public void setWizardImportedEvents(List wizardImportedEvents) {
552: this .wizardImportedEvents = wizardImportedEvents;
553: }
554:
555: public List getWizardImportedEvents() {
556: return wizardImportedEvents;
557: }
558:
559: private Site m_editSite;
560: private CalendarEventEdit m_edit;
561:
562: /**
563: * Set edit The canlender event edit object
564: */
565: public void setEdit(CalendarEventEdit edit) {
566: m_edit = edit;
567: }
568:
569: /*******************************************************************************
570: * SessionBindingListener implementation
571: *******************************************************************************/
572:
573: public void valueBound(SessionBindingEvent event) {
574: }
575:
576: public void valueUnbound(SessionBindingEvent event) {
577: if (M_log.isDebugEnabled())
578: M_log.debug("valueUnbound()");
579:
580: // pass it on to my edits
581: if ((m_editSite != null)
582: && (m_editSite instanceof SessionBindingListener)) {
583: ((SessionBindingListener) m_editSite).valueUnbound(event);
584: }
585:
586: if ((m_edit != null)
587: && (m_edit instanceof SessionBindingListener)) {
588: ((SessionBindingListener) m_edit).valueUnbound(event);
589: }
590:
591: } // valueUnbound
592:
593: } // class CalendarActionState
|