KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > guiframework > view > descriptors > CCDateTimeDescriptor


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.tools.guiframework.view.descriptors;
25
26 import com.iplanet.jato.RequestContext;
27 import com.iplanet.jato.RequestManager;
28 import com.iplanet.jato.view.ContainerView;
29 import com.iplanet.jato.view.View;
30
31 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
32 import com.sun.enterprise.tools.guiframework.view.DescriptorCCDateTime;
33
34 import com.sun.web.ui.model.CCDateTimeModelInterface;
35
36 import java.util.Date JavaDoc;
37 import java.util.HashMap JavaDoc;
38 import java.util.Map JavaDoc;
39
40
41 /**
42  *
43  */

44 public class CCDateTimeDescriptor extends DisplayFieldDescriptor {
45
46     /**
47      * Constructor
48      */

49     public CCDateTimeDescriptor(String JavaDoc name) {
50     super(name);
51     }
52
53     /**
54      *
55      */

56     public CCDateTimeModelInterface getModel() {
57     return getModel(RequestManager.getRequestContext());
58     }
59
60     /**
61      *
62      */

63     public CCDateTimeModelInterface getModel(RequestContext ctx) {
64     return (CCDateTimeModelInterface)ctx.getModelManager().getModel(
65         CCDateTimeModelInterface.class,
66         getModelInstanceName(),
67         shouldGetModelFromSession(),
68         shouldPutModelToSession());
69     }
70
71     /**
72      * This is a factory method for CCDateTime instances.
73      *
74      * @param ctx The RequestContext
75      * @param container The container for the newly created
76      */

77     public View getInstance(RequestContext ctx, ContainerView container, String JavaDoc name) {
78     // Get the Model
79
CCDateTimeModelInterface model = getModel(ctx);
80
81     // Set some defaults if the model is not pre-populated
82
if (model.getStartDateTime() == null) {
83         // Initialize the Model
84
// Start Date / Time
85
Date JavaDoc today = (Date JavaDoc)getParameter(START_DATE_TIME);
86         if (today == null) {
87         today = new Date JavaDoc();
88         }
89         model.setStartDateTime(today);
90
91         // End Date / Time (not used)
92
// model.setEndTime(today);
93

94         // Make START_DATE_TIME_ONLY the default type
95
model.setType(CCDateTimeModelInterface.START_DATE_TIME_ONLY);
96
97         // Check to see if the developer provided a type
98
String JavaDoc value = (String JavaDoc)getParameter(DATE_TIME_TYPE);
99         if (value != null) {
100         Integer JavaDoc type = (Integer JavaDoc)_typeMap.get(value);
101         if (type != null) {
102             model.setType(type.intValue());
103         } else {
104             throw new FrameworkException("Invalid CCDateTime type!");
105         }
106         }
107
108         // Repeat Interval (LH BUG, NO DEFAULT!! NPE if not supplied)
109
model.setSelectedRepeatIntervalName(CCDateTimeModelInterface.WEEKLY);
110
111         // Repeat Limits (not used)
112
// model.setRepeatLimitUnit(CCDateTimeModelInterface.WEEKS);
113
// model.setRepeatLimitPeriod(52);
114
// "*'d fields are required" Message
115
value = (String JavaDoc)getParameter(SHOW_REQUIRED_MESSAGE);
116         boolean booleanValue = false;
117         if (value != null) {
118         booleanValue = new Boolean JavaDoc(value).booleanValue();
119         }
120         model.setShowRequiredMsg(booleanValue);
121
122         // Date
123
value = (String JavaDoc)getParameter(START_DATE_LABEL);
124         if (value != null) {
125         model.setStartDateLabel(value);
126         }
127
128         // Time
129
value = (String JavaDoc)getParameter(START_TIME_LABEL);
130         if (value != null) {
131         model.setStartTimeLabel(value);
132         }
133
134         // End Time (not used) (add in if other types are supported)
135
// value = (String)getParameter(END_TIME_LABEL);
136
// if (value != null) {
137
// model.setEndTimeLabel(value);
138
// }
139
}
140
141     // Create the CCDateTime field
142
return new DescriptorCCDateTime(ctx, name, this, container, model);
143 // FOR popup...
144
// return new com.sun.web.ui.view.datetime.CCDateTimeWindow(container, model, name);
145
}
146
147     /**
148      *
149      */

150     private static Map JavaDoc _typeMap = new HashMap JavaDoc();
151
152     static {
153     _typeMap.put("NORMAL", new Integer JavaDoc(CCDateTimeModelInterface.NORMAL));
154     _typeMap.put("NO_END_TIME", new Integer JavaDoc(CCDateTimeModelInterface.NO_END_TIME));
155     _typeMap.put("FOR_DATE_SELECTION", new Integer JavaDoc(CCDateTimeModelInterface.FOR_DATE_SELECTION));
156     _typeMap.put("NO_REPEAT_LIMIT", new Integer JavaDoc(CCDateTimeModelInterface.NO_REPEAT_LIMIT));
157     _typeMap.put("START_DATE_TIME_ONLY", new Integer JavaDoc(CCDateTimeModelInterface.START_DATE_TIME_ONLY));
158     }
159
160     /**
161      * Parameter (startDateTime) used to provide the start date time
162      */

163     public static final String JavaDoc START_DATE_TIME = "startDateTime";
164
165     /**
166      * Parameter (startDateLabel) indicates the label for the date.
167      */

168     public static final String JavaDoc START_DATE_LABEL = "startDateLabel";
169
170     /**
171      * Parameter (startTimeLabel) indicates the label for the time.
172      */

173     public static final String JavaDoc START_TIME_LABEL = "startTimeLabel";
174
175     /**
176      * Parameter (endTimeLabel) indicates the label for the end time. (not
177      * currently used because datetime type is fixed to START_DATE_TIME_ONLY).
178      */

179     public static final String JavaDoc END_TIME_LABEL = "endTimeLabel";
180
181     /**
182      * Paramter (showRequiredMessage), if set to "true" a message indicating
183      * *'d fields are required will appear.
184      */

185     public static final String JavaDoc SHOW_REQUIRED_MESSAGE = "showRequiredMessage";
186
187     /**
188      * <P> Parameter (type) indicates the CCDateTime type. Valid values
189      * are:</P>
190      *
191      * <UL><LI>NORMAL</LI>
192      * <LI>NO_END_TIME</LI>
193      * <LI>FOR_DATE_SELECTION</LI>
194      * <LI>NO_REPEAT_LIMIT</LI>
195      * <LI>START_DATE_TIME_ONLY</LI></UL>
196      */

197     public static final String JavaDoc DATE_TIME_TYPE = "type";
198 }
199
Popular Tags