KickJava   Java API By Example, From Geeks To Geeks.

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


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.view.ContainerView;
29 import com.iplanet.jato.view.View;
30 import com.iplanet.jato.view.DisplayField;
31 import com.iplanet.jato.RequestManager;
32 import com.iplanet.jato.view.ContainerViewBase;
33
34 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
35 import com.sun.enterprise.tools.guiframework.view.DescriptorCCActionTable;
36
37 import com.sun.web.ui.model.CCActionTableModelInterface;
38
39 import java.io.InputStream JavaDoc;
40
41
42 /**
43  *
44  */

45 public class CCActionTableDescriptor extends ViewDescriptor {
46
47     /**
48      * Constructor
49      */

50     public CCActionTableDescriptor(String JavaDoc name) {
51     super(name);
52     }
53
54     
55     public void registerChildren(ContainerViewBase instance) {
56         // Invoke the super registerChild
57
super.registerChildren(instance);
58
59     getModel().registerChildren(instance);
60     }
61
62     
63     /**
64      * This method creates empty descriptors on the fly for fields that are
65      * defined by the underlying model.
66      */

67     public ViewDescriptor getChildDescriptor(String JavaDoc name) {
68         // Do the normal stuff if we can...
69
ViewDescriptor desc = super.getChildDescriptor(name);
70     if (desc != null) {
71         return desc;
72     }
73
74     // Do we need to create a descriptor on the fly?
75
CCActionTableModelInterface model = getModel();
76         if (model != null && model.isChildSupported(name)) {
77         // YES
78
desc = new CCActionTableChildDescriptor(name);
79         // NOTE: This call is safe (mostly), because although we are
80
// NOTE: modifying a static structure... this change is applicable
81
// NOTE: to all users. However, there is a slight possibility of
82
// NOTE: of a sync. problem... not worth worrying about now. If
83
// NOTE: this does become a problem, just remove the
84
// NOTE: addChildDescriptor() line below.
85
addChildDescriptor(desc);
86         return desc;
87     }
88
89     return null;
90     }
91     
92     /**
93      * This is a factory method for CCActionTable instances.
94      *
95      * @param ctx The RequestContext
96      * @param container The container for the newly created
97      */

98     public View getInstance(RequestContext ctx, ContainerView container, String JavaDoc name) {
99     return new DescriptorCCActionTable(ctx, container, name, this, getModel());
100     }
101
102     /**
103      * Call this method when the XML changes and the model needs to reparse it.
104      */

105     public void resetXML() {
106         getModel(true);
107     }
108     
109     /**
110      * This method returns the model associated with this View.
111      */

112     public CCActionTableModelInterface getModel() {
113         return getModel(false);
114     }
115     
116     private CCActionTableModelInterface getModel(boolean resetXML) {
117     // Determine if the session should be used w/ the model manager.
118
boolean fromSession = shouldGetModelFromSession();
119     boolean toSession = shouldPutModelToSession();
120     String JavaDoc value = getModelInstanceName();
121
122     // Use the ModelManager to create/get the model
123
ModelManager mgr = RequestManager.getRequestContext().getModelManager();
124     CCActionTableModelInterface model =
125         (CCActionTableModelInterface)mgr.getModel(
126         CCActionTableModelInterface.class,
127         value, fromSession, toSession);
128
129     // Make sure the XML file is set on the Model
130
if (resetXML || model.getDocument() == null) {
131         // Get the XML document
132
InputStream JavaDoc in = getXMLFileAsStream();
133         model.setDocument(in);
134         try {
135         in.close();
136         } catch (java.io.IOException JavaDoc ex) {
137         // Ignore
138
}
139
140         // Other values set in this "if" statement provide defaults that
141
// the user may choose to override
142

143         // Set the default Primary Sort Name
144
value = (String JavaDoc)getParameter(PRIMARY_SORT_NAME);
145         if (value != null) {
146         model.setPrimarySortName(value);
147         }
148
149         // Set the default Primary Sort Order
150
value = (String JavaDoc)getParameter(PRIMARY_SORT_ORDER);
151         if (value != null) {
152         model.setPrimarySortOrder(value);
153         }
154
155         // Set the default Secondary Sort Name
156
value = (String JavaDoc)getParameter(SECONDARY_SORT_NAME);
157         if (value != null) {
158         model.setSecondarySortName(value);
159         }
160
161         // Set the default Secondary Sort Order
162
value = (String JavaDoc)getParameter(SECONDARY_SORT_ORDER);
163         if (value != null) {
164         model.setSecondarySortOrder(value);
165         }
166     }
167
168     // Check to see if the selection type was specified
169
value = (String JavaDoc)getParameter(ROW_SELECTION_TYPE);
170     if (value != null) {
171         model.setRowSelectionType(value);
172     }
173
174     return model;
175     }
176
177     /**
178      * <P> This parameter key allows the row selection type to be
179      * provided.</P>
180      *
181      * <P>Valid values are:</P>
182      *
183      * <UL><LI>CCActionTableModelInterface.MULTIPLE</LI>
184      * <LI>CCActionTableModelInterface.SINGLE</LI>
185      * <LI>CCActionTableModelInterface.NONE</LI></UL>
186      */

187     public static final String JavaDoc ROW_SELECTION_TYPE = "rowSelectionType";
188
189     /**
190      * <P> This parameter key allows the primary sort name to be set.</P>
191      */

192     public static final String JavaDoc PRIMARY_SORT_NAME = "primarySortName";
193
194     /**
195      * <P> This parameter key allows the primary sort order to be set.</P>
196      *
197      * <P>Valid values are:</P>
198      *
199      * <UL><LI>CCActionTableModelInterface.ASCENDING</LI>
200      * <LI>CCActionTableModelInterface.DESCENDING</LI></UL>
201      */

202     public static final String JavaDoc PRIMARY_SORT_ORDER = "primarySortOrder";
203
204     /**
205      * <P> This parameter key allows the secondary sort name to be set.</P>
206      */

207     public static final String JavaDoc SECONDARY_SORT_NAME = "secondarySortName";
208
209     /**
210      * <P> This parameter key allows the secondary sort order to be set.</P>
211      *
212      * <P>Valid values are:</P>
213      *
214      * <UL><LI>CCActionTableModelInterface.ASCENDING</LI>
215      * <LI>CCActionTableModelInterface.DESCENDING</LI></UL>
216      */

217     public static final String JavaDoc SECONDARY_SORT_ORDER = "secondarySortOrder";
218 }
219
Popular Tags