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