001 // ---------- Attention: Generated code, please do not modify! ----------- 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 package org.apache.myfaces.tobago.component; 021 022 import javax.faces.context.FacesContext; 023 import org.apache.myfaces.tobago.context.Markup; 024 import org.apache.myfaces.tobago.internal.component.AbstractUIGridLayout; 025 import org.apache.myfaces.tobago.layout.Measure; 026 import org.apache.commons.lang.ArrayUtils; 027 import org.apache.commons.lang.StringUtils; 028 import org.apache.myfaces.tobago.component.MethodBindingToMethodExpression; 029 import org.apache.myfaces.tobago.component.MethodExpressionToMethodBinding; 030 import org.apache.myfaces.tobago.internal.util.Deprecation; 031 import org.apache.myfaces.tobago.renderkit.MarginValues; 032 import org.apache.myfaces.tobago.renderkit.SpacingValues; 033 import org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer; 034 import javax.el.ELException; 035 import javax.faces.FacesException; 036 import java.util.ArrayList; 037 import java.util.List; 038 import javax.el.MethodExpression; 039 import javax.el.ValueExpression; 040 041 /** 042 Renders a GridLayout. 043 <pre> 044 columns/rows ::= LAYOUT 045 LAYOUT ::= TOKEN [";" TOKEN]+ 046 TOKEN ::= FIXED | PIXEL | PROPORTIONAL 047 FIXED ::= "fixed" 048 PIXEL ::= NUMBER "px" 049 PROPORTIONAL ::= [NUMBER] "*" 050 </pre> 051 <p/> 052 <table border="1"> 053 <tr> 054 <th>Parent</th> 055 <th>Child</th> 056 <th>Okay?</th> 057 <th>Remarks</th> 058 </tr> 059 <tr> 060 <td>FIXED</td> 061 <td>any combination of FIXED or PIXEL but no PROPORTIONAL</td> 062 <td>okay</td> 063 <td>-</td> 064 </tr> 065 <tr> 066 <td>FIXED</td> 067 <td>any combination with at least one PROPORTIONAL</td> 068 <td>wrong</td> 069 <td>LayoutManager cannot compute the fixed value.</td> 070 </tr> 071 <tr> 072 <td>PIXEL</td> 073 <td>any combination of FIXED or PIXEL but no PROPORTIONAL</td> 074 <td>potentially wrong</td> 075 <td>The values depend on each other, the programmer has to keep consistency manually.</td> 076 </tr> 077 <tr> 078 <td>PIXEL</td> 079 <td>any combination with at least one PROPORTIONAL</td> 080 <td>okay</td> 081 <td>-</td> 082 </tr> 083 <tr> 084 <td>PROPORTIONAL</td> 085 <td>any combination of FIXED or PIXEL but no PROPORTIONAL</td> 086 <td>potentially wrong</td> 087 <td>No automatic matching:<ul><li>too little space: scroll bar</li> 088 <li>too much space: elements will be spread.</li></ul></td> 089 </tr> 090 <tr> 091 <td>PROPORTIONAL</td> 092 <td>any combination with at least one PROPORTIONAL</td> 093 <td>okay</td> 094 <td>-</td> 095 </tr> 096 </table> 097 * UIComponent class, generated from template {@code component1.2.stg} with class 098 * {@link org.apache.myfaces.tobago.internal.taglib.component.GridLayoutTagDeclaration}. 099 */ 100 public class UIGridLayout 101 extends AbstractUIGridLayout implements SupportsMarkup { 102 103 public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.GridLayout"; 104 105 public static final String COMPONENT_FAMILY = "org.apache.myfaces.tobago.GridLayout"; 106 107 private org.apache.myfaces.tobago.context.Markup markup; 108 private org.apache.myfaces.tobago.layout.Measure marginLeft; 109 private org.apache.myfaces.tobago.layout.Measure marginTop; 110 private org.apache.myfaces.tobago.layout.Measure marginRight; 111 private java.lang.String columns; 112 private org.apache.myfaces.tobago.layout.Measure cellspacing; 113 private java.lang.String rows; 114 private org.apache.myfaces.tobago.layout.Measure marginBottom; 115 private org.apache.myfaces.tobago.layout.Measure rowSpacing; 116 private org.apache.myfaces.tobago.context.Markup currentMarkup; 117 private org.apache.myfaces.tobago.layout.Measure margin; 118 private java.lang.String border; 119 private org.apache.myfaces.tobago.layout.Measure columnSpacing; 120 121 public String getFamily() { 122 return COMPONENT_FAMILY; 123 } 124 125 126 public org.apache.myfaces.tobago.context.Markup getMarkup() { 127 if (markup != null) { 128 return markup; 129 } 130 ValueExpression ve = getValueExpression("markup"); 131 if (ve != null) { 132 try { 133 Object object = ve.getValue(getFacesContext().getELContext()); 134 return Markup.valueOf(object); 135 } catch (ELException e) { 136 throw new FacesException(e); 137 } 138 } 139 return null; 140 } 141 142 public void setMarkup(org.apache.myfaces.tobago.context.Markup markup) { 143 this.markup = markup; 144 } 145 146 /** 147 Left margin between container component and the children. 148 149 */ 150 public org.apache.myfaces.tobago.layout.Measure getMarginLeft() { 151 if (marginLeft != null) { 152 return marginLeft; 153 } 154 ValueExpression ve = getValueExpression("marginLeft"); 155 if (ve != null) { 156 try { 157 Object object = ve.getValue(getFacesContext().getELContext()); 158 return Measure.valueOf(object); 159 } catch (ELException e) { 160 throw new FacesException(e); 161 } 162 } 163 return getMargin() != null 164 ? getMargin() 165 : ((MarginValues)getRenderer(getFacesContext())).getMarginLeft(getFacesContext(), this); 166 } 167 168 public void setMarginLeft(org.apache.myfaces.tobago.layout.Measure marginLeft) { 169 this.marginLeft = marginLeft; 170 } 171 172 /** 173 Top margin between container component and the children. 174 175 */ 176 public org.apache.myfaces.tobago.layout.Measure getMarginTop() { 177 if (marginTop != null) { 178 return marginTop; 179 } 180 ValueExpression ve = getValueExpression("marginTop"); 181 if (ve != null) { 182 try { 183 Object object = ve.getValue(getFacesContext().getELContext()); 184 return Measure.valueOf(object); 185 } catch (ELException e) { 186 throw new FacesException(e); 187 } 188 } 189 return getMargin() != null 190 ? getMargin() 191 : ((MarginValues)getRenderer(getFacesContext())).getMarginTop(getFacesContext(), this); 192 } 193 194 public void setMarginTop(org.apache.myfaces.tobago.layout.Measure marginTop) { 195 this.marginTop = marginTop; 196 } 197 198 /** 199 Right margin between container component and the children. 200 201 */ 202 public org.apache.myfaces.tobago.layout.Measure getMarginRight() { 203 if (marginRight != null) { 204 return marginRight; 205 } 206 ValueExpression ve = getValueExpression("marginRight"); 207 if (ve != null) { 208 try { 209 Object object = ve.getValue(getFacesContext().getELContext()); 210 return Measure.valueOf(object); 211 } catch (ELException e) { 212 throw new FacesException(e); 213 } 214 } 215 return getMargin() != null 216 ? getMargin() 217 : ((MarginValues)getRenderer(getFacesContext())).getMarginRight(getFacesContext(), this); 218 } 219 220 public void setMarginRight(org.apache.myfaces.tobago.layout.Measure marginRight) { 221 this.marginRight = marginRight; 222 } 223 224 /** 225 This value defines the layout constraints for column layout. 226 It is a semicolon separated list of layout tokens '[<n>]*', '<n>px' or 'auto'. 227 Where <n> is a non negative integer and the square brackets means optional. 228 Example: '2*;*;100px;auto'. 229 <br />Default: <code>1*</code> 230 */ 231 public java.lang.String getColumns() { 232 if (columns != null) { 233 return columns; 234 } 235 ValueExpression ve = getValueExpression("columns"); 236 if (ve != null) { 237 try { 238 java.lang.String columns = (java.lang.String) ve.getValue(getFacesContext().getELContext()); 239 if (columns != null) { 240 return columns; 241 } 242 } catch (ELException e) { 243 throw new FacesException(e); 244 } 245 } 246 return "1*"; 247 } 248 249 public void setColumns(java.lang.String columns) { 250 this.columns = columns; 251 } 252 253 /** 254 Spacing between component and layout cell's. 255 Can be overwritten by columnSpacing and rowSpacing. 256 257 @deprecated*/ 258 @Deprecated 259 public org.apache.myfaces.tobago.layout.Measure getCellspacing() { 260 if (cellspacing != null) { 261 return cellspacing; 262 } 263 ValueExpression ve = getValueExpression("cellspacing"); 264 if (ve != null) { 265 try { 266 Object object = ve.getValue(getFacesContext().getELContext()); 267 return Measure.valueOf(object); 268 } catch (ELException e) { 269 throw new FacesException(e); 270 } 271 } 272 return null; 273 } 274 275 @Deprecated 276 public void setCellspacing(org.apache.myfaces.tobago.layout.Measure cellspacing) { 277 this.cellspacing = cellspacing; 278 } 279 280 /** 281 This value defines the layout constraints for column layout. 282 It is a semicolon separated list of layout tokens '[<n>]*', '<n>px' or 'auto'. 283 Where <n> is a non negative integer and the square brackets means optional. 284 Example: '2*;*;100px;auto'. 285 <br />Default: <code>1*</code> 286 */ 287 public java.lang.String getRows() { 288 if (rows != null) { 289 return rows; 290 } 291 ValueExpression ve = getValueExpression("rows"); 292 if (ve != null) { 293 try { 294 java.lang.String rows = (java.lang.String) ve.getValue(getFacesContext().getELContext()); 295 if (rows != null) { 296 return rows; 297 } 298 } catch (ELException e) { 299 throw new FacesException(e); 300 } 301 } 302 return "1*"; 303 } 304 305 public void setRows(java.lang.String rows) { 306 this.rows = rows; 307 } 308 309 /** 310 Bottom margin between container component and the children. 311 312 */ 313 public org.apache.myfaces.tobago.layout.Measure getMarginBottom() { 314 if (marginBottom != null) { 315 return marginBottom; 316 } 317 ValueExpression ve = getValueExpression("marginBottom"); 318 if (ve != null) { 319 try { 320 Object object = ve.getValue(getFacesContext().getELContext()); 321 return Measure.valueOf(object); 322 } catch (ELException e) { 323 throw new FacesException(e); 324 } 325 } 326 return getMargin() != null 327 ? getMargin() 328 : ((MarginValues)getRenderer(getFacesContext())).getMarginBottom(getFacesContext(), this); 329 } 330 331 public void setMarginBottom(org.apache.myfaces.tobago.layout.Measure marginBottom) { 332 this.marginBottom = marginBottom; 333 } 334 335 /** 336 Spacing between the rows in the actual layout. 337 338 */ 339 public org.apache.myfaces.tobago.layout.Measure getRowSpacing() { 340 if (rowSpacing != null) { 341 return rowSpacing; 342 } 343 ValueExpression ve = getValueExpression("rowSpacing"); 344 if (ve != null) { 345 try { 346 Object object = ve.getValue(getFacesContext().getELContext()); 347 return Measure.valueOf(object); 348 } catch (ELException e) { 349 throw new FacesException(e); 350 } 351 } 352 return getCellspacing() != null 353 ? getCellspacing() 354 : ((SpacingValues)getRenderer(getFacesContext())).getRowSpacing(getFacesContext(), this); 355 } 356 357 public void setRowSpacing(org.apache.myfaces.tobago.layout.Measure rowSpacing) { 358 this.rowSpacing = rowSpacing; 359 } 360 361 public org.apache.myfaces.tobago.context.Markup getCurrentMarkup() { 362 if (currentMarkup != null) { 363 return currentMarkup; 364 } 365 ValueExpression ve = getValueExpression("currentMarkup"); 366 if (ve != null) { 367 try { 368 Object object = ve.getValue(getFacesContext().getELContext()); 369 return Markup.valueOf(object); 370 } catch (ELException e) { 371 throw new FacesException(e); 372 } 373 } 374 return null; 375 } 376 377 public void setCurrentMarkup(org.apache.myfaces.tobago.context.Markup currentMarkup) { 378 this.currentMarkup = currentMarkup; 379 } 380 381 /** 382 Margin between container component and the children. 383 384 */ 385 public org.apache.myfaces.tobago.layout.Measure getMargin() { 386 if (margin != null) { 387 return margin; 388 } 389 ValueExpression ve = getValueExpression("margin"); 390 if (ve != null) { 391 try { 392 Object object = ve.getValue(getFacesContext().getELContext()); 393 return Measure.valueOf(object); 394 } catch (ELException e) { 395 throw new FacesException(e); 396 } 397 } 398 return null; 399 } 400 401 public void setMargin(org.apache.myfaces.tobago.layout.Measure margin) { 402 this.margin = margin; 403 } 404 405 /** 406 Border size of this component. 407 408 */ 409 public java.lang.String getBorder() { 410 if (border != null) { 411 return border; 412 } 413 ValueExpression ve = getValueExpression("border"); 414 if (ve != null) { 415 try { 416 return (java.lang.String) ve.getValue(getFacesContext().getELContext()); 417 } catch (ELException e) { 418 throw new FacesException(e); 419 } 420 } 421 return null; 422 } 423 424 public void setBorder(java.lang.String border) { 425 this.border = border; 426 } 427 428 /** 429 Spacing between the columns in the actual layout. 430 431 */ 432 public org.apache.myfaces.tobago.layout.Measure getColumnSpacing() { 433 if (columnSpacing != null) { 434 return columnSpacing; 435 } 436 ValueExpression ve = getValueExpression("columnSpacing"); 437 if (ve != null) { 438 try { 439 Object object = ve.getValue(getFacesContext().getELContext()); 440 return Measure.valueOf(object); 441 } catch (ELException e) { 442 throw new FacesException(e); 443 } 444 } 445 return getCellspacing() != null 446 ? getCellspacing() 447 : ((SpacingValues)getRenderer(getFacesContext())).getColumnSpacing(getFacesContext(), this); 448 } 449 450 public void setColumnSpacing(org.apache.myfaces.tobago.layout.Measure columnSpacing) { 451 this.columnSpacing = columnSpacing; 452 } 453 454 public void restoreState(FacesContext context, Object componentState) { 455 Object[] values = (Object[]) componentState; 456 super.restoreState(context, values[0]); 457 markup = (org.apache.myfaces.tobago.context.Markup) values[1]; 458 marginLeft = (org.apache.myfaces.tobago.layout.Measure) values[2]; 459 marginTop = (org.apache.myfaces.tobago.layout.Measure) values[3]; 460 marginRight = (org.apache.myfaces.tobago.layout.Measure) values[4]; 461 columns = (java.lang.String) values[5]; 462 cellspacing = (org.apache.myfaces.tobago.layout.Measure) values[6]; 463 rows = (java.lang.String) values[7]; 464 marginBottom = (org.apache.myfaces.tobago.layout.Measure) values[8]; 465 rowSpacing = (org.apache.myfaces.tobago.layout.Measure) values[9]; 466 currentMarkup = (org.apache.myfaces.tobago.context.Markup) values[10]; 467 margin = (org.apache.myfaces.tobago.layout.Measure) values[11]; 468 border = (java.lang.String) values[12]; 469 columnSpacing = (org.apache.myfaces.tobago.layout.Measure) values[13]; 470 } 471 472 public Object saveState(FacesContext context) { 473 Object[] values = new Object[14]; 474 values[0] = super.saveState(context); 475 values[1] = markup; 476 values[2] = marginLeft; 477 values[3] = marginTop; 478 values[4] = marginRight; 479 values[5] = columns; 480 values[6] = cellspacing; 481 values[7] = rows; 482 values[8] = marginBottom; 483 values[9] = rowSpacing; 484 values[10] = currentMarkup; 485 values[11] = margin; 486 values[12] = border; 487 values[13] = columnSpacing; 488 return values; 489 } 490 491 492 }