001: /*
002: * $Id: PropertyColumn.java 460410 2006-04-27 00:23:51Z ivaynberg $
003: * $Revision: 460410 $
004: * $Date: 2006-04-27 02:23:51 +0200 (Thu, 27 Apr 2006) $
005: *
006: * ====================================================================
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: */
019: package wicket.extensions.markup.html.repeater.data.table;
020:
021: import wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
022: import wicket.extensions.markup.html.repeater.refreshing.Item;
023: import wicket.markup.html.basic.Label;
024: import wicket.model.IModel;
025: import wicket.model.PropertyModel;
026:
027: /**
028: * A convinience implementation of column that adds a label to the cell whose
029: * model is determined by the provided wicket property expression (same as used
030: * by {@link PropertyModel}) that is evaluated against the current row's model
031: * object
032: * <p>
033: * Example
034: *
035: * <pre>
036: * columns[0] = new PropertyColumn(new Model("First Name"), "name.first");
037: * </pre>
038: *
039: * The above will attach a label to the cell with a property model for the
040: * expression "name.first"
041: *
042: * @see PropertyModel
043: *
044: * @author Igor Vaynberg ( ivaynberg )
045: *
046: */
047: public class PropertyColumn extends AbstractColumn {
048: private static final long serialVersionUID = 1L;
049:
050: private final String propertyExpression;
051:
052: /**
053: * Creates a property column that is also sortable
054: *
055: * @param displayModel
056: * display model
057: * @param sortProperty
058: * sort property
059: * @param propertyExpression
060: * wicket property expression used by PropertyModel
061: */
062: public PropertyColumn(IModel displayModel, String sortProperty,
063: String propertyExpression) {
064: super (displayModel, sortProperty);
065: this .propertyExpression = propertyExpression;
066: }
067:
068: /**
069: * Creates a non sortable property column
070: *
071: * @param displayModel
072: * display model
073: * @param propertyExpressions
074: * wicket property expression
075: * @see PropertyModel
076: */
077: public PropertyColumn(IModel displayModel,
078: String propertyExpressions) {
079: super (displayModel, null);
080: this .propertyExpression = propertyExpressions;
081: }
082:
083: /**
084: * Implementation of populateItem which adds a label to the cell whose model
085: * is the provided property expression evaluated agains rowModelObject
086: *
087: * @see ICellPopulator#populateItem(Item, String, IModel)
088: */
089: public void populateItem(Item item, String componentId, IModel model) {
090: item.add(new Label(componentId, createLabelModel(model)));
091: }
092:
093: //TODO Post 1.3: rename embeddedModel to itemModel
094: protected IModel createLabelModel(IModel embeddedModel) {
095: return new PropertyModel(embeddedModel, propertyExpression);
096: }
097:
098: /**
099: * @return wicket property expression
100: */
101: public String getPropertyExpression() {
102: return propertyExpression;
103: }
104:
105: }
|