001/**
002 * Copyright 2005-2018 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krad.uif.container;
017
018import java.util.HashSet;
019import java.util.Set;
020
021import org.apache.commons.collections.CollectionUtils;
022import org.apache.commons.lang.StringUtils;
023import org.kuali.rice.krad.datadictionary.parse.BeanTag;
024import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
025import org.kuali.rice.krad.datadictionary.parse.BeanTags;
026import org.kuali.rice.krad.uif.UifConstants;
027import org.kuali.rice.krad.uif.component.ClientSideState;
028import org.kuali.rice.krad.uif.component.Component;
029import org.kuali.rice.krad.uif.util.LifecycleElement;
030import org.kuali.rice.krad.uif.widget.Tabs;
031
032/**
033 * A group that presents its child Groups as tabs.  Items in this group's item list must be Groups
034 * themselves.
035 *
036 * @author Kuali Rice Team (rice.collab@kuali.org)
037 * @see Group
038 */
039@BeanTags({@BeanTag(name = "tabGroup", parent = "Uif-TabGroup"),
040        @BeanTag(name = "tabSection", parent = "Uif-TabSection"),
041        @BeanTag(name = "tabSubSection", parent = "Uif-TabSubSection")})
042public class TabGroup extends GroupBase {
043    private static final long serialVersionUID = 3L;
044
045    private Tabs tabsWidget;
046
047    // Required by ClientSideState annotation though not used by class
048    @ClientSideState(variableName = "activeTab")
049    private String defaultActiveTabId;
050
051    public TabGroup() {
052        super();
053    }
054
055    /**
056     * {@inheritDoc}
057     */
058    @Override
059    public void performFinalize(Object model, LifecycleElement parent) {
060        super.performFinalize(model, parent);
061        this.addDataAttribute(UifConstants.DataAttributes.TYPE, "Uif-TabGroup");
062
063        if (StringUtils.isBlank(defaultActiveTabId) && CollectionUtils.isNotEmpty(this.getItems())) {
064            defaultActiveTabId = this.getItems().get(0).getId();
065        }
066    }
067
068    /**
069     * Only groups are supported for this group.
070     *
071     * {@inheritDoc}
072     */
073    @Override
074    public Set<Class<? extends Component>> getSupportedComponents() {
075        Set<Class<? extends Component>> supportedComponents = new HashSet<Class<? extends Component>>();
076        supportedComponents.add(Group.class);
077
078        return supportedComponents;
079    }
080
081    /**
082     * Gets the widget which contains any configuration for the tab widget component used to render
083     * this TabGroup
084     *
085     * @return the tabsWidget
086     */
087    @BeanTagAttribute
088    public Tabs getTabsWidget() {
089        return this.tabsWidget;
090    }
091
092    /**
093     * @param tabsWidget the tabsWidget to set
094     */
095    public void setTabsWidget(Tabs tabsWidget) {
096        this.tabsWidget = tabsWidget;
097    }
098
099    /**
100     * Id of the active tab of the tab group when rendered.
101     *
102     * @return the default active tab of this tab group
103     */
104    @BeanTagAttribute
105    public String getDefaultActiveTabId() {
106        return defaultActiveTabId;
107    }
108
109    /**
110     * @see org.kuali.rice.krad.uif.container.TabGroup#getDefaultActiveTabId()
111     */
112    public void setDefaultActiveTabId(String defaultActiveTabId) {
113        this.defaultActiveTabId = defaultActiveTabId;
114    }
115}