KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > business > calendar > struts > IndexForm


1 /*
2  * Copyright (c) 2001 - 2005 ivata limited.
3  * All rights reserved.
4  * -----------------------------------------------------------------------------
5  * ivata groupware may be redistributed under the GNU General Public
6  * License as published by the Free Software Foundation;
7  * version 2 of the License.
8  *
9  * These programs are free software; you can redistribute them and/or
10  * modify them under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; version 2 of the License.
12  *
13  * These programs are distributed in the hope that they will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License in the file LICENSE.txt for more
18  * details.
19  *
20  * If you would like a copy of the GNU General Public License write to
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place - Suite 330
24  * Boston, MA 02111-1307, USA.
25  *
26  *
27  * To arrange commercial support and licensing, contact ivata at
28  * http://www.ivata.com/contact.jsp
29  * -----------------------------------------------------------------------------
30  * $Log: IndexForm.java,v $
31  * Revision 1.3 2005/04/10 20:43:44 colinmacleod
32  * Added new themes.
33  * Changed id type to String.
34  * Changed i tag to em and b tag to strong.
35  * Improved PicoContainerFactory with NanoContainer scripts.
36  *
37  * Revision 1.2 2005/04/09 17:19:18 colinmacleod
38  * Changed copyright text to GPL v2 explicitly.
39  *
40  * Revision 1.1.1.1 2005/03/10 17:47:44 colinmacleod
41  * Restructured ivata op around Hibernate/PicoContainer.
42  * Renamed ivata groupware.
43  *
44  * Revision 1.6 2004/11/12 18:19:14 colinmacleod
45  * Change action and form classes to extend MaskAction, MaskForm respectively.
46  *
47  * Revision 1.5 2004/11/03 15:49:51 colinmacleod
48  * Changed todo comments to TODO: all caps.
49  *
50  * Revision 1.4 2004/07/13 19:42:14 colinmacleod
51  * Moved project to POJOs from EJBs.
52  * Applied PicoContainer to services layer (replacing session EJBs).
53  * Applied Hibernate to persistence layer (replacing entity EJBs).
54  *
55  * Revision 1.3 2004/03/21 21:16:22 colinmacleod
56  * Shortened name to ivata op.
57  *
58  * Revision 1.2 2004/02/01 22:07:29 colinmacleod
59  * Added full names to author tags
60  *
61  * Revision 1.1.1.1 2004/01/27 20:58:22 colinmacleod
62  * Moved ivata openportal to SourceForge..
63  *
64  * Revision 1.2 2003/10/15 13:57:23 colin
65  * fixing for XDoclet
66  *
67  * Revision 1.2 2003/04/14 12:31:04 peter
68  * removed helpKey field - it is inherited
69  *
70  * Revision 1.1 2003/02/24 19:09:22 colin
71  * moved to business
72  *
73  * Revision 1.2 2003/02/13 08:45:42 colin
74  * conversion to Struts/popups
75  *
76  * Revision 1.1 2003/02/04 17:50:17 colin
77  * first version in CVS
78  *
79  * Revision 1.1 2003/02/04 17:41:16 colin
80  * first version in CVS
81  * -----------------------------------------------------------------------------
82  */

83 package com.ivata.groupware.business.calendar.struts;
84
85 import java.util.GregorianCalendar JavaDoc;
86 import java.util.Map JavaDoc;
87 import java.util.Vector JavaDoc;
88
89 import javax.servlet.http.HttpServletRequest JavaDoc;
90 import javax.servlet.http.HttpSession JavaDoc;
91
92 import org.apache.struts.action.ActionMapping;
93
94 import com.ivata.groupware.admin.setting.SettingsDataTypeException;
95 import com.ivata.groupware.admin.setting.SettingsInitializationException;
96 import com.ivata.groupware.util.SettingDateFormatter;
97 import com.ivata.mask.Mask;
98 import com.ivata.mask.validation.ValidationErrors;
99 import com.ivata.mask.web.format.DateFormatterConstants;
100 import com.ivata.mask.web.format.DateFormatterException;
101 import com.ivata.mask.web.struts.DialogForm;
102
103
104 /**
105  * <p>This form contains parameters for the main calendar list.</p>
106  *
107  * @since 2003-02-01
108  * @author Colin MacLeod
109  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
110  * @version $Revision: 1.3 $
111  *
112  */

113 public class IndexForm extends DialogForm {
114     /**
115      * <p>For week and day view, stores a <code>Vector</code> of all day
116      * events. This is not used in month and year views.</p>
117      */

118     private Vector JavaDoc[] allDayEvents;
119     /**
120      * <p>Specifies the current day being viewed.</p>
121      */

122     private GregorianCalendar JavaDoc currentDay = new GregorianCalendar JavaDoc();
123     /**
124      * <p>
125      * Used to format and display only the date part of an event.
126      * </p>
127      */

128     private SettingDateFormatter dateFormatter;
129     /**
130      * <p>
131      * Used to format and display date and time parts of an event.
132      * </p>
133      */

134     private SettingDateFormatter dateTimeFormatter;
135     /**
136      * <p>Last hour of the day to show in the day view.</p>
137      */

138     private int dayFinishHour = 17;
139     /**
140      * <p>First hour of the day to show in the day view.</p>
141      */

142     private int dayStartHour = 8;
143     /**
144      * <p>For week and day views, contains events for day view which are
145      * not all day events, indexed by hour.</p>
146      *
147      * <p>For month views, contains all events for each day, indexed by
148      * day. There will be as many elements of the array as there are weeks
149      * in the month.</p>
150      *
151      * <p>Each element of each <code>Map</code> is a sorted
152      * <code>TreeSet</code> which uses <code>EventHourComparator</code> to
153      * sort.</p>
154      */

155     private Map JavaDoc[] events = null;
156     /**
157      * <p>This attribute is used in week views to determine the date of
158      * the first day to be shown.</p>
159      */

160     private GregorianCalendar JavaDoc firstWeekDay = null;
161     /**
162      * <p>
163      * Used to format and display only the time part of an event.
164      * </p>
165      */

166     private SettingDateFormatter timeFormatter;
167
168     /**
169      * <p>Represents the current view type, set to one of the constants in
170      * {@link IndexFormConstants IndexFormConstants}. If unset, defaults
171      * to
172      * the settings <code>calendarDefaultView</code>.</p>
173      */

174     private Integer JavaDoc view = null;
175     /**
176      * <p>Path of the page to include which will show the current view.</p>
177      */

178     private String JavaDoc viewPage = null;
179     /**
180      * <p>
181      * Defines the base class of all objects in the value object list.
182      * </p>
183      */

184     private Class JavaDoc baseClass;
185     /**
186      * <p>
187      * Mask containing all the field definitions for this list.
188      * </p>
189      */

190     private Mask mask;
191     /**
192      * Construct an index form with the date formatters provided.
193      *
194      * @param dateFormatter used to format and display only the date part of an
195      * event.
196      * @param timeFormatter used to format and display only the time part of an
197      * event.
198      * @param dateTimeFormatter used to format and display date and time parts
199      * of an event.
200      * @param maskParam Refer to {@link DialogForm#DialogForm}.
201      * @param baseClassParam Refer to {@link DialogForm#DialogForm}.
202      */

203     public IndexForm(final SettingDateFormatter dateFormatter,
204             final SettingDateFormatter timeFormatter,
205             final SettingDateFormatter dateTimeFormatter)
206             throws SettingsDataTypeException, SettingsInitializationException {
207         this.dateFormatter = dateFormatter;
208         try {
209             dateFormatter.setDateTimeText("{0}");
210             dateFormatter.setDateFormat(DateFormatterConstants.DATE_LONG_DAY);
211             this.timeFormatter = timeFormatter;
212             timeFormatter.setDateTimeText("{1}");
213             timeFormatter.setTimeFormat(DateFormatterConstants.TIME_SHORT);
214             this.dateTimeFormatter = dateTimeFormatter;
215             dateFormatter.setDateFormat(DateFormatterConstants.DATE_SHORT);
216             timeFormatter.setTimeFormat(DateFormatterConstants.TIME_SHORT);
217         } catch (DateFormatterException e) {
218             throw new RuntimeException JavaDoc(e);
219         }
220     }
221
222     /**
223      * <p>
224      * Return all form state to initial values.
225      * </p>
226      *
227      * @see com.ivata.mask.web.struts.MaskForm#clear()
228      */

229     protected void clear() {
230         allDayEvents = null;
231         currentDay = new GregorianCalendar JavaDoc();
232         dayFinishHour = 17;
233         dayStartHour = 8;
234         events = null;
235         firstWeekDay = null;
236         view = null;
237         viewPage = null;
238     }
239
240     /**
241      * <p>Get the all day events to be shown for each day. In the day
242      * view, the array only contains one element - for the week views, it
243      * contains as many elements as there are days</p>
244      *
245      * @return all day events to be shown in the day view as a
246      * <code>Vector</code> of <code>EventDO</code> instances.
247      */

248     public final Vector JavaDoc[] getAllDayEvents() {
249         return allDayEvents;
250     }
251
252     /**
253      * <p>Specifies the current day being viewed.</p>
254      *
255      * @return the current value of currentDay.
256      */

257     public final GregorianCalendar JavaDoc getCurrentDay() {
258         return currentDay;
259     }
260     /**
261      * <p>
262      * Used to format and display only the date part of an event.
263      * </p>
264      *
265      * @return format and display only the date part of an event.
266      */

267     public final SettingDateFormatter getDateFormatter() {
268         return dateFormatter;
269     }
270
271     /**
272      * <p>
273      * Used to format and display date and time parts of an event.
274      * </p>
275      *
276      * @return format and display date and time parts of an event.
277      */

278     public final SettingDateFormatter getDateTimeFormatter() {
279         return dateTimeFormatter;
280     }
281
282     /**
283      * <p>Last hour of the day to show in the day view.</p>
284      *
285      * @return the current value of dayFinishHour.
286      */

287     public final int getDayFinishHour() {
288         return dayFinishHour;
289     }
290
291     /**
292      * <p>First hour of the day to show in the day view.</p>
293      *
294      * @return the current value of dayStartHour.
295      */

296     public final int getDayStartHour() {
297         return dayStartHour;
298     }
299
300     /**
301      * <p>For week and day views, contains events for day view which are
302      * not all day events, indexed by hour.</p>
303      *
304      * <p>For month views, contains all events for each day, indexed by
305      * day. There will be as many elements of the array as there are weeks
306      * in the month.</p>
307      *
308      * <p>Each element of each <code>Map</code> is a sorted
309      * <code>TreeSet</code> which uses <code>EventHourComparator</code> to
310      * sort.</p>
311      *
312      * @return current value of events.
313      */

314     public final Map JavaDoc[] getEvents() {
315         return events;
316     }
317
318     /**
319      * <p>This attribute is used in week views to determine the date of
320      * the first day to be shown.</p>
321      *
322      * @return the current value of firstWeekDay.
323      */

324     public final GregorianCalendar JavaDoc getFirstWeekDay() {
325         return firstWeekDay;
326     }
327
328     /**
329      * <p>
330      * Used to format and display only the time part of an event.
331      * </p>
332      *
333      * @return format and display only the time part of an event.
334      */

335     public final SettingDateFormatter getTimeFormatter() {
336         return timeFormatter;
337     }
338
339     /**
340      * <p>Represents the current view type, set to one of the constants in
341      * {@link IndexFormConstants IndexFormConstants}. If unset, defaults
342      * to
343      * the settings <code>calendarDefaultView</code>.</p>
344      *
345      * @return the current value of view.
346      */

347     public final Integer JavaDoc getView() {
348         return view;
349     }
350
351     /**
352      * <p>Path of the page to include which will show the current
353      * view.</p>
354      *
355      * @return the current value of viewPage.
356      */

357     public final String JavaDoc getViewPage() {
358         return viewPage;
359     }
360
361     /**
362      * <p>Reset all bean properties to their default state. This method
363      * is called before the properties are repopulated by the controller
364      * servlet.</p>
365      *
366      * @param calendar valid calendar remote instance.
367      * @param request The servlet request we are processing.
368      * @param session The servlet session we are processing.
369      *
370      */

371     public void reset(final ActionMapping mapping,
372             final HttpServletRequest JavaDoc request) {
373         // TODO: make this a setting
374
dayStartHour = 8;
375         dayFinishHour = 17;
376         allDayEvents = null;
377         events = null;
378     }
379
380     /**
381      * <p>Set the all day events to be shown for each day. In the day
382      * view, the array only contains one element - for the week views, it
383      * contains as many elements as there are days</p>
384      *
385      * @param allDayEvents all day events to be shown for each day as a
386      * <code>Vector</code> of <code>EventDO</code> instances.
387      */

388     public final void setAllDayEvents(final Vector JavaDoc[] allDayEvents) {
389         this.allDayEvents = allDayEvents;
390     }
391
392     /**
393      * <p>Specifies the current day being viewed.</p>
394      *
395      * @param currentDay the new value of currentDay.
396      */

397     public final void setCurrentDay(final GregorianCalendar JavaDoc currentDay) {
398         this.currentDay = currentDay;
399     }
400
401     /**
402      * <p>
403      * Used to format and display only the date part of an event.
404      * </p>
405      *
406      * @param formatter format and display only the date part of an event.
407      */

408     public final void setDateFormatter(final SettingDateFormatter formatter) {
409         dateFormatter = formatter;
410     }
411
412     /**
413      * <p>
414      * Used to format and display date and time parts of an event.
415      * </p>
416      *
417      * @param formatter format and display date and time parts of an event.
418      */

419     public final void setDateTimeFormatter(final SettingDateFormatter formatter) {
420         dateTimeFormatter = formatter;
421     }
422
423     /**
424      * <p>Last hour of the day to show in the day view.</p>
425      *
426      * @param dayFinishHour the new value of dayFinishHour.
427      */

428     public final void setDayFinishHour(final int dayFinishHour) {
429         this.dayFinishHour = dayFinishHour;
430     }
431
432     /**
433      * <p>First hour of the day to show in the day view.</p>
434      *
435      * @param dayStartHour the new value of dayStartHour.
436      */

437     public final void setDayStartHour(final int dayStartHour) {
438         this.dayStartHour = dayStartHour;
439     }
440
441     /**
442      * <p>For week and day views, contains events for day view which are
443      * not all day events, indexed by hour.</p>
444      *
445      * <p>For month views, contains all events for each day, indexed by
446      * day. There will be as many elements of the array as there are weeks
447      * in the month.</p>
448      *
449      * <p>Each element of each <code>Map</code> is a sorted
450      * <code>TreeSet</code> which uses <code>EventHourComparator</code> to
451      * sort.</p>
452      *
453      * @param events new value of events.
454      */

455     public final void setEvents(final Map JavaDoc[] events) {
456         this.events = events;
457     }
458
459     /**
460      * <p>This attribute is used in week views to determine the date of
461      * the first day to be shown.</p>
462      *
463      * @param firstWeekDay the new value of firstWeekDay.
464      */

465     public final void setFirstWeekDay(final GregorianCalendar JavaDoc firstWeekDay) {
466         this.firstWeekDay = firstWeekDay;
467     }
468
469     /**
470      * <p>
471      * Used to format and display only the time part of an event.
472      * </p>
473      *
474      * @param formatter format and display only the time part of an event.
475      */

476     public final void setTimeFormatter(final SettingDateFormatter formatter) {
477         timeFormatter = formatter;
478     }
479
480     /**
481      * <p>Represents the current view type, set to one of the constants in
482      * {@link IndexFormConstants IndexFormConstants}. If unset, defaults
483      * to
484      * the settings <code>calendarDefaultView</code>.</p>
485      *
486      * @param view the new value of view.
487      */

488     public final void setView(final Integer JavaDoc view) {
489         this.view = view;
490     }
491
492     /**
493      * <p>Path of the page to include which will show the current
494      * view.</p>
495      *
496      * @param viewPage the new value of viewPage.
497      */

498     public final void setViewPage(final String JavaDoc viewPage) {
499         this.viewPage = viewPage;
500     }
501
502     /**
503      * TODO
504      *
505      * @see com.ivata.mask.web.struts.MaskForm#validate(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpSession)
506      */

507     public ValidationErrors validate(final HttpServletRequest JavaDoc request,
508             final HttpSession JavaDoc session) {
509         // TODO Auto-generated method stub
510
return null;
511     }
512
513     /**
514      * <p>
515      * Defines the base class of all objects in the value object list.
516      * </p>
517      *
518      * @return base class of all objects in the value object list.
519      */

520     public final Class JavaDoc getBaseClass() {
521         return baseClass;
522     }
523
524     /**
525      * <p>
526      * Mask containing all the field definitions for this list.
527      * </p>
528      *
529      * @return mask containing all the field definitions for this list.
530      */

531     public final Mask getMask() {
532         return mask;
533     }
534
535 }
536
Popular Tags