View Javadoc

1   // ---------- Attention: Generated code, please do not modify! -----------  
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.myfaces.tobago.component;
21  
22  import javax.faces.context.FacesContext;
23  import org.apache.myfaces.tobago.context.Markup;
24  import org.apache.myfaces.tobago.internal.component.AbstractUIGridLayout;
25  import org.apache.myfaces.tobago.layout.Measure;
26  import org.apache.myfaces.tobago.internal.util.ArrayUtils;
27  import org.apache.myfaces.tobago.internal.util.StringUtils;
28  import org.apache.myfaces.tobago.internal.util.Deprecation;
29  import org.apache.myfaces.tobago.renderkit.MarginValues;
30  import org.apache.myfaces.tobago.renderkit.SpacingValues;
31  import org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer;
32  import javax.el.ELException;
33  import javax.faces.FacesException;
34  import java.util.ArrayList;
35  import java.util.List;
36  import javax.el.MethodExpression;
37  import javax.el.ValueExpression;
38  
39  /** 
40   Renders a GridLayout.
41    <pre>
42    columns/rows ::= LAYOUT
43    LAYOUT       ::= TOKEN [";" TOKEN]+
44    TOKEN        ::= AUTO | PIXEL | PROPORTIONAL
45    AUTO         ::= "auto" | "fixed"
46    PIXEL        ::= NUMBER "px"
47    PROPORTIONAL ::= [NUMBER] "*"
48    </pre>
49    <p/>
50    <table border="1">
51    <tr>
52    <th>Parent</th>
53    <th>Child</th>
54    <th>Okay?</th>
55    <th>Remarks</th>
56    </tr>
57    <tr>
58    <td>AUTO</td>
59    <td>any combination of AUTO or PIXEL but no PROPORTIONAL</td>
60    <td>okay</td>
61    <td>-</td>
62    </tr>
63    <tr>
64    <td>AUTO</td>
65    <td>any combination with at least one PROPORTIONAL</td>
66    <td>wrong</td>
67    <td>LayoutManager cannot compute the auto value.</td>
68    </tr>
69    <tr>
70    <td>PIXEL</td>
71    <td>any combination of AUTO or PIXEL but no PROPORTIONAL</td>
72    <td>potentially wrong</td>
73    <td>The values depend on each other, the programmer has to keep consistency manually.</td>
74    </tr>
75    <tr>
76    <td>PIXEL</td>
77    <td>any combination with at least one PROPORTIONAL</td>
78    <td>okay</td>
79    <td>-</td>
80    </tr>
81    <tr>
82    <td>PROPORTIONAL</td>
83    <td>any combination of AUTO or PIXEL but no PROPORTIONAL</td>
84    <td>potentially wrong</td>
85    <td>No automatic matching:<ul><li>too little space: scroll bar</li>
86    <li>too much space: elements will be spread.</li></ul></td>
87    </tr>
88    <tr>
89    <td>PROPORTIONAL</td>
90    <td>any combination with at least one PROPORTIONAL</td>
91    <td>okay</td>
92    <td>-</td>
93    </tr>
94    </table>
95    * UIComponent class, generated from template {@code component2.0.stg} with class
96    * {@link org.apache.myfaces.tobago.internal.taglib.component.GridLayoutTagDeclaration}.
97   */
98  public class UIGridLayout
99      extends AbstractUIGridLayout implements SupportsMarkup {
100 
101   public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.GridLayout";
102 
103   public static final String COMPONENT_FAMILY = "org.apache.myfaces.tobago.GridLayout";
104 
105   private org.apache.myfaces.tobago.context.Markup currentMarkup;
106 
107   enum PropertyKeys {
108     rowOverflow,
109     markup,
110     marginLeft,
111     marginTop,
112     marginRight,
113     columns,
114     rigid,
115     cellspacing,
116     rows,
117     marginBottom,
118     columnOverflow,
119     rowSpacing,
120     margin,
121     border,
122     columnSpacing,
123   }
124 
125   public String getFamily() {
126     return COMPONENT_FAMILY;
127   }
128 
129 
130   /**
131   This attribute is a hint for the layout manager. Should not be used in most cases.
132 
133   */
134   public boolean isRowOverflow() {
135     Boolean bool = (Boolean) getStateHelper().eval(PropertyKeys.rowOverflow);
136     if (bool != null) {
137       return bool;
138     }
139     return false;
140   }
141 
142   public void setRowOverflow(boolean rowOverflow) {
143     getStateHelper().put(PropertyKeys.rowOverflow, rowOverflow);
144   }
145 
146   public org.apache.myfaces.tobago.context.Markup getMarkup() {
147     Object object = getStateHelper().eval(PropertyKeys.markup);
148     if (object != null) {
149       return Markup.valueOf(object);
150     }
151     return null;
152   }
153 
154   public void setMarkup(org.apache.myfaces.tobago.context.Markup markup) {
155     getStateHelper().put(PropertyKeys.markup, markup);
156   }
157 
158   /**
159   Left margin between container component and the children.
160 
161   */
162   public org.apache.myfaces.tobago.layout.Measure getMarginLeft() {
163     Object object = getStateHelper().eval(PropertyKeys.marginLeft);
164     if (object != null) {
165        return Measure.valueOf(object);
166     }
167     return getMargin() != null
168    ? getMargin()
169    : getRendererType() != null ? ((MarginValues)getRenderer(getFacesContext())).getMarginLeft(getFacesContext(), this) : Measure.ZERO;
170   }
171 
172   public void setMarginLeft(org.apache.myfaces.tobago.layout.Measure marginLeft) {
173     getStateHelper().put(PropertyKeys.marginLeft, marginLeft);
174   }
175 
176   /**
177   Top margin between container component and the children.
178 
179   */
180   public org.apache.myfaces.tobago.layout.Measure getMarginTop() {
181     Object object = getStateHelper().eval(PropertyKeys.marginTop);
182     if (object != null) {
183        return Measure.valueOf(object);
184     }
185     return getMargin() != null
186    ? getMargin()
187    : getRendererType() != null ? ((MarginValues)getRenderer(getFacesContext())).getMarginTop(getFacesContext(), this) : Measure.ZERO;
188   }
189 
190   public void setMarginTop(org.apache.myfaces.tobago.layout.Measure marginTop) {
191     getStateHelper().put(PropertyKeys.marginTop, marginTop);
192   }
193 
194   /**
195   Right margin between container component and the children.
196 
197   */
198   public org.apache.myfaces.tobago.layout.Measure getMarginRight() {
199     Object object = getStateHelper().eval(PropertyKeys.marginRight);
200     if (object != null) {
201        return Measure.valueOf(object);
202     }
203     return getMargin() != null
204    ? getMargin()
205    : getRendererType() != null ? ((MarginValues)getRenderer(getFacesContext())).getMarginRight(getFacesContext(), this) : Measure.ZERO;
206   }
207 
208   public void setMarginRight(org.apache.myfaces.tobago.layout.Measure marginRight) {
209     getStateHelper().put(PropertyKeys.marginRight, marginRight);
210   }
211 
212   /**
213   This value defines the layout constraints for column layout.
214    It is a semicolon separated list of layout tokens '[&lt;n>]*', '&lt;n>px' or 'auto'.
215    Where &lt;n> is a non negative integer and the square brackets means optional.
216    Example: '2*;*;100px;auto'.
217   <br />Default: <code>1*</code>
218   */
219   public java.lang.String getColumns() {
220     java.lang.String columns = (java.lang.String) getStateHelper().eval(PropertyKeys.columns);
221     if (columns != null) {
222       return columns;
223     }
224     return "1*";
225   }
226 
227   public void setColumns(java.lang.String columns) {
228     getStateHelper().put(PropertyKeys.columns, columns);
229   }
230 
231   /**
232   This attribute advises the layout manager, to not use space that comes from non rendered components.
233 
234   */
235   public boolean isRigid() {
236     Boolean bool = (Boolean) getStateHelper().eval(PropertyKeys.rigid);
237     if (bool != null) {
238       return bool;
239     }
240     return false;
241   }
242 
243   public void setRigid(boolean rigid) {
244     getStateHelper().put(PropertyKeys.rigid, rigid);
245   }
246 
247   /**
248   Spacing between component and layout cell's.
249    Can be overwritten by columnSpacing and rowSpacing.
250 
251   @deprecated*/
252   @Deprecated
253   public org.apache.myfaces.tobago.layout.Measure getCellspacing() {
254     Object object = getStateHelper().eval(PropertyKeys.cellspacing);
255     if (object != null) {
256        return Measure.valueOf(object);
257     }
258     return null;
259   }
260 
261   @Deprecated
262   public void setCellspacing(org.apache.myfaces.tobago.layout.Measure cellspacing) {
263       Deprecation.LOG.error("The attribute 'cellspacing' of 'UIGridLayout' is deprecated. "
264           + "Please refer the documentation for further information.");
265     getStateHelper().put(PropertyKeys.cellspacing, cellspacing);
266   }
267 
268   /**
269   This value defines the layout constraints for column layout.
270    It is a semicolon separated list of layout tokens '[&lt;n>]*', '&lt;n>px' or 'auto'.
271    Where &lt;n> is a non negative integer and the square brackets means optional.
272    Example: '2*;*;100px;auto'.
273   <br />Default: <code>1*</code>
274   */
275   public java.lang.String getRows() {
276     java.lang.String rows = (java.lang.String) getStateHelper().eval(PropertyKeys.rows);
277     if (rows != null) {
278       return rows;
279     }
280     return "1*";
281   }
282 
283   public void setRows(java.lang.String rows) {
284     getStateHelper().put(PropertyKeys.rows, rows);
285   }
286 
287   /**
288   Bottom margin between container component and the children.
289 
290   */
291   public org.apache.myfaces.tobago.layout.Measure getMarginBottom() {
292     Object object = getStateHelper().eval(PropertyKeys.marginBottom);
293     if (object != null) {
294        return Measure.valueOf(object);
295     }
296     return getMargin() != null
297    ? getMargin()
298    : getRendererType() != null ? ((MarginValues)getRenderer(getFacesContext())).getMarginBottom(getFacesContext(), this) : Measure.ZERO;
299   }
300 
301   public void setMarginBottom(org.apache.myfaces.tobago.layout.Measure marginBottom) {
302     getStateHelper().put(PropertyKeys.marginBottom, marginBottom);
303   }
304 
305   /**
306   This attribute is a hint for the layout manager. Should not be used in most cases.
307 
308   */
309   public boolean isColumnOverflow() {
310     Boolean bool = (Boolean) getStateHelper().eval(PropertyKeys.columnOverflow);
311     if (bool != null) {
312       return bool;
313     }
314     return false;
315   }
316 
317   public void setColumnOverflow(boolean columnOverflow) {
318     getStateHelper().put(PropertyKeys.columnOverflow, columnOverflow);
319   }
320 
321   /**
322   Spacing between the rows in the actual layout.
323 
324   */
325   public org.apache.myfaces.tobago.layout.Measure getRowSpacing() {
326     Object object = getStateHelper().eval(PropertyKeys.rowSpacing);
327     if (object != null) {
328        return Measure.valueOf(object);
329     }
330     return getCellspacing() != null
331    ? getCellspacing()
332    : getRendererType() != null ? ((SpacingValues)getRenderer(getFacesContext())).getRowSpacing(getFacesContext(), this) : Measure.ZERO;
333   }
334 
335   public void setRowSpacing(org.apache.myfaces.tobago.layout.Measure rowSpacing) {
336     getStateHelper().put(PropertyKeys.rowSpacing, rowSpacing);
337   }
338 
339   public org.apache.myfaces.tobago.context.Markup getCurrentMarkup() {
340     if (currentMarkup != null) {
341       return currentMarkup;
342     }
343     return null;
344   }
345 
346   public void setCurrentMarkup(org.apache.myfaces.tobago.context.Markup currentMarkup) {
347     this.currentMarkup = currentMarkup;
348   }
349 
350   /**
351   Margin between container component and the children.
352 
353   */
354   public org.apache.myfaces.tobago.layout.Measure getMargin() {
355     Object object = getStateHelper().eval(PropertyKeys.margin);
356     if (object != null) {
357        return Measure.valueOf(object);
358     }
359     return null;
360   }
361 
362   public void setMargin(org.apache.myfaces.tobago.layout.Measure margin) {
363     getStateHelper().put(PropertyKeys.margin, margin);
364   }
365 
366   /**
367   Border size of this component.
368 
369   */
370   public java.lang.String getBorder() {
371     return (java.lang.String) getStateHelper().eval(PropertyKeys.border);
372   }
373 
374   public void setBorder(java.lang.String border) {
375     getStateHelper().put(PropertyKeys.border, border);
376   }
377 
378   /**
379   Spacing between the columns in the actual layout.
380 
381   */
382   public org.apache.myfaces.tobago.layout.Measure getColumnSpacing() {
383     Object object = getStateHelper().eval(PropertyKeys.columnSpacing);
384     if (object != null) {
385        return Measure.valueOf(object);
386     }
387     return getCellspacing() != null
388    ? getCellspacing()
389    : getRendererType() != null ? ((SpacingValues)getRenderer(getFacesContext())).getColumnSpacing(getFacesContext(), this) : Measure.ZERO;
390   }
391 
392   public void setColumnSpacing(org.apache.myfaces.tobago.layout.Measure columnSpacing) {
393     getStateHelper().put(PropertyKeys.columnSpacing, columnSpacing);
394   }
395 
396   public Object saveState(FacesContext context) {
397     currentMarkup = null;
398     return super.saveState(context);
399   }
400 
401 }