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.tabs;
018
019import org.apache.wicket.markup.html.WebMarkupContainer;
020import org.apache.wicket.model.IModel;
021
022/**
023 * A simple decorator that will cache the panel returned from the first call to getPanel()
024 * 
025 * @see org.apache.wicket.extensions.markup.html.tabs.ITab
026 * @see org.apache.wicket.extensions.markup.html.tabs.TabbedPanel
027 * 
028 * @author Igor Vaynberg (ivaynberg)
029 */
030public class PanelCachingTab implements ITab
031{
032        private static final long serialVersionUID = 1L;
033
034        // Might Panel or Fragment or ...
035        private WebMarkupContainer panel;
036
037        private final ITab delegate;
038
039        /**
040         * Constructor
041         * 
042         * @param delegate
043         *            ITab implementation to decorate
044         */
045        public PanelCachingTab(final ITab delegate)
046        {
047                this.delegate = delegate;
048        }
049
050        /**
051         * {@inheritDoc}
052         */
053        @Override
054        public IModel<String> getTitle()
055        {
056                return delegate.getTitle();
057        }
058
059        /**
060         * {@inheritDoc}
061         */
062        @Override
063        public WebMarkupContainer getPanel(final String panelId)
064        {
065                if (panel == null)
066                {
067                        panel = delegate.getPanel(panelId);
068                }
069                return panel;
070        }
071
072        /**
073         * {@inheritDoc}
074         */
075        @Override
076        public boolean isVisible()
077        {
078                return delegate.isVisible();
079        }
080}