001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020 package org.apache.myfaces.tobago.component; 021 022 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL; 023 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TIP; 024 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DISABLED; 025 026 import javax.faces.el.ValueBinding; 027 import javax.faces.context.FacesContext; 028 029 /* 030 * Date: Mar 22, 2007 031 * Time: 10:51:16 PM 032 */ 033 034 public class UITab extends UIPanel { 035 036 public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Tab"; 037 038 private String label; 039 private String tip; 040 private Boolean disabled; 041 042 public String getTip() { 043 if (tip != null) { 044 return tip; 045 } 046 ValueBinding vb = getValueBinding(ATTR_TIP); 047 if (vb != null) { 048 return (String) vb.getValue(getFacesContext()); 049 } else { 050 return null; 051 } 052 } 053 054 public void setTip(String tip) { 055 this.tip = tip; 056 } 057 058 public String getLabel() { 059 if (label != null) { 060 return label; 061 } 062 ValueBinding vb = getValueBinding(ATTR_LABEL); 063 if (vb != null) { 064 return (String) vb.getValue(getFacesContext()); 065 } else { 066 return label; 067 } 068 } 069 070 public void setLabel(String label) { 071 this.label = label; 072 } 073 074 public boolean isDisabled() { 075 if (disabled != null) { 076 return disabled; 077 } 078 ValueBinding vb = getValueBinding(ATTR_DISABLED); 079 if (vb != null) { 080 return Boolean.TRUE.equals(vb.getValue(getFacesContext())); 081 } else { 082 return false; 083 } 084 } 085 086 public void setDisabled(boolean disabled) { 087 this.disabled = disabled; 088 } 089 090 public Object saveState(FacesContext context) { 091 Object[] state = new Object[4]; 092 state[0] = super.saveState(context); 093 state[1] = tip; 094 state[2] = label; 095 state[3] = disabled; 096 return state; 097 } 098 099 public void restoreState(FacesContext context, Object state) { 100 Object[] values = (Object[]) state; 101 super.restoreState(context, values[0]); 102 tip = (String) values[1]; 103 label = (String) values[2]; 104 disabled = (Boolean) values[3]; 105 } 106 }