KickJava   Java API By Example, From Geeks To Geeks.

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


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.BasicChoiceDisplayField;
29 import com.iplanet.jato.view.Choice;
30 import com.iplanet.jato.view.SimpleChoice;
31 import com.iplanet.jato.view.View;
32 import com.iplanet.jato.view.ViewBean;
33 import com.iplanet.jato.view.event.DisplayEvent;
34
35 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
36
37 import java.util.ArrayList JavaDoc;
38 import java.util.List JavaDoc;
39
40 /**
41  *
42  */

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

51     public ChoiceFieldDescriptor(String JavaDoc name) {
52     super(name);
53     }
54
55
56     /**
57      *
58      */

59     public View getInstance(RequestContext ctx, ContainerView container, String JavaDoc name) {
60     BasicChoiceDisplayField choice =
61         new BasicChoiceDisplayField(container, name);
62     setModelFieldBinding(choice, getModelFieldName());
63     Object JavaDoc options = getParameter(LABELS);
64     if (options != null) {
65         if (options instanceof String JavaDoc) {
66         List JavaDoc tmp = new ArrayList JavaDoc();
67         tmp.add(options);
68         options = tmp;
69         }
70         List JavaDoc optionList = (List JavaDoc)options;
71
72         Object JavaDoc values = getParameter(VALUES);
73         List JavaDoc valueList = optionList;
74         if (values != null) {
75         if (values instanceof String JavaDoc) {
76             List JavaDoc tmp = new ArrayList JavaDoc();
77             tmp.add(values);
78             values = tmp;
79         }
80         valueList = (List JavaDoc)values;
81         if (valueList.size() != optionList.size()) {
82             throw new FrameworkException(
83             "Unequal number of option names / values!",
84             this, container);
85         }
86         }
87
88         Choice choices[] = new Choice[valueList.size()];
89         for (int count=0; count<valueList.size(); count++) {
90         // FIXME: Do I18N
91
choices[count] = new SimpleChoice(
92             optionList.get(count), valueList.get(count));
93         }
94         choice.setChoices(choices);
95     }
96     return choice;
97     }
98
99
100     /**
101      * OPTIONS are the
102      */

103     public static final String JavaDoc LABELS = "labels";
104     public static final String JavaDoc VALUES = "values";
105 }
106
Popular Tags