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 java.lang.Boolean rowOverflow;
108      private org.apache.myfaces.tobago.context.Markup markup;
109      private org.apache.myfaces.tobago.layout.Measure marginLeft;
110      private org.apache.myfaces.tobago.layout.Measure marginTop;
111      private org.apache.myfaces.tobago.layout.Measure marginRight;
112      private java.lang.String columns;
113      private org.apache.myfaces.tobago.layout.Measure cellspacing;
114      private java.lang.String rows;
115      private org.apache.myfaces.tobago.layout.Measure marginBottom;
116      private java.lang.Boolean columnOverflow;
117      private org.apache.myfaces.tobago.layout.Measure rowSpacing;
118      private org.apache.myfaces.tobago.context.Markup currentMarkup;
119      private org.apache.myfaces.tobago.layout.Measure margin;
120      private java.lang.String border;
121      private org.apache.myfaces.tobago.layout.Measure columnSpacing;
122    
123      public String getFamily() {
124        return COMPONENT_FAMILY;
125      }
126    
127    
128      /**
129      This attribute is a hint for the layout manager. Should not be used in most cases.
130    
131      */
132      public boolean isRowOverflow() {
133        if (rowOverflow != null) {
134          return rowOverflow;
135        }
136        ValueExpression ve = getValueExpression("rowOverflow");
137        if (ve != null) {
138          try {
139            Boolean bool = (Boolean) ve.getValue(getFacesContext().getELContext());
140            if (bool != null) {
141              return bool;
142            }
143          } catch (ELException e) {
144                      throw new FacesException(e);
145              }
146        }
147        return false;
148      }
149    
150      public void setRowOverflow(boolean rowOverflow) {
151        this.rowOverflow = rowOverflow;
152      }
153    
154      public org.apache.myfaces.tobago.context.Markup getMarkup() {
155        if (markup != null) {
156          return markup;
157        }
158        ValueExpression ve = getValueExpression("markup");
159        if (ve != null) {
160          try {
161            Object object = ve.getValue(getFacesContext().getELContext());
162            return Markup.valueOf(object);
163          } catch (ELException e) {
164                      throw new FacesException(e);
165              }
166        }
167        return null;
168      }
169    
170      public void setMarkup(org.apache.myfaces.tobago.context.Markup markup) {
171        this.markup = markup;
172      }
173    
174      /**
175      Left margin between container component and the children.
176    
177      */
178      public org.apache.myfaces.tobago.layout.Measure getMarginLeft() {
179        if (marginLeft != null) {
180          return marginLeft;
181        }
182        ValueExpression ve = getValueExpression("marginLeft");
183        if (ve != null) {
184          try {
185            Object object = ve.getValue(getFacesContext().getELContext());
186            return Measure.valueOf(object);
187          } catch (ELException e) {
188                      throw new FacesException(e);
189              }
190        }
191        return getMargin() != null
192       ? getMargin()
193       : ((MarginValues)getRenderer(getFacesContext())).getMarginLeft(getFacesContext(), this);
194      }
195    
196      public void setMarginLeft(org.apache.myfaces.tobago.layout.Measure marginLeft) {
197        this.marginLeft = marginLeft;
198      }
199    
200      /**
201      Top margin between container component and the children.
202    
203      */
204      public org.apache.myfaces.tobago.layout.Measure getMarginTop() {
205        if (marginTop != null) {
206          return marginTop;
207        }
208        ValueExpression ve = getValueExpression("marginTop");
209        if (ve != null) {
210          try {
211            Object object = ve.getValue(getFacesContext().getELContext());
212            return Measure.valueOf(object);
213          } catch (ELException e) {
214                      throw new FacesException(e);
215              }
216        }
217        return getMargin() != null
218       ? getMargin()
219       : ((MarginValues)getRenderer(getFacesContext())).getMarginTop(getFacesContext(), this);
220      }
221    
222      public void setMarginTop(org.apache.myfaces.tobago.layout.Measure marginTop) {
223        this.marginTop = marginTop;
224      }
225    
226      /**
227      Right margin between container component and the children.
228    
229      */
230      public org.apache.myfaces.tobago.layout.Measure getMarginRight() {
231        if (marginRight != null) {
232          return marginRight;
233        }
234        ValueExpression ve = getValueExpression("marginRight");
235        if (ve != null) {
236          try {
237            Object object = ve.getValue(getFacesContext().getELContext());
238            return Measure.valueOf(object);
239          } catch (ELException e) {
240                      throw new FacesException(e);
241              }
242        }
243        return getMargin() != null
244       ? getMargin()
245       : ((MarginValues)getRenderer(getFacesContext())).getMarginRight(getFacesContext(), this);
246      }
247    
248      public void setMarginRight(org.apache.myfaces.tobago.layout.Measure marginRight) {
249        this.marginRight = marginRight;
250      }
251    
252      /**
253      This value defines the layout constraints for column layout.
254       It is a semicolon separated list of layout tokens '[&lt;n>]*', '&lt;n>px' or 'auto'.
255       Where &lt;n> is a non negative integer and the square brackets means optional.
256       Example: '2*;*;100px;auto'.
257      <br />Default: <code>1*</code>
258      */
259      public java.lang.String getColumns() {
260        if (columns != null) {
261          return columns;
262        }
263        ValueExpression ve = getValueExpression("columns");
264        if (ve != null) {
265          try {
266            java.lang.String columns = (java.lang.String) ve.getValue(getFacesContext().getELContext());
267            if (columns != null) {
268              return columns;
269            }
270          } catch (ELException e) {
271                      throw new FacesException(e);
272              }
273        }
274        return "1*";
275      }
276    
277      public void setColumns(java.lang.String columns) {
278        this.columns = columns;
279      }
280    
281      /**
282      Spacing between component and layout cell's.
283       Can be overwritten by columnSpacing and rowSpacing.
284    
285      @deprecated*/
286      @Deprecated
287      public org.apache.myfaces.tobago.layout.Measure getCellspacing() {
288        if (cellspacing != null) {
289          return cellspacing;
290        }
291        ValueExpression ve = getValueExpression("cellspacing");
292        if (ve != null) {
293          try {
294            Object object = ve.getValue(getFacesContext().getELContext());
295            return Measure.valueOf(object);
296          } catch (ELException e) {
297                      throw new FacesException(e);
298              }
299        }
300        return null;
301      }
302    
303      @Deprecated
304      public void setCellspacing(org.apache.myfaces.tobago.layout.Measure cellspacing) {
305        this.cellspacing = cellspacing;
306      }
307    
308      /**
309      This value defines the layout constraints for column layout.
310       It is a semicolon separated list of layout tokens '[&lt;n>]*', '&lt;n>px' or 'auto'.
311       Where &lt;n> is a non negative integer and the square brackets means optional.
312       Example: '2*;*;100px;auto'.
313      <br />Default: <code>1*</code>
314      */
315      public java.lang.String getRows() {
316        if (rows != null) {
317          return rows;
318        }
319        ValueExpression ve = getValueExpression("rows");
320        if (ve != null) {
321          try {
322            java.lang.String rows = (java.lang.String) ve.getValue(getFacesContext().getELContext());
323            if (rows != null) {
324              return rows;
325            }
326          } catch (ELException e) {
327                      throw new FacesException(e);
328              }
329        }
330        return "1*";
331      }
332    
333      public void setRows(java.lang.String rows) {
334        this.rows = rows;
335      }
336    
337      /**
338      Bottom margin between container component and the children.
339    
340      */
341      public org.apache.myfaces.tobago.layout.Measure getMarginBottom() {
342        if (marginBottom != null) {
343          return marginBottom;
344        }
345        ValueExpression ve = getValueExpression("marginBottom");
346        if (ve != null) {
347          try {
348            Object object = ve.getValue(getFacesContext().getELContext());
349            return Measure.valueOf(object);
350          } catch (ELException e) {
351                      throw new FacesException(e);
352              }
353        }
354        return getMargin() != null
355       ? getMargin()
356       : ((MarginValues)getRenderer(getFacesContext())).getMarginBottom(getFacesContext(), this);
357      }
358    
359      public void setMarginBottom(org.apache.myfaces.tobago.layout.Measure marginBottom) {
360        this.marginBottom = marginBottom;
361      }
362    
363      /**
364      This attribute is a hint for the layout manager. Should not be used in most cases.
365    
366      */
367      public boolean isColumnOverflow() {
368        if (columnOverflow != null) {
369          return columnOverflow;
370        }
371        ValueExpression ve = getValueExpression("columnOverflow");
372        if (ve != null) {
373          try {
374            Boolean bool = (Boolean) ve.getValue(getFacesContext().getELContext());
375            if (bool != null) {
376              return bool;
377            }
378          } catch (ELException e) {
379                      throw new FacesException(e);
380              }
381        }
382        return false;
383      }
384    
385      public void setColumnOverflow(boolean columnOverflow) {
386        this.columnOverflow = columnOverflow;
387      }
388    
389      /**
390      Spacing between the rows in the actual layout.
391    
392      */
393      public org.apache.myfaces.tobago.layout.Measure getRowSpacing() {
394        if (rowSpacing != null) {
395          return rowSpacing;
396        }
397        ValueExpression ve = getValueExpression("rowSpacing");
398        if (ve != null) {
399          try {
400            Object object = ve.getValue(getFacesContext().getELContext());
401            return Measure.valueOf(object);
402          } catch (ELException e) {
403                      throw new FacesException(e);
404              }
405        }
406        return getCellspacing() != null
407       ? getCellspacing()
408       : ((SpacingValues)getRenderer(getFacesContext())).getRowSpacing(getFacesContext(), this);
409      }
410    
411      public void setRowSpacing(org.apache.myfaces.tobago.layout.Measure rowSpacing) {
412        this.rowSpacing = rowSpacing;
413      }
414    
415      public org.apache.myfaces.tobago.context.Markup getCurrentMarkup() {
416        if (currentMarkup != null) {
417          return currentMarkup;
418        }
419        return null;
420      }
421    
422      public void setCurrentMarkup(org.apache.myfaces.tobago.context.Markup currentMarkup) {
423        this.currentMarkup = currentMarkup;
424      }
425    
426      /**
427      Margin between container component and the children.
428    
429      */
430      public org.apache.myfaces.tobago.layout.Measure getMargin() {
431        if (margin != null) {
432          return margin;
433        }
434        ValueExpression ve = getValueExpression("margin");
435        if (ve != null) {
436          try {
437            Object object = ve.getValue(getFacesContext().getELContext());
438            return Measure.valueOf(object);
439          } catch (ELException e) {
440                      throw new FacesException(e);
441              }
442        }
443        return null;
444      }
445    
446      public void setMargin(org.apache.myfaces.tobago.layout.Measure margin) {
447        this.margin = margin;
448      }
449    
450      /**
451      Border size of this component.
452    
453      */
454      public java.lang.String getBorder() {
455        if (border != null) {
456          return border;
457        }
458        ValueExpression ve = getValueExpression("border");
459        if (ve != null) {
460          try {
461            return (java.lang.String) ve.getValue(getFacesContext().getELContext());
462          } catch (ELException e) {
463                      throw new FacesException(e);
464              }
465        }
466        return null;
467      }
468    
469      public void setBorder(java.lang.String border) {
470        this.border = border;
471      }
472    
473      /**
474      Spacing between the columns in the actual layout.
475    
476      */
477      public org.apache.myfaces.tobago.layout.Measure getColumnSpacing() {
478        if (columnSpacing != null) {
479          return columnSpacing;
480        }
481        ValueExpression ve = getValueExpression("columnSpacing");
482        if (ve != null) {
483          try {
484            Object object = ve.getValue(getFacesContext().getELContext());
485            return Measure.valueOf(object);
486          } catch (ELException e) {
487                      throw new FacesException(e);
488              }
489        }
490        return getCellspacing() != null
491       ? getCellspacing()
492       : ((SpacingValues)getRenderer(getFacesContext())).getColumnSpacing(getFacesContext(), this);
493      }
494    
495      public void setColumnSpacing(org.apache.myfaces.tobago.layout.Measure columnSpacing) {
496        this.columnSpacing = columnSpacing;
497      }
498    
499      public void restoreState(FacesContext context, Object componentState) {
500        Object[] values = (Object[]) componentState;
501        super.restoreState(context, values[0]);
502        rowOverflow = (java.lang.Boolean) values[1];
503        markup = (org.apache.myfaces.tobago.context.Markup) values[2];
504        marginLeft = (org.apache.myfaces.tobago.layout.Measure) values[3];
505        marginTop = (org.apache.myfaces.tobago.layout.Measure) values[4];
506        marginRight = (org.apache.myfaces.tobago.layout.Measure) values[5];
507        columns = (java.lang.String) values[6];
508        cellspacing = (org.apache.myfaces.tobago.layout.Measure) values[7];
509        rows = (java.lang.String) values[8];
510        marginBottom = (org.apache.myfaces.tobago.layout.Measure) values[9];
511        columnOverflow = (java.lang.Boolean) values[10];
512        rowSpacing = (org.apache.myfaces.tobago.layout.Measure) values[11];
513        margin = (org.apache.myfaces.tobago.layout.Measure) values[12];
514        border = (java.lang.String) values[13];
515        columnSpacing = (org.apache.myfaces.tobago.layout.Measure) values[14];
516      }
517    
518      public Object saveState(FacesContext context) {
519        Object[] values = new Object[15];
520        values[0] = super.saveState(context);
521        values[1] = rowOverflow;
522        values[2] = markup;
523        values[3] = marginLeft;
524        values[4] = marginTop;
525        values[5] = marginRight;
526        values[6] = columns;
527        values[7] = cellspacing;
528        values[8] = rows;
529        values[9] = marginBottom;
530        values[10] = columnOverflow;
531        values[11] = rowSpacing;
532        values[12] = margin;
533        values[13] = border;
534        values[14] = columnSpacing;
535        currentMarkup = null;
536        return values;
537      }
538    
539    
540    }