KickJava   Java API By Example, From Geeks To Geeks.

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


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.BasicDisplayField;
29 import com.iplanet.jato.view.ContainerView;
30 import com.iplanet.jato.view.DisplayField;
31 import com.iplanet.jato.view.View;
32
33 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
34
35 import com.sun.web.ui.model.CCActionTableModelInterface;
36
37
38 /**
39  * This Descriptor is needed so that children of a CCActionTable can be
40  * created from the CCActionTable's model rather than directly.
41  */

42 public class CCActionTableChildDescriptor extends DisplayFieldDescriptor {
43
44     /**
45      * Constructor
46      */

47     public CCActionTableChildDescriptor(String JavaDoc name) {
48     super(name);
49     }
50
51
52     /**
53      * This method returns the model associated with this View (it is actually
54      * obtained from the parent CCActionTableDescriptor).
55      *
56      * @return CCActionTableModelInterface
57      */

58     protected CCActionTableModelInterface getModel() {
59     // Find the CCActionTable
60
ViewDescriptor viewDesc = getParent();
61     while (viewDesc != null) {
62         if (viewDesc instanceof CCActionTableDescriptor) {
63         break;
64         }
65         viewDesc = viewDesc.getParent();
66     }
67     if (viewDesc == null) {
68         throw new FrameworkException(this.getClass().getName()+
69         " is not contained within a CCActionTableDescriptor!",
70         this, getView(RequestManager.getRequestContext()));
71     }
72     return ((CCActionTableDescriptor)viewDesc).getModel();
73     }
74
75
76     /**
77      * This is a factory method.
78      *
79      * @param ctx The RequestContext
80      * @param container The container for the newly created
81      * @param name The Name of the View to be created.
82      */

83     public View getInstance(RequestContext ctx, ContainerView container, String JavaDoc name) {
84     CCActionTableModelInterface model = getModel();
85         if (model != null && model.isChildSupported(name)) {
86         // Create the View
87
View child = model.createChild(container, name);
88             
89             // possibly add some default values in the model from the view desc.
90
if (child instanceof DisplayField) {
91                 DisplayField field = (DisplayField)child;
92
93         // Set the ModelFieldBinding or BoundName
94
setBoundName(field);
95
96         // Set the model action for this field
97
String JavaDoc value = (String JavaDoc)getParameter("actionValue");
98         if (value != null) {
99             model.setActionValue(name, value);
100         }
101         
102         // Set the model value for this field
103
value = (String JavaDoc)getParameter("value");
104         if (value != null) {
105             model.setValue(name, value);
106         }
107             }
108             return child;
109         }
110         return null;
111     }
112 }
113
Popular Tags