001 package org.apache.myfaces.tobago.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 static org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL; 021 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TIP; 022 023 import javax.faces.el.ValueBinding; 024 import javax.faces.context.FacesContext; 025 026 /* 027 * Date: Mar 22, 2007 028 * Time: 10:51:16 PM 029 */ 030 031 public class UITab extends UIPanel { 032 033 public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Tab"; 034 035 private String label; 036 private String tip; 037 038 public String getTip() { 039 if (tip != null) { 040 return tip; 041 } 042 ValueBinding vb = getValueBinding(ATTR_TIP); 043 if (vb != null) { 044 return (String) vb.getValue(getFacesContext()); 045 } else { 046 return null; 047 } 048 } 049 050 public void setTip(String tip) { 051 this.tip = tip; 052 } 053 054 public String getLabel() { 055 if (label != null) { 056 return label; 057 } 058 ValueBinding vb = getValueBinding(ATTR_LABEL); 059 if (vb != null) { 060 return (String) vb.getValue(getFacesContext()); 061 } else { 062 return label; 063 } 064 } 065 066 public void setLabel(String label) { 067 this.label = label; 068 } 069 070 public Object saveState(FacesContext context) { 071 Object[] state = new Object[3]; 072 state[0] = super.saveState(context); 073 state[1] = tip; 074 state[2] = label; 075 return state; 076 } 077 078 public void restoreState(FacesContext context, Object state) { 079 Object[] values = (Object[]) state; 080 super.restoreState(context, values[0]); 081 tip = (String) values[1]; 082 label = (String) values[2]; 083 } 084 }