001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.extensions.markup.html.repeater.data.grid; 018 019import org.apache.wicket.markup.repeater.Item; 020import org.apache.wicket.model.IDetachable; 021import org.apache.wicket.model.IModel; 022import org.apache.wicket.util.io.IClusterable; 023 024/** 025 * Represents an object that is capable of populating an {@link Item} container representing a cell 026 * in a {@link DataGridView} with components. 027 * <p> 028 * Example 029 * <p> 030 * 031 * <pre> 032 * class NamePopulator implements ICellPopulator 033 * { 034 * void populateItem(final Item cellItem, final String componentId, final IModel rowModel) { 035 * User user=(User)rowModel.getObject(cellItem); 036 * String name=user.getFirstName()+" "+user.getLastName(); 037 * cellItem.add(new Label(componentId, name); 038 * }} 039 * </pre> 040 * 041 * In this example the IDataProvider assigned to the DataGridView retrieves User objects from the 042 * database. The cell populator adds a label to the cell that will display the full name of the 043 * user. 044 * 045 * @see DataGridView 046 * @see Item 047 * 048 * @author Igor Vaynberg (ivaynberg) 049 * 050 * @param <T> 051 * Model object type 052 */ 053public interface ICellPopulator<T> extends IClusterable, IDetachable 054{ 055 /** 056 * Method used to populate a cell in the {@link DataGridView} 057 * 058 * <b>Implementation MUST add a component to the cellItem using the component id provided by 059 * componentId argument, otherwise a WicketRuntimeException will be thrown</b> 060 * 061 * @param cellItem 062 * the item representing the current table cell being rendered 063 * @param componentId 064 * the id of the component used to render the cell (only one component should be 065 * added to the cell) 066 * @param rowModel 067 * the model of the row item being rendered. this model usually contains the model 068 * provided by the data provider. 069 * 070 * @see Item 071 */ 072 void populateItem(final Item<ICellPopulator<T>> cellItem, final String componentId, 073 final IModel<T> rowModel); 074}