KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > form > StringPropertySelectionModel


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.form;
16
17 /**
18  * Implementation of {@link IPropertySelectionModel} that allows one String from
19  * an array of Strings to be selected as the property.
20  *
21  * <p>Uses a simple index number as the value (used to represent the selected String).
22  * This assumes that the possible values for the Strings will remain constant between
23  * request cycles.
24  *
25  * @author Howard Lewis Ship
26  *
27  **/

28
29 public class StringPropertySelectionModel implements IPropertySelectionModel
30 {
31     private String JavaDoc[] options;
32
33     /**
34      * Standard constructor.
35      *
36      * The options are retained (not copied).
37      **/

38
39     public StringPropertySelectionModel(String JavaDoc[] options)
40     {
41         this.options = options;
42     }
43
44     public int getOptionCount()
45     {
46         return options.length;
47     }
48
49     public Object JavaDoc getOption(int index)
50     {
51         return options[index];
52     }
53
54     /**
55      * Labels match options.
56      *
57      **/

58
59     public String JavaDoc getLabel(int index)
60     {
61         return options[index];
62     }
63
64     /**
65      * Values are indexes into the array of options.
66      *
67      **/

68
69     public String JavaDoc getValue(int index)
70     {
71         return Integer.toString(index);
72     }
73
74     public Object JavaDoc translateValue(String JavaDoc value)
75     {
76         int index;
77
78         index = Integer.parseInt(value);
79
80         return options[index];
81     }
82
83 }
Popular Tags