KickJava   Java API By Example, From Geeks To Geeks.

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


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.view.ContainerView;
28 import com.iplanet.jato.view.html.SelectableGroup;
29 import com.iplanet.jato.view.html.SelectableGroupImpl;
30 import com.iplanet.jato.view.html.OptionList;
31 import com.iplanet.jato.view.html.Option;
32 import com.iplanet.jato.view.View;
33 import com.iplanet.jato.view.ViewBean;
34 import com.iplanet.jato.view.event.DisplayEvent;
35
36 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
37
38 import java.util.ArrayList JavaDoc;
39 import java.util.List JavaDoc;
40
41 /**
42  * Unfortunately, this class has to exist to support Lockhart tags. They are
43  * not current with JATO and cannot use JATO BasicChoiceDisplayField's. Once,
44  * Lockhart supports those fields, then this class will be deprecated in favor
45  * of ChoiceFieldDescriptor.
46  */

47 public class SelectFieldDescriptor extends DisplayFieldDescriptor {
48
49     /**
50      * This constructor creates a DisplayFieldDescriptor. Name is
51      * required to create a SelectFieldDescriptor.
52      *
53      * @param name Instance name for the described SelectField
54      */

55     public SelectFieldDescriptor(String JavaDoc name) {
56     super(name);
57     }
58
59
60     /**
61      *
62      */

63     public View getInstance(RequestContext ctx, ContainerView container, String JavaDoc name) {
64     SelectableGroupImpl choice = new SelectableGroupImpl(
65         container, name, getModelFieldName(), getInitialValue());
66         setOptions(choice);
67     setExtraHtml(choice);
68     return choice;
69     }
70     
71     protected void setOptions(SelectableGroup choice) {
72     Object JavaDoc options = getParameter(LABELS);
73     if (options != null) {
74         if (options instanceof String JavaDoc) {
75         List tmp = new ArrayList JavaDoc();
76         tmp.add(options);
77         options = tmp;
78         }
79         List optionList = (List)options;
80         int numOptions = optionList.size();
81
82         Object JavaDoc values = getParameter(VALUES);
83         List valueList = optionList;
84         if (values != null) {
85         if (values instanceof String JavaDoc) {
86             List tmp = new ArrayList JavaDoc();
87             tmp.add(values);
88             values = tmp;
89         }
90         valueList = (List)values;
91         if (valueList.size() != numOptions) {
92             throw new FrameworkException(
93             "Unequal number of option names / values!",
94             this, choice.getParent());
95         }
96         }
97
98         OptionList choices =
99         new OptionList(
100             (String JavaDoc [])optionList.toArray(new String JavaDoc[numOptions]),
101             (String JavaDoc [])valueList.toArray(new String JavaDoc[numOptions]));
102         choice.setOptions(choices);
103     }
104     }
105
106
107     /**
108      * OPTIONS are the
109      */

110     public static final String JavaDoc LABELS = "labels";
111     public static final String JavaDoc VALUES = "values";
112 }
113
Popular Tags