001    package org.apache.myfaces.tobago.taglib.component;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more
005     * contributor license agreements.  See the NOTICE file distributed with
006     * this work for additional information regarding copyright ownership.
007     * The ASF licenses this file to You under the Apache License, Version 2.0
008     * (the "License"); you may not use this file except in compliance with
009     * the License.  You may obtain a copy of the License at
010     *
011     *      http://www.apache.org/licenses/LICENSE-2.0
012     *
013     * Unless required by applicable law or agreed to in writing, software
014     * distributed under the License is distributed on an "AS IS" BASIS,
015     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016     * See the License for the specific language governing permissions and
017     * limitations under the License.
018     */
019    
020    import org.apache.commons.logging.Log;
021    import org.apache.commons.logging.LogFactory;
022    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_IMMEDIATE;
023    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_NAVIGATION_BAR;
024    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SELECTED_INDEX;
025    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SWITCH_TYPE;
026    import org.apache.myfaces.tobago.component.ComponentUtil;
027    import org.apache.myfaces.tobago.component.UITabGroup;
028    import static org.apache.myfaces.tobago.component.UITabGroup.SWITCH_TYPE_CLIENT;
029    import static org.apache.myfaces.tobago.component.UITabGroup.SWITCH_TYPE_RELOAD_PAGE;
030    
031    import javax.faces.component.UIComponent;
032    
033    public class TabGroupTag extends TobagoTag
034        implements TabGroupTagDeclaration {
035    
036      private static final Log LOG = LogFactory.getLog(TabGroupTag.class);
037    
038      private String selectedIndex;
039      private String switchType;
040      private String immediate;
041      private String state;
042      private String showNavigationBar;
043    
044      @Override
045      public String getComponentType() {
046        return UITabGroup.COMPONENT_TYPE;
047      }
048    
049      @Override
050      protected void setProperties(UIComponent component) {
051        super.setProperties(component);
052        ComponentUtil.setIntegerProperty(component, ATTR_SELECTED_INDEX, selectedIndex);
053        ComponentUtil.setIntegerProperty(component, ATTR_SELECTED_INDEX, state);
054        ComponentUtil.setStringProperty(component, ATTR_SWITCH_TYPE, switchType);
055        ComponentUtil.setBooleanProperty(component, ATTR_IMMEDIATE, immediate);
056        ComponentUtil.setBooleanProperty(component, ATTR_SHOW_NAVIGATION_BAR, showNavigationBar);
057      }
058    
059      @Override
060      public void release() {
061        super.release();
062        state = null;
063        switchType = null;
064        immediate = null;
065        selectedIndex = null;
066        showNavigationBar = null;
067      }
068    
069      public void setServerside(String serverside) {
070        LOG.warn("Attribute 'serverside' is deprecated! Use 'switchType' instead.");
071        this.switchType = Boolean.valueOf(serverside)
072            ? SWITCH_TYPE_RELOAD_PAGE : SWITCH_TYPE_CLIENT;
073      }
074    
075      public void setState(String state) {
076        this.state = state;
077      }
078    
079      public void setSelectedIndex(String selectedIndex) {
080        this.selectedIndex = selectedIndex;
081      }
082    
083      public void setSwitchType(String switchType) {
084        this.switchType = switchType;
085      }
086    
087      public void setImmediate(String immediate) {
088        this.immediate = immediate;
089      }
090    
091      public String getShowNavigationBar() {
092        return showNavigationBar;
093      }
094    
095      public void setShowNavigationBar(String showNavigationBar) {
096        this.showNavigationBar = showNavigationBar;
097      }
098    }
099