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