View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.uif.container;
17  
18  import java.util.HashSet;
19  import java.util.Set;
20  
21  import org.apache.commons.collections.CollectionUtils;
22  import org.apache.commons.lang.StringUtils;
23  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
24  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
25  import org.kuali.rice.krad.datadictionary.parse.BeanTags;
26  import org.kuali.rice.krad.uif.UifConstants;
27  import org.kuali.rice.krad.uif.component.ClientSideState;
28  import org.kuali.rice.krad.uif.component.Component;
29  import org.kuali.rice.krad.uif.util.LifecycleElement;
30  import org.kuali.rice.krad.uif.widget.Tabs;
31  
32  /**
33   * A group that presents its child Groups as tabs.  Items in this group's item list must be Groups
34   * themselves.
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   * @see Group
38   */
39  @BeanTags({@BeanTag(name = "tabGroup", parent = "Uif-TabGroup"),
40          @BeanTag(name = "tabSection", parent = "Uif-TabSection"),
41          @BeanTag(name = "tabSubSection", parent = "Uif-TabSubSection")})
42  public class TabGroup extends GroupBase {
43      private static final long serialVersionUID = 3L;
44  
45      private Tabs tabsWidget;
46  
47      // Required by ClientSideState annotation though not used by class
48      @ClientSideState(variableName = "activeTab")
49      private String defaultActiveTabId;
50  
51      public TabGroup() {
52          super();
53      }
54  
55      /**
56       * {@inheritDoc}
57       */
58      @Override
59      public void performFinalize(Object model, LifecycleElement parent) {
60          super.performFinalize(model, parent);
61          this.addDataAttribute(UifConstants.DataAttributes.TYPE, "Uif-TabGroup");
62  
63          if (StringUtils.isBlank(defaultActiveTabId) && CollectionUtils.isNotEmpty(this.getItems())) {
64              defaultActiveTabId = this.getItems().get(0).getId();
65          }
66      }
67  
68      /**
69       * Only groups are supported for this group.
70       *
71       * {@inheritDoc}
72       */
73      @Override
74      public Set<Class<? extends Component>> getSupportedComponents() {
75          Set<Class<? extends Component>> supportedComponents = new HashSet<Class<? extends Component>>();
76          supportedComponents.add(Group.class);
77  
78          return supportedComponents;
79      }
80  
81      /**
82       * Gets the widget which contains any configuration for the tab widget component used to render
83       * this TabGroup
84       *
85       * @return the tabsWidget
86       */
87      @BeanTagAttribute
88      public Tabs getTabsWidget() {
89          return this.tabsWidget;
90      }
91  
92      /**
93       * @param tabsWidget the tabsWidget to set
94       */
95      public void setTabsWidget(Tabs tabsWidget) {
96          this.tabsWidget = tabsWidget;
97      }
98  
99      /**
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 }