|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
LabeledPropertySelectionModel.java | 100% | 65.4% | 60.9% | 68.4% |
|
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 |
* Decorates an underlying {@link IPropertySelectionModel}adding an initial
|
|
19 |
* property. The label, option, and value of the initial property are
|
|
20 |
* configurable.
|
|
21 |
*
|
|
22 |
* @author Paul Ferraro
|
|
23 |
* @since 4.0
|
|
24 |
*/
|
|
25 |
public class LabeledPropertySelectionModel implements IPropertySelectionModel |
|
26 |
{ |
|
27 |
private IPropertySelectionModel _model;
|
|
28 |
private String _label = ""; |
|
29 |
private Object _option = null; |
|
30 |
private String _value = ""; |
|
31 |
|
|
32 |
/**
|
|
33 |
* Constructs a new LabeledPropertySelectionModel using an empty model and
|
|
34 |
* default label, option, and value. Default constructor is made available
|
|
35 |
* so that this model may be specified as a component helper bean.
|
|
36 |
*/
|
|
37 | 1 |
public LabeledPropertySelectionModel()
|
38 |
{ |
|
39 | 1 |
this(EMPTY_MODEL);
|
40 |
} |
|
41 |
|
|
42 |
/**
|
|
43 |
* Constructs a new LabeledPropertySelectionModel using the specified model
|
|
44 |
* and default label, option, and value.
|
|
45 |
* @param model the underlying model to decorate
|
|
46 |
*/
|
|
47 | 3 |
public LabeledPropertySelectionModel(IPropertySelectionModel model)
|
48 |
{ |
|
49 | 3 |
_model = model; |
50 |
} |
|
51 |
|
|
52 |
/**
|
|
53 |
* Constructs a new LabeledPropertySelectionModel using the specified model
|
|
54 |
* and label, and default option and value.
|
|
55 |
* @param model the underlying model to decorate
|
|
56 |
* @param label the label of the initial property
|
|
57 |
*/
|
|
58 | 1 |
public LabeledPropertySelectionModel(IPropertySelectionModel model,
|
59 |
String label) |
|
60 |
{ |
|
61 | 1 |
this(model);
|
62 |
|
|
63 | 1 |
_label = label; |
64 |
} |
|
65 |
|
|
66 |
/**
|
|
67 |
* Constructs a new LabeledPropertySelectionModel using the specified model,
|
|
68 |
* label, and option; and default value.
|
|
69 |
* @param model the underlying model to decorate
|
|
70 |
* @param label the label of the initial property
|
|
71 |
* @param option the option value of the initial property
|
|
72 |
*/
|
|
73 | 1 |
public LabeledPropertySelectionModel(IPropertySelectionModel model,
|
74 |
String label, Object option) |
|
75 |
{ |
|
76 | 1 |
this(model, label);
|
77 |
|
|
78 | 1 |
_option = option; |
79 |
} |
|
80 |
|
|
81 |
/**
|
|
82 |
* Constructs a new LabeledPropertySelectionModel using the specified model,
|
|
83 |
* label, option, and value.
|
|
84 |
* @param model the underlying model to decorate
|
|
85 |
* @param label the label of the initial property
|
|
86 |
* @param option the option value of the initial property
|
|
87 |
* @param value the value of the initial property
|
|
88 |
*/
|
|
89 | 1 |
public LabeledPropertySelectionModel(IPropertySelectionModel model,
|
90 |
String label, Object option, String value) |
|
91 |
{ |
|
92 | 1 |
this(model, label, option);
|
93 |
|
|
94 | 1 |
_value = value; |
95 |
} |
|
96 |
|
|
97 |
/**
|
|
98 |
* Returns the underlying IPropertySelectionModel
|
|
99 |
* @return the underlying IPropertySelectionModel
|
|
100 |
*/
|
|
101 | 0 |
public IPropertySelectionModel getModel()
|
102 |
{ |
|
103 | 0 |
return _model;
|
104 |
} |
|
105 |
|
|
106 |
/**
|
|
107 |
* Sets the underlying IPropertySelectionModel
|
|
108 |
* @param model the IPropertySelectionModel to set
|
|
109 |
*/
|
|
110 | 0 |
public void setModel(IPropertySelectionModel model) |
111 |
{ |
|
112 | 0 |
_model = model; |
113 |
} |
|
114 |
|
|
115 |
/**
|
|
116 |
* @see org.apache.tapestry.form.IPropertySelectionModel#getOptionCount()
|
|
117 |
*/
|
|
118 | 6 |
public int getOptionCount() |
119 |
{ |
|
120 | 6 |
return _model.getOptionCount() + 1;
|
121 |
} |
|
122 |
|
|
123 |
/**
|
|
124 |
* @see org.apache.tapestry.form.IPropertySelectionModel#getOption(int)
|
|
125 |
*/
|
|
126 | 7 |
public Object getOption(int index) |
127 |
{ |
|
128 | 7 |
return (index == 0) ? _option : _model.getOption(index - 1);
|
129 |
} |
|
130 |
|
|
131 |
/**
|
|
132 |
* @see org.apache.tapestry.form.IPropertySelectionModel#getLabel(int)
|
|
133 |
*/
|
|
134 | 7 |
public String getLabel(int index) |
135 |
{ |
|
136 | 7 |
return (index == 0) ? _label : _model.getLabel(index - 1);
|
137 |
} |
|
138 |
|
|
139 |
/**
|
|
140 |
* @see org.apache.tapestry.form.IPropertySelectionModel#getValue(int)
|
|
141 |
*/
|
|
142 | 7 |
public String getValue(int index) |
143 |
{ |
|
144 | 7 |
return (index == 0) ? _value : _model.getValue(index - 1);
|
145 |
} |
|
146 |
|
|
147 |
/**
|
|
148 |
* @see org.apache.tapestry.form.IPropertySelectionModel#translateValue(java.lang.String)
|
|
149 |
*/
|
|
150 | 7 |
public Object translateValue(String value)
|
151 |
{ |
|
152 | 7 |
return value.equals(_value) ? _option : _model.translateValue(value);
|
153 |
} |
|
154 |
|
|
155 |
/**
|
|
156 |
* Returns the label of the initial IPropertySelectionModel option
|
|
157 |
* @return a IPropertySelectionModel option label
|
|
158 |
*/
|
|
159 | 1 |
public String getLabel()
|
160 |
{ |
|
161 | 1 |
return _label;
|
162 |
} |
|
163 |
|
|
164 |
/**
|
|
165 |
* Sets the label of the initial IPropertySelectionModel option
|
|
166 |
* @param label a IPropertySelectionModel option label
|
|
167 |
*/
|
|
168 | 0 |
public void setLabel(String label) |
169 |
{ |
|
170 | 0 |
_label = label; |
171 |
} |
|
172 |
|
|
173 |
/**
|
|
174 |
* Returns the value of the initial IPropertySelectionModel option
|
|
175 |
* @return a IPropertySelectionModel option value
|
|
176 |
*/
|
|
177 | 1 |
public String getValue()
|
178 |
{ |
|
179 | 1 |
return _value;
|
180 |
} |
|
181 |
|
|
182 |
/**
|
|
183 |
* Sets the value of the initial IPropertySelectionModel option
|
|
184 |
* @param value a IPropertySelectionModel option value
|
|
185 |
*/
|
|
186 | 0 |
public void setValue(String value) |
187 |
{ |
|
188 | 0 |
_value = value; |
189 |
} |
|
190 |
|
|
191 |
/**
|
|
192 |
* Returns the initial option
|
|
193 |
* @return a PropertySelectionModel option
|
|
194 |
*/
|
|
195 | 1 |
public Object getOption()
|
196 |
{ |
|
197 | 1 |
return _option;
|
198 |
} |
|
199 |
|
|
200 |
/**
|
|
201 |
* Sets the initial IPropertySelectionModel option
|
|
202 |
* @param option a IPropertySelectionModel option
|
|
203 |
*/
|
|
204 | 0 |
public void setOption(Object option) |
205 |
{ |
|
206 | 0 |
_option = option; |
207 |
} |
|
208 |
|
|
209 |
/**
|
|
210 |
* Empty model implementation. Avoids NullPointerExceptions when default
|
|
211 |
* constructor is used.
|
|
212 |
*/
|
|
213 |
private static final IPropertySelectionModel EMPTY_MODEL = new IPropertySelectionModel() |
|
214 |
{ |
|
215 |
/**
|
|
216 |
* @see org.apache.tapestry.form.IPropertySelectionModel#getOptionCount()
|
|
217 |
*/
|
|
218 | 2 |
public int getOptionCount() |
219 |
{ |
|
220 | 2 |
return 0;
|
221 |
} |
|
222 |
|
|
223 |
/**
|
|
224 |
* @see org.apache.tapestry.form.IPropertySelectionModel#getOption(int)
|
|
225 |
*/
|
|
226 | 0 |
public Object getOption(int index) |
227 |
{ |
|
228 | 0 |
return null; |
229 |
} |
|
230 |
|
|
231 |
/**
|
|
232 |
* @see org.apache.tapestry.form.IPropertySelectionModel#getLabel(int)
|
|
233 |
*/
|
|
234 | 0 |
public String getLabel(int index) |
235 |
{ |
|
236 | 0 |
return null; |
237 |
} |
|
238 |
|
|
239 |
/**
|
|
240 |
* @see org.apache.tapestry.form.IPropertySelectionModel#getValue(int)
|
|
241 |
*/
|
|
242 | 0 |
public String getValue(int index) |
243 |
{ |
|
244 | 0 |
return null; |
245 |
} |
|
246 |
|
|
247 |
/**
|
|
248 |
* @see org.apache.tapestry.form.IPropertySelectionModel#translateValue(java.lang.String)
|
|
249 |
*/
|
|
250 | 0 |
public Object translateValue(String value)
|
251 |
{ |
|
252 | 0 |
return null; |
253 |
} |
|
254 |
}; |
|
255 |
} |
|
256 |
|
|