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 org.apache.myfaces.tobago.component.ComponentUtil;
023    import org.apache.myfaces.tobago.component.UITabGroup;
024    import org.apache.myfaces.tobago.util.Deprecation;
025    
026    import javax.faces.application.Application;
027    import javax.faces.component.UIComponent;
028    import javax.faces.context.FacesContext;
029    
030    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_IMMEDIATE;
031    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SELECTED_INDEX;
032    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_NAVIGATION_BAR;
033    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SWITCH_TYPE;
034    import static org.apache.myfaces.tobago.component.UITabGroup.SWITCH_TYPE_CLIENT;
035    import static org.apache.myfaces.tobago.component.UITabGroup.SWITCH_TYPE_RELOAD_PAGE;
036    
037    public class TabGroupTag extends TobagoTag
038        implements TabGroupTagDeclaration {
039    
040      private static final Log LOG = LogFactory.getLog(TabGroupTag.class);
041    
042      private String selectedIndex;
043      private String switchType;
044      private String immediate;
045      private String state;
046      private String showNavigationBar;
047      private String tabChangeListener;
048    
049      @Override
050      public String getComponentType() {
051        return UITabGroup.COMPONENT_TYPE;
052      }
053    
054      @Override
055      protected void setProperties(UIComponent component) {
056        super.setProperties(component);
057        ComponentUtil.setIntegerProperty(component, ATTR_SELECTED_INDEX, selectedIndex);
058        ComponentUtil.setIntegerProperty(component, ATTR_SELECTED_INDEX, state);
059        ComponentUtil.setStringProperty(component, ATTR_SWITCH_TYPE, switchType);
060        ComponentUtil.setBooleanProperty(component, ATTR_IMMEDIATE, immediate);
061        ComponentUtil.setBooleanProperty(component, ATTR_SHOW_NAVIGATION_BAR, showNavigationBar);
062        if (tabChangeListener != null && component instanceof  UITabGroup && isValueReference(tabChangeListener)) {
063          final Application application = FacesContext.getCurrentInstance().getApplication();
064          final javax.faces.el.MethodBinding methodBinding = application.createMethodBinding(tabChangeListener,
065              new Class[] {org.apache.myfaces.tobago.event.TabChangeEvent.class});
066          ((UITabGroup) component).setTabChangeListener(methodBinding);
067        }
068      }
069    
070      @Override
071      public void release() {
072        super.release();
073        state = null;
074        switchType = null;
075        immediate = null;
076        selectedIndex = null;
077        showNavigationBar = null;
078        tabChangeListener = null;
079      }
080    
081      public void setServerside(String serverside) {
082        Deprecation.LOG.error("The attribute 'serverside' of 'UITabGroup' is deprecated. "
083            + "Please refer the documentation for further information.");
084        this.switchType = Boolean.valueOf(serverside)
085            ? SWITCH_TYPE_RELOAD_PAGE : SWITCH_TYPE_CLIENT;
086      }
087    
088      public void setState(String state) {
089        Deprecation.LOG.error("The attribute 'state' of 'UITabGroup' is deprecated. "
090            + "Please refer the documentation for further information.");
091        this.state = state;
092      }
093    
094      public void setSelectedIndex(String selectedIndex) {
095        this.selectedIndex = selectedIndex;
096      }
097    
098      public void setSwitchType(String switchType) {
099        this.switchType = switchType;
100      }
101    
102      public void setImmediate(String immediate) {
103        this.immediate = immediate;
104      }
105    
106      public String getShowNavigationBar() {
107        return showNavigationBar;
108      }
109    
110      public void setShowNavigationBar(String showNavigationBar) {
111        this.showNavigationBar = showNavigationBar;
112      }
113    
114      public String getTabChangeListener() {
115        return tabChangeListener;
116      }
117    
118      public void setTabChangeListener(final String tabChangeListener) {
119        this.tabChangeListener = tabChangeListener;
120      }
121    }
122