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_ALIGN;
021    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL;
022    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SORTABLE;
023    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_WIDTH;
024    
025    import javax.faces.context.FacesContext;
026    import javax.faces.el.ValueBinding;
027    
028    
029    /*
030     * Date: 18.04.2006
031     * Time: 21:50:29
032     */
033    public class UIColumn extends javax.faces.component.UIColumn implements SupportsMarkup {
034      public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Column";
035      private Boolean sortable;
036      private String align;
037      private String label;
038      private String[] markup;
039      private String width;
040    
041      public void restoreState(FacesContext context, Object state) {
042        Object[] values = (Object[]) state;
043        super.restoreState(context, values[0]);
044        align = (String) values[1];
045        sortable = (Boolean) values[2];
046        label = (String) values[3];
047        markup = (String[]) values[4];
048        width = (String) values[5];
049      }
050    
051      public Object saveState(FacesContext context) {
052        Object[] values = new Object[6];
053        values[0] = super.saveState(context);
054        values[1] = align;
055        values[2] = sortable;
056        values[3] = label;
057        values[4] = markup;
058        values[5] = width;
059        return values;
060      }
061    
062      public String[] getMarkup() {
063        if (markup != null) {
064          return markup;
065        }
066        return ComponentUtil.getMarkupBinding(getFacesContext(), this);
067      }
068    
069      public void setMarkup(String[] markup) {
070        this.markup = markup;
071      }
072    
073      public boolean isSortable() {
074        if (sortable != null) {
075          return sortable;
076        }
077        ValueBinding vb = getValueBinding(ATTR_SORTABLE);
078        if (vb != null) {
079          return (Boolean.TRUE.equals(vb.getValue(getFacesContext())));
080        } else {
081          return false;
082        }
083      }
084    
085      public void setSortable(boolean sortable) {
086        this.sortable = sortable;
087      }
088    
089      public String getAlign() {
090        if (align != null) {
091          return align;
092        }
093        ValueBinding vb = getValueBinding(ATTR_ALIGN);
094        if (vb != null) {
095          return (String) vb.getValue(getFacesContext());
096        } else {
097          return align;
098        }
099      }
100    
101      public void setAlign(String align) {
102        this.align = align;
103      }
104    
105      public String getLabel() {
106        if (label != null) {
107          return label;
108        }
109        ValueBinding vb = getValueBinding(ATTR_LABEL);
110        if (vb != null) {
111          return (String) vb.getValue(getFacesContext());
112        } else {
113          return label;
114        }
115      }
116    
117      public void setLabel(String label) {
118        this.label = label;
119      }
120    
121      public String getWidth() {
122        if (width != null) {
123          return width;
124        }
125        ValueBinding vb = getValueBinding(ATTR_WIDTH);
126        if (vb != null) {
127          return (String) vb.getValue(getFacesContext());
128        } else {
129          return RelativeLayoutToken.DEFAULT_TOKEN_STRING;
130        }
131      }
132    
133      public void setWidth(String width) {
134        this.width = width;
135      }
136    
137    }