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.tree.table;
018
019import org.apache.wicket.Component;
020import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
021import org.apache.wicket.markup.repeater.Item;
022import org.apache.wicket.model.IModel;
023
024/**
025 * A column displaying the tree nodes hierarchy.
026 * 
027 * @author svenmeier
028 * @param <T>
029 *            node type
030 * @param <S>
031 *            the type of the sort property
032 */
033public class TreeColumn<T, S> extends AbstractTreeColumn<T, S>
034{
035
036        private static final long serialVersionUID = 1L;
037
038        /**
039         * Construct.
040         * 
041         * @param displayModel
042         *            model used to generate header text
043         */
044        public TreeColumn(IModel<String> displayModel)
045        {
046                super(displayModel);
047        }
048
049        /**
050         * Construct.
051         * 
052         * @param displayModel
053         *            model used to generate header text
054         * @param sortProperty
055         *            sort property
056         */
057        public TreeColumn(IModel<String> displayModel, S sortProperty)
058        {
059                super(displayModel, sortProperty);
060        }
061
062        @Override
063        public String getCssClass()
064        {
065                return "tree";
066        }
067
068        @Override
069        public void populateItem(Item<ICellPopulator<T>> cellItem, String componentId,
070                IModel<T> rowModel)
071        {
072                NodeModel<T> nodeModel = (NodeModel<T>)rowModel;
073
074                Component nodeComponent = getTree().newNodeComponent(componentId,
075                        nodeModel.getWrappedModel());
076
077                nodeComponent.add(new NodeBorder(nodeModel.getBranches()));
078
079                cellItem.add(nodeComponent);
080        }
081}