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