|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| StringPropertySelectionModel.java | - | 100% | 100% | 100% |
|
||||||||||||||
| 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[] options; | |
| 32 | ||
| 33 | /** | |
| 34 | * Standard constructor. | |
| 35 | * | |
| 36 | * The options are retained (not copied). | |
| 37 | **/ | |
| 38 | ||
| 39 | 6 | public StringPropertySelectionModel(String[] options) |
| 40 | { | |
| 41 | 6 | this.options = options; |
| 42 | } | |
| 43 | ||
| 44 | 12 | public int getOptionCount() |
| 45 | { | |
| 46 | 12 | return options.length; |
| 47 | } | |
| 48 | ||
| 49 | 63 | public Object getOption(int index) |
| 50 | { | |
| 51 | 63 | return options[index]; |
| 52 | } | |
| 53 | ||
| 54 | /** | |
| 55 | * Labels match options. | |
| 56 | * | |
| 57 | **/ | |
| 58 | ||
| 59 | 72 | public String getLabel(int index) |
| 60 | { | |
| 61 | 72 | return options[index]; |
| 62 | } | |
| 63 | ||
| 64 | /** | |
| 65 | * Values are indexes into the array of options. | |
| 66 | * | |
| 67 | **/ | |
| 68 | ||
| 69 | 72 | public String getValue(int index) |
| 70 | { | |
| 71 | 72 | return Integer.toString(index); |
| 72 | } | |
| 73 | ||
| 74 | 12 | public Object translateValue(String value) |
| 75 | { | |
| 76 | 12 | int index; |
| 77 | ||
| 78 | 12 | index = Integer.parseInt(value); |
| 79 | ||
| 80 | 12 | return options[index]; |
| 81 | } | |
| 82 | ||
| 83 | } |
|
||||||||||