KickJava   Java API By Example, From Geeks To Geeks.

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


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.ModelManager;
27 import com.iplanet.jato.RequestContext;
28 import com.iplanet.jato.RequestManager;
29 import com.iplanet.jato.view.ContainerView;
30 import com.iplanet.jato.view.View;
31
32 import com.sun.enterprise.tools.guiframework.view.DescriptorCCPrimaryMasthead;
33 import com.sun.web.ui.model.CCMastheadModel;
34 import com.sun.web.ui.model.CCMastheadModelInterface;
35
36
37 /**
38  *
39  */

40 public class CCPrimaryMastheadDescriptor extends DisplayFieldDescriptor {
41
42     /**
43      * Constructor
44      */

45     public CCPrimaryMastheadDescriptor(String JavaDoc name) {
46     super(name);
47     }
48
49     /**
50      * <p> This method retrieves the CCMastheadModelInterface
51      * implementation. If the Model is new, it will attempt to populate
52      * it via parameters supplied via the XML. If you want to populate
53      * the model via code, you can do that as well.</p>
54      *
55      * @return The CCMastheadModel from the ModelManager.
56      */

57     public CCMastheadModelInterface getModel() {
58     // Determine if the session should be used w/ the model manager.
59
boolean fromSession = shouldGetModelFromSession();
60     boolean toSession = shouldPutModelToSession();
61     String JavaDoc value = getModelInstanceName();
62
63     // Use the ModelManager to create/get the model
64
ModelManager mgr = RequestManager.getRequestContext().getModelManager();
65     // Using the instance class b/c I'm too lazy to register the mapping
66
CCMastheadModelInterface model =
67         (CCMastheadModelInterface) mgr.getModel(CCMastheadModel.class,
68         value, fromSession, toSession);
69
70     // Use model.getShowDate() to see if we need to populate the model
71
if (model.getShowDate() != null) {
72         // Model already populated, return it
73
return model;
74     }
75
76     //help
77
String JavaDoc helpFile = (String JavaDoc) getParameter(HELP_FILENAME);
78     if (helpFile != null) {
79         ((CCMastheadModel) model).setHelpFileName(helpFile);
80     }
81
82     // Set CCMastheadModel.showDate()
83
value = (String JavaDoc) getParameter(SHOW_DATE);
84     if (value == null) {
85         value = "false";
86     }
87     model.setShowDate(new Boolean JavaDoc(value).booleanValue());
88
89     // Set the taskStatusHref
90
value = (String JavaDoc) getParameter(TASK_STATUS_HREF);
91     if (value != null) {
92         model.setTaskStatusHREF(value);
93     }
94
95     // Set the currentAlarmsHref
96
value = (String JavaDoc) getParameter(CURRENT_ALARMS_HREF);
97     if (value != null) {
98         model.setCurrentAlarmsHREF(value);
99     }
100
101     // Set the alarmCountHref
102
value = (String JavaDoc) getParameter(ALARM_COUNT_HREF);
103     if (value != null) {
104         model.setAlarmCountHREF(value);
105     }
106
107     // Set the number of tasks running
108
value = (String JavaDoc) getParameter(NUM_TASKS);
109     if (value != null) {
110         model.setNumTasks(Integer.parseInt(value));
111     }
112
113     // Set the number of tasks running
114
value = (String JavaDoc) getParameter(NUM_DOWN);
115     if (value != null) {
116         ((CCMastheadModel) model).setAlarms(
117         value,
118         (String JavaDoc) getParameter(NUM_CRITICAL),
119         (String JavaDoc) getParameter(NUM_MAJOR),
120         (String JavaDoc) getParameter(NUM_MINOR));
121     }
122
123     // Add arbitrary links
124
int count = 0;
125     value = (String JavaDoc) getParameter(LINK + count);
126     while (value != null) {
127         model.addLink(
128         value,
129         (String JavaDoc) getParameter(LINK_LABEL + count),
130         (String JavaDoc) getParameter(LINK_TOOLTIP + count),
131         (String JavaDoc) getParameter(LINK_STATUS + count));
132         count++;
133         value = (String JavaDoc) getParameter(LINK + count);
134     }
135
136     // Show Server
137
value = (String JavaDoc) getParameter(SHOW_SERVER);
138     if (value != null) {
139         model.setShowServer(Boolean.valueOf(value));
140     }
141
142     // Show User Role
143
value = (String JavaDoc) getParameter(SHOW_USER_ROLE);
144     if (value != null) {
145         model.setShowUserRole(Boolean.valueOf(value));
146     }
147
148     // Image
149
String JavaDoc imageSrc = (String JavaDoc) getParameter(IMAGE_SRC);
150     if (imageSrc != null) {
151         model.setSrc(imageSrc);
152     }
153
154     //Version
155
String JavaDoc versionFile = (String JavaDoc) getParameter(VERSION_FILE);
156     if (versionFile != null) {
157         ((CCMastheadModel) model).setVersionFileName(versionFile);
158     }
159
160     String JavaDoc versionWindowHeight = (String JavaDoc) getParameter(VERSION_WINDOW_HEIGHT);
161     if (versionWindowHeight != null) {
162         ((CCMastheadModel) model).setVersionHeight(versionWindowHeight);
163     }
164
165     String JavaDoc versionWindowWidth = (String JavaDoc) getParameter(VERSION_WINDOW_WIDTH);
166     if (versionWindowWidth != null) {
167         ((CCMastheadModel) model).setVersionWidth(versionWindowWidth);
168     }
169
170     String JavaDoc prodNameSrc = (String JavaDoc) getParameter(PRODUCT_NAME_SRC);
171     if (prodNameSrc != null) {
172         ((CCMastheadModel) model).setVersionProductNameSrc(prodNameSrc);
173     }
174
175     String JavaDoc prodNameHeight = (String JavaDoc) getParameter(PRODUCT_NAME_HEIGHT);
176     if (prodNameHeight != null) {
177         ((CCMastheadModel) model).setVersionProductNameHeight(prodNameHeight);
178     }
179
180     String JavaDoc prodNameWidth = (String JavaDoc) getParameter(PRODUCT_NAME_WIDTH);
181     if (prodNameWidth != null) {
182         ((CCMastheadModel) model).setVersionProductNameWidth(prodNameWidth);
183     }
184
185     //Help
186
String JavaDoc helpType = (String JavaDoc) getParameter(HELP_TYPE);
187     if (helpType == null) {
188         helpType = DEFAULT_HELP_TYPE;
189     }
190     ((CCMastheadModel) model).setHelpType(helpType);
191
192     String JavaDoc helpMastheadTitle = (String JavaDoc) getParameter(HELP_MASTHEADTITLE);
193     if (helpMastheadTitle != null) {
194         ((CCMastheadModel) model).setHelpMastheadTitle(helpMastheadTitle);
195     }
196
197     // Return the model
198
return model;
199     }
200
201     /**
202      * This is a factory method for DescriptorCCPrimaryMasthead instances.
203      *
204      * @param ctx The RequestContext
205      * @param container The container for the newly created
206      * @param name The instance name
207      *
208      * @return A DescriptorCCPrimaryMasthead instance.
209      */

210     public View getInstance(RequestContext ctx, ContainerView container, String JavaDoc name) {
211     // Create the DescriptorCCPrimaryMasthead
212
DescriptorCCPrimaryMasthead mh = new DescriptorCCPrimaryMasthead(
213         ctx, container, name, this, getModel());
214
215     // Set View parameters
216
// Set CCMastheadModel.showDate()
217
String JavaDoc value = (String JavaDoc) getParameter(SUBMIT_FORM_DATA);
218     if (value == null) {
219         value = "false";
220     }
221     mh.setSubmitFormData(new Boolean JavaDoc(value).booleanValue());
222
223     // Set the userInfoHref
224
value = (String JavaDoc) getParameter(USER_INFO_HREF);
225     if (value != null) {
226         mh.setUserInfoHREF(value);
227     }
228
229     // Set the notificationMsg
230
value = (String JavaDoc) getParameter(NOTIFICATION_MSG);
231     if (value != null) {
232         mh.setNotificationMsg(value);
233     }
234
235     // Set the notificationHref
236
value = (String JavaDoc) getParameter(NOTIFICATION_HREF);
237     if (value != null) {
238         mh.setNotificationHREF(value);
239     }
240
241     value = (String JavaDoc) getParameter(USER_NAME);
242     if (value != null) {
243         mh.setUserName(value);
244     }
245
246     // Return the CCPrimaryMastHead instance
247
return mh;
248     }
249
250     /**
251      * <p> This parameter (showDate) should be set to "true" to set the
252      * CCMastheadModel.showDate(true), else false will be used.</p>
253      */

254     public static final String JavaDoc SHOW_DATE = "showDate";
255
256     /**
257      * <p> This parameter (taskStatusHref) should be set to the name of the
258      * href for task status. If supplied, this will be set via
259      * CCMastheadModel.setTaskStatusHREF(String).</p>
260      */

261     public static final String JavaDoc TASK_STATUS_HREF = "taskStatusHref";
262
263     /**
264      * <p> This parameter (currentAlarmsHref) should be set to the name of the
265      * currentAlarmsHref child. If supplied, this will be set via
266      * CCMastheadModel.setCurrentAlarmsHREF(String).</p>
267      */

268     public static final String JavaDoc CURRENT_ALARMS_HREF = "currentAlarmsHref";
269
270     /**
271      * <p> This parameter (alarmCountHref) should be set to the name of the
272      * alarmCountHref child. If supplied, this will be set via
273      * CCMastheadModel.setAlarmCountHREF(String).</p>
274      */

275     public static final String JavaDoc ALARM_COUNT_HREF = "alarmCountHref";
276
277     /**
278      * <p> This parameter (numTasks) should be set to the number of the
279      * current running tasks. If supplied, this will be set via
280      * CCMastheadModel.setNumTasks(int).</p>
281      */

282     public static final String JavaDoc NUM_TASKS = "numTasks";
283
284     /**
285      * <p> This parameter (numDown) reflects the down alarm count. It will
286      * be passed to CCMastHeadModel.setAlarms(String, String, String,
287      * String) as the first argument.</p>
288      */

289     public static final String JavaDoc NUM_DOWN = "numDown";
290
291     /**
292      * <p> This parameter (numCritical) reflects the critical alarm count. It
293      * will be passed to CCMastHeadModel.setAlarms(String, String,
294      * String, String) as the second argument.</p>
295      */

296     public static final String JavaDoc NUM_CRITICAL = "numCritical";
297
298     /**
299      * <p> This parameter (numMajor) reflects the major alarm count. It will
300      * be passed to CCMastHeadModel.setAlarms(String, String, String,
301      * String) as the third argument.</p>
302      */

303     public static final String JavaDoc NUM_MAJOR = "numMajor";
304
305     /**
306      * <p> This parameter (numMinor) reflects the minor alarm count. It will
307      * be passed to CCMastHeadModel.setAlarms(String, String, String,
308      * String) as the fourth argument.</p>
309      */

310     public static final String JavaDoc NUM_MINOR = "numMinor";
311
312     /**
313      * <p> This parameter name (link) will have a number 0 through n
314      * appended to it where n represents the last general link added to
315      * the Masthead. Link numbers must be sequential. The value for
316      * this parameter will be the href child name.</p>
317      */

318     public static final String JavaDoc LINK = "link";
319
320     /**
321      * <p> This parameter name (linkLabel) will have a number 0 through n
322      * appended to it where n represents the last general link added to
323      * the Masthead. Link numbers must be sequential. The value for
324      * this parameter will be the href child label.</p>
325      */

326     public static final String JavaDoc LINK_LABEL = "linkLabel";
327
328     /**
329      * <p> This parameter name (linkTooltip) will have a number 0 through n
330      * appended to it where n represents the last general link added to
331      * the Masthead. Link numbers must be sequential. The value for
332      * this parameter will be the href child tooltip.</p>
333      */

334     public static final String JavaDoc LINK_TOOLTIP = "linkTooltip";
335
336     /**
337      * <p> This parameter name (linkStatus) will have a number 0 through n
338      * appended to it where n represents the last general link added to
339      * the Masthead. Link numbers must be sequential. The value for
340      * this parameter will be the href child status.</p>
341      */

342     public static final String JavaDoc LINK_STATUS = "linkStatus";
343
344     /**
345      * <p> The value for parameter (submitFormData) is passed to
346      * CCPrimaryMasthead.setSubmitFormData(boolean). The default is
347      * false.</p>
348      */

349     public static final String JavaDoc SUBMIT_FORM_DATA = "submitFormData";
350
351     /**
352      * <p> This parameter (userInfoHref) should be set to the name of the
353      * userInfoHref child. If supplied, this will be set via
354      * CCPrimaryMasthead.setUserInfoHREF(String).</p>
355      */

356     public static final String JavaDoc USER_INFO_HREF = "userInfoHref";
357
358     /**
359      * <p> This parameter (notificationMsg) should be set to the
360      * notificationMsg value. If supplied, this will be set via
361      * CCPrimaryMasthead.setNotificationMsg(String).</p>
362      */

363     public static final String JavaDoc NOTIFICATION_MSG = "notificationMsg";
364
365     /**
366      * <p> This parameter (notificationHref) should be set to the name of the
367      * notificationHref child. If supplied, this will be set via
368      * CCPrimaryMasthead.setNotificationHREF(String).</p>
369      */

370     public static final String JavaDoc NOTIFICATION_HREF = "notificationHref";
371
372     /**
373      * <p> This parameter (productNameSrc) should be set to the path of the
374      * product name gif file. If supplied this will be set via
375      * CCHelpVersionInterface.setVersionProductNameSrc method
376      */

377     public static final String JavaDoc PRODUCT_NAME_SRC = "productNameSrc";
378
379     /**
380      * <p> This parameter (productNameHeight) should be set to the height of the
381      * product name gif file. If supplied this will be set via
382      * CCHelpVersionInterface.setVersionProductNameHeight method
383      */

384     public static final String JavaDoc PRODUCT_NAME_HEIGHT = "productNameHeight";
385
386     /**
387      * <p> This parameter (productNameWidth) should be set to the width of the
388      * product name gif file. If supplied this will be set via
389      * CCHelpVersionInterface.setVersionProductNameWidth method
390      */

391     public static final String JavaDoc PRODUCT_NAME_WIDTH = "productNameWidth";
392
393     /**
394      * <p> This parameter (versionFile) should be set to the path of the
395      * version file. If supplied this will be set via
396      * CCHelpVersionInterface.setVersionFile method
397      * Also see CCVersionWindowTag API Help for more info on the localization of
398      * the file
399      *
400      * HACK: setting this as a relative path to the top level file which calls a JSP
401      * for the localized copyright message
402      */

403     public static final String JavaDoc VERSION_FILE = "versionFile";
404
405     public static final String JavaDoc SHOW_SERVER = "showServer";
406     public static final String JavaDoc SHOW_USER_ROLE = "showUserRole";
407     public static final String JavaDoc IMAGE_SRC = "imageSrc";
408
409     public static final String JavaDoc VERSION_WINDOW_HEIGHT = "versionWindowHeight";
410     public static final String JavaDoc VERSION_WINDOW_WIDTH = "versionWindowWidth";
411     public static final String JavaDoc USER_NAME = "userName";
412
413     //HELP
414
public static final String JavaDoc HELP_MASTHEADTITLE = "helpMastheadTitle";
415     public static final String JavaDoc HELP_TYPE = "helpType";
416     public static final String JavaDoc DEFAULT_HELP_TYPE = "help2";
417     public static final String JavaDoc HELP_FILENAME = "helpFile";
418     public static final String JavaDoc HELP_RESOURCES = "helpResources";
419 }
420
Popular Tags