01: /*
02: * $Id: PropertyPopulator.java 458270 2005-12-09 07:43:11Z ivaynberg $
03: * $Revision: 458270 $
04: * $Date: 2005-12-09 08:43:11 +0100 (Fri, 09 Dec 2005) $
05: *
06: * ====================================================================
07: * Licensed under the Apache License, Version 2.0 (the "License");
08: * you may not use this file except in compliance with the License.
09: * You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19: package wicket.extensions.markup.html.repeater.data.grid;
20:
21: import wicket.extensions.markup.html.repeater.refreshing.Item;
22: import wicket.markup.html.basic.Label;
23: import wicket.model.IModel;
24: import wicket.model.PropertyModel;
25:
26: /**
27: * A convinience implementation of {@link ICellPopulator} that adds a label that
28: * will display the value of the specified property. Non-string properties will
29: * be converted to a string before display.
30: * <p>
31: * Example
32: *
33: * <pre>
34: * ICellPopulator cityPopulator = new PropertyPopulator("address.city");
35: * </pre>
36: *
37: * @author Igor Vaynberg (ivaynberg)
38: *
39: */
40: public class PropertyPopulator implements ICellPopulator {
41: private static final long serialVersionUID = 1L;
42: private String property;
43:
44: /**
45: * Constructor
46: *
47: * @param property
48: * property whose value will be displayed in the cell. uses
49: * wicket's {@link PropertyModel} notation.
50: */
51: public PropertyPopulator(String property) {
52: if (property == null) {
53: throw new IllegalArgumentException(
54: "argument [property] cannot be null");
55: }
56: this .property = property;
57: }
58:
59: /**
60: * @see wicket.extensions.markup.html.repeater.data.grid.ICellPopulator#populateItem(wicket.extensions.markup.html.repeater.refreshing.Item,
61: * java.lang.String, wicket.model.IModel)
62: */
63: public void populateItem(Item cellItem, String componentId,
64: IModel rowModel) {
65: cellItem.add(new Label(componentId, new PropertyModel(rowModel,
66: property)));
67: }
68:
69: }
|