KickJava   Java API By Example, From Geeks To Geeks.

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


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.model.ModelFieldBinding;
28 import com.iplanet.jato.view.BasicDisplayField;
29 import com.iplanet.jato.view.DisplayFieldImpl;
30 import com.iplanet.jato.view.ContainerView;
31 import com.iplanet.jato.view.DisplayField;
32 import com.iplanet.jato.view.View;
33 import com.iplanet.jato.view.ViewBean;
34 import com.iplanet.jato.view.event.DisplayEvent;
35 import com.iplanet.jato.view.html.HtmlDisplayFieldBase;
36
37 import java.util.ArrayList JavaDoc;
38 import java.util.List JavaDoc;
39
40
41 /**
42  *
43  */

44 public class DisplayFieldDescriptor extends ViewDescriptor {
45
46     /**
47      * This constructor creates a DisplayFieldDescriptor. Name is
48      * required to create a DisplayFieldDescriptor.
49      *
50      * @param name Instance name for the described DisplayField
51      */

52     public DisplayFieldDescriptor(String JavaDoc name) {
53     super(name);
54     }
55
56
57     /**
58      * This method will set the default value if the view is a DisplayField
59      * and a DefaultValue has been supplied.
60      */

61     protected void setDefaultValue(View view) {
62     // We first check (value != null) b/c this is relatively inexpensive
63
// compared to instanceof and DisplayField.getValue(), also it is very
64
// likely that a default value is not supplied.
65
Object JavaDoc value = getInitialValue();
66     if (value != null) {
67         if (view instanceof DisplayField) {
68         DisplayField df = ((DisplayField)view);
69         if (df.getValue() == null) {
70             // Only set a default value if no value has been set yet
71
df.setValue(value);
72         }
73         }
74     }
75     }
76
77
78     /**
79      *
80      */

81     public View getInstance(RequestContext ctx, ContainerView container, String JavaDoc name) {
82     // Create the field
83
BasicDisplayField field = new BasicDisplayField(container, name);
84
85     // Set the ModelFieldBinding
86
setModelFieldBinding(field, getModelFieldName());
87
88     // Set the default value if supplied
89
setDefaultValue(field);
90
91     return field;
92     }
93
94
95     /**
96      * This method retrieves the model field name that this field is bound to.
97      * This uses the MODEL_FIELD_NAME parameter.
98      *
99      * @return The bound name (will return getName() if MODEL_FIELD_NAME is
100      * not supplied).
101      */

102     public String JavaDoc getModelFieldName() {
103     String JavaDoc value = (String JavaDoc)getParameter(MODEL_FIELD_NAME);
104     if (value == null) {
105         value = getName();
106     }
107     return value;
108     }
109
110     /**
111      * <P> This method sets the Model field name that the given
112      * DisplayFieldImpl should be bound. It will retrieve the bound name
113      * via the getModelFieldName method.</P>
114      *
115      * @param field DisplayFieldImpl to bind
116      *
117      * @see #getModelFieldName()
118      */

119     public void setBoundName(DisplayField field) {
120     if (field instanceof DisplayFieldImpl) {
121         setBoundName((DisplayFieldImpl)field, getModelFieldName());
122     } else if (field instanceof BasicDisplayField) {
123         setModelFieldBinding((BasicDisplayField)field, getModelFieldName());
124     }
125     }
126
127     /**
128      * <P> This method sets the Model field name that the given
129      * DisplayFieldImpl should be bound.</P>
130      *
131      * @param field DisplayFieldImpl to bind
132      * @param name The model field name.
133      */

134     public void setBoundName(DisplayFieldImpl field, String JavaDoc name) {
135     field.setBoundName(name);
136     }
137
138     /**
139      * <P> This method sets the ModelFieldBinding for the given
140      * BasicDisplayField.</P>
141      *
142      * @param field The BasicDisplayField
143      * @param name The model field name.
144      */

145     public void setModelFieldBinding(BasicDisplayField field, String JavaDoc name) {
146     field.setModelFieldBinding(new ModelFieldBinding(name));
147     }
148
149     /**
150      * Returns the initial value (if any). If InitialValue is null, then no
151      * value will be set (the model may already have a value, or provide an
152      * initial value).
153      *
154      * @return The initial value to set to the DisplayField upon creation
155      */

156     public Object JavaDoc getInitialValue() {
157     return getParameter(DEFAULT_VALUE);
158     }
159
160
161     /**
162      * This method looks for extra HTML supplied as a parameter and applies
163      * it to the given HtmlDisplayField.
164      *
165      * @param view The HtmlDisplayField to recieve the extra HTML
166      *
167      * @return The extraHtml String
168      */

169     public String JavaDoc setExtraHtml(HtmlDisplayFieldBase view) {
170 // FIXME: JATO bug prevents us from using HtmlDisplayField, setExtraHtml
171
// FIXME: not defined in this Interface (CR#: 6175891)
172
String JavaDoc extra = (String JavaDoc)getParameter(EXTRA_HTML);
173     if ((extra != null) && (view != null)) {
174         view.setExtraHtml(extra);
175     }
176     return extra;
177     }
178
179     /**
180      * <p> This method checks the {@link #DISABLED} parameter and returns
181      * true if the display field should be disabled.</p>
182      */

183     public boolean isDisabled() {
184         return Boolean.parseBoolean((""+getParameter(DISABLED)).toString());
185     }
186
187     /**
188      * This parameter specifies if this field should be disabled.
189      * ("disabled")
190      */

191     public static final String JavaDoc DISABLED = "disabled";
192
193
194
195     /**
196      * This parameter specifies the model's field name that this field is
197      * bound to. If a parameter of this name is supplied, its value will be
198      * used for the model field; otherwise this.getName() will be used as the
199      * model field name. ("modelFieldName")
200      */

201     public static final String JavaDoc MODEL_FIELD_NAME= "modelFieldName";
202
203     /**
204      * DEFAULT_VALUE (which is set to "defaultValue") is the name of the
205      * Paramter that can be specified to supply a default value to a display
206      * field.
207      */

208     public static final String JavaDoc DEFAULT_VALUE = "defaultValue";
209
210
211     /**
212      * EXTRA_HTML (which is set to "extraHtml") is the name of the Paramter
213      * that can be specified to supply extra HTML to this field.
214      */

215     public static final String JavaDoc EXTRA_HTML = "extraHtml";
216 }
217
Popular Tags