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;
018
019import org.apache.wicket.Component;
020import org.apache.wicket.markup.html.basic.Label;
021import org.apache.wicket.model.IModel;
022
023/**
024 * A helper implementation for the IColumn interface
025 * 
026 * @author Igor Vaynberg ( ivaynberg )
027 * @param <T>
028 *            the type of the object that will be rendered in this column's cells
029 * @param <S>
030 *            the type of the sort property
031 */
032public abstract class AbstractColumn<T, S> implements IStyledColumn<T, S>
033{
034        private static final long serialVersionUID = 1L;
035
036        private final IModel<String> displayModel;
037
038        private final S sortProperty;
039
040        /**
041         * @param displayModel
042         *            model used to generate header text
043         * @param sortProperty
044         *            sort property this column represents
045         */
046        public AbstractColumn(final IModel<String> displayModel, final S sortProperty)
047        {
048                this.displayModel = displayModel;
049                this.sortProperty = sortProperty;
050        }
051
052        /**
053         * @param displayModel
054         *            model used to generate header text
055         */
056        public AbstractColumn(final IModel<String> displayModel)
057        {
058                this(displayModel, null);
059        }
060
061        /**
062         * @return returns display model to be used for the header component
063         */
064        public IModel<String> getDisplayModel()
065        {
066                return displayModel;
067        }
068
069        @Override
070        public S getSortProperty()
071        {
072                return sortProperty;
073        }
074
075        @Override
076        public Component getHeader(final String componentId)
077        {
078                return new Label(componentId, getDisplayModel());
079        }
080
081        @Override
082        public void detach()
083        {
084                if (displayModel != null)
085                {
086                        displayModel.detach();
087                }
088        }
089
090        @Override
091        public String getCssClass()
092        {
093                return null;
094        }
095}