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.nested;
018
019import org.apache.wicket.markup.ComponentTag;
020import org.apache.wicket.markup.repeater.Item;
021import org.apache.wicket.model.IModel;
022
023/**
024 * A branch is a container for a single node and its children inside a {@link Subtree}.
025 * 
026 * @see Subtree#newBranchItem(String, int, IModel)
027 * 
028 * @author svenmeier
029 */
030public class BranchItem<T> extends Item<T>
031{
032
033        private static final long serialVersionUID = 1L;
034
035        public BranchItem(String id, int index, IModel<T> model)
036        {
037                super(id, index, model);
038
039                setOutputMarkupId(true);
040        }
041
042        @Override
043        protected void onComponentTag(ComponentTag tag)
044        {
045                super.onComponentTag(tag);
046
047                if (isLast())
048                {
049                        tag.put("class", "tree-branch tree-branch-last");
050                }
051                else
052                {
053                        tag.put("class", "tree-branch tree-branch-mid");
054                }
055        }
056
057        /**
058         * Is this the last branch in the containing subtree.
059         */
060        protected boolean isLast()
061        {
062                return getIndex() == getParent().size() - 1;
063        }
064}