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.table.export; 018 019import org.apache.wicket.Component; 020import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator; 021import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn; 022import org.apache.wicket.markup.html.basic.Label; 023import org.apache.wicket.markup.repeater.Item; 024import org.apache.wicket.model.IModel; 025 026/** 027 * A helper implementation of {@link IExportableColumn}. This implementation requires you to only 028 * implement {@link #getDataModel(org.apache.wicket.model.IModel)}. 029 * @author Jesse Long 030 * @param <T> The type of each row in the table. 031 * @param <S> The type of the sort property of the table. 032 */ 033public abstract class AbstractExportableColumn<T, S> 034 extends AbstractColumn<T, S> 035 implements IExportableColumn<T, S> 036{ 037 /** 038 * Creates a new {@link AbstractExportableColumn} with the provided display model, and without a sort property. 039 * @param displayModel The {@link IModel} of the text to be used in the column header. 040 */ 041 public AbstractExportableColumn(IModel<String> displayModel) 042 { 043 super(displayModel); 044 } 045 046 /** 047 * Creates a new {@link AbstractExportableColumn} with the provided display model, and sort property. 048 * @param displayModel The {@link IModel} of the text to be used in the column header. 049 * @param sortProperty The sort property used by this column. 050 */ 051 public AbstractExportableColumn(IModel<String> displayModel, S sortProperty) 052 { 053 super(displayModel, sortProperty); 054 } 055 056 /** 057 * Creates a {@link Component} which will be used to display the content of the column in this row. 058 * The default implementation simply creates a label with the data model provided. 059 * @param componentId 060 * The component id of the display component. 061 * @param dataModel 062 * The model of the data for this column in the row. This should usually be passed as the model 063 * of the display component. 064 * @return a {@link Component} which will be used to display the content of the column in this row. 065 */ 066 protected Component createDisplayComponent(String componentId, IModel<?> dataModel) 067 { 068 return new Label(componentId, dataModel); 069 } 070 071 /** 072 * Populated the data for this column in the row into the {@code cellItem}. 073 * <p> 074 * This implementation adds the {@link Component} returned by {@link #createDisplayComponent(java.lang.String, org.apache.wicket.model.IModel) } 075 * to the cell. 076 * @param cellItem The cell to be populated. 077 * @param componentId The component id to be used for the component that will be added to the cell. 078 * @param rowModel A model of the row data. 079 */ 080 @Override 081 public void populateItem(Item<ICellPopulator<T>> cellItem, String componentId, IModel<T> rowModel) 082 { 083 cellItem.add(createDisplayComponent(componentId, getDataModel(rowModel))); 084 } 085}