View Javadoc

1   package org.rcfaces.core.internal.taglib;
2   
3   import javax.faces.application.Application;
4   import javax.faces.component.UIComponent;
5   import org.rcfaces.core.internal.component.Properties;
6   import javax.el.ValueExpression;
7   import javax.faces.component.UIViewRoot;
8   import org.apache.commons.logging.Log;
9   import org.rcfaces.core.component.RulerComponent;
10  import javax.servlet.jsp.tagext.Tag;
11  import org.apache.commons.logging.LogFactory;
12  import org.rcfaces.core.internal.tools.ListenersTools1_2;
13  import org.rcfaces.core.internal.tools.ListenersTools;
14  import javax.faces.context.FacesContext;
15  
16  public class RulerTag extends CameliaTag implements Tag {
17  
18  
19  	private static final Log LOG=LogFactory.getLog(RulerTag.class);
20  
21  	private ValueExpression x;
22  	private ValueExpression y;
23  	private ValueExpression bottom;
24  	private ValueExpression left;
25  	private ValueExpression right;
26  	private ValueExpression top;
27  	private ValueExpression marginBottom;
28  	private ValueExpression marginLeft;
29  	private ValueExpression marginRight;
30  	private ValueExpression marginTop;
31  	private ValueExpression width;
32  	private ValueExpression height;
33  	private ValueExpression visible;
34  	private ValueExpression hiddenMode;
35  	private ValueExpression lookId;
36  	private ValueExpression orientation;
37  	private ValueExpression backgroundColor;
38  	private ValueExpression foregroundColor;
39  	private ValueExpression alignment;
40  	private ValueExpression rendered;
41  	private ValueExpression margins;
42  	public String getComponentType() {
43  		return RulerComponent.COMPONENT_TYPE;
44  	}
45  
46  	public final void setX(ValueExpression x) {
47  		this.x = x;
48  	}
49  
50  	public final void setY(ValueExpression y) {
51  		this.y = y;
52  	}
53  
54  	public final void setBottom(ValueExpression bottom) {
55  		this.bottom = bottom;
56  	}
57  
58  	public final void setLeft(ValueExpression left) {
59  		this.left = left;
60  	}
61  
62  	public final void setRight(ValueExpression right) {
63  		this.right = right;
64  	}
65  
66  	public final void setTop(ValueExpression top) {
67  		this.top = top;
68  	}
69  
70  	public final void setMarginBottom(ValueExpression marginBottom) {
71  		this.marginBottom = marginBottom;
72  	}
73  
74  	public final void setMarginLeft(ValueExpression marginLeft) {
75  		this.marginLeft = marginLeft;
76  	}
77  
78  	public final void setMarginRight(ValueExpression marginRight) {
79  		this.marginRight = marginRight;
80  	}
81  
82  	public final void setMarginTop(ValueExpression marginTop) {
83  		this.marginTop = marginTop;
84  	}
85  
86  	public final void setWidth(ValueExpression width) {
87  		this.width = width;
88  	}
89  
90  	public final void setHeight(ValueExpression height) {
91  		this.height = height;
92  	}
93  
94  	public final void setVisible(ValueExpression visible) {
95  		this.visible = visible;
96  	}
97  
98  	public final void setHiddenMode(ValueExpression hiddenMode) {
99  		this.hiddenMode = hiddenMode;
100 	}
101 
102 	public final void setLookId(ValueExpression lookId) {
103 		this.lookId = lookId;
104 	}
105 
106 	public final void setOrientation(ValueExpression orientation) {
107 		this.orientation = orientation;
108 	}
109 
110 	public final void setBackgroundColor(ValueExpression backgroundColor) {
111 		this.backgroundColor = backgroundColor;
112 	}
113 
114 	public final void setForegroundColor(ValueExpression foregroundColor) {
115 		this.foregroundColor = foregroundColor;
116 	}
117 
118 	public final void setAlignment(ValueExpression alignment) {
119 		this.alignment = alignment;
120 	}
121 
122 	public final void setRendered(ValueExpression rendered) {
123 		this.rendered = rendered;
124 	}
125 
126 	public final void setMargins(ValueExpression margins) {
127 		this.margins = margins;
128 	}
129 
130 	protected void setProperties(UIComponent uiComponent) {
131 		if (LOG.isDebugEnabled()) {
132 			if (RulerComponent.COMPONENT_TYPE==getComponentType()) {
133 				LOG.debug("Component id='"+getId()+"' type='"+getComponentType()+"'.");
134 			}
135 			LOG.debug("  x='"+x+"'");
136 			LOG.debug("  y='"+y+"'");
137 			LOG.debug("  bottom='"+bottom+"'");
138 			LOG.debug("  left='"+left+"'");
139 			LOG.debug("  right='"+right+"'");
140 			LOG.debug("  top='"+top+"'");
141 			LOG.debug("  marginBottom='"+marginBottom+"'");
142 			LOG.debug("  marginLeft='"+marginLeft+"'");
143 			LOG.debug("  marginRight='"+marginRight+"'");
144 			LOG.debug("  marginTop='"+marginTop+"'");
145 			LOG.debug("  width='"+width+"'");
146 			LOG.debug("  height='"+height+"'");
147 			LOG.debug("  visible='"+visible+"'");
148 			LOG.debug("  hiddenMode='"+hiddenMode+"'");
149 			LOG.debug("  lookId='"+lookId+"'");
150 			LOG.debug("  orientation='"+orientation+"'");
151 			LOG.debug("  backgroundColor='"+backgroundColor+"'");
152 			LOG.debug("  foregroundColor='"+foregroundColor+"'");
153 			LOG.debug("  alignment='"+alignment+"'");
154 			LOG.debug("  rendered='"+rendered+"'");
155 			LOG.debug("  margins='"+margins+"'");
156 		}
157 		if ((uiComponent instanceof RulerComponent)==false) {
158 			if (uiComponent instanceof UIViewRoot) {
159 				throw new IllegalStateException("The first component of the page must be a UIViewRoot component !");
160 			}
161 			throw new IllegalStateException("Component specified by tag is not instanceof of 'RulerComponent'.");
162 		}
163 
164 		super.setProperties(uiComponent);
165 
166 		RulerComponent component = (RulerComponent) uiComponent;
167 		FacesContext facesContext = getFacesContext();
168 
169 		if (x != null) {
170 			if (x.isLiteralText()==false) {
171 				component.setValueExpression(Properties.X, x);
172 
173 			} else {
174 				component.setX(x.getExpressionString());
175 			}
176 		}
177 
178 		if (y != null) {
179 			if (y.isLiteralText()==false) {
180 				component.setValueExpression(Properties.Y, y);
181 
182 			} else {
183 				component.setY(y.getExpressionString());
184 			}
185 		}
186 
187 		if (bottom != null) {
188 			if (bottom.isLiteralText()==false) {
189 				component.setValueExpression(Properties.BOTTOM, bottom);
190 
191 			} else {
192 				component.setBottom(getInt(bottom.getExpressionString()));
193 			}
194 		}
195 
196 		if (left != null) {
197 			if (left.isLiteralText()==false) {
198 				component.setValueExpression(Properties.LEFT, left);
199 
200 			} else {
201 				component.setLeft(getInt(left.getExpressionString()));
202 			}
203 		}
204 
205 		if (right != null) {
206 			if (right.isLiteralText()==false) {
207 				component.setValueExpression(Properties.RIGHT, right);
208 
209 			} else {
210 				component.setRight(getInt(right.getExpressionString()));
211 			}
212 		}
213 
214 		if (top != null) {
215 			if (top.isLiteralText()==false) {
216 				component.setValueExpression(Properties.TOP, top);
217 
218 			} else {
219 				component.setTop(getInt(top.getExpressionString()));
220 			}
221 		}
222 
223 		if (marginBottom != null) {
224 			if (marginBottom.isLiteralText()==false) {
225 				component.setValueExpression(Properties.MARGIN_BOTTOM, marginBottom);
226 
227 			} else {
228 				component.setMarginBottom(marginBottom.getExpressionString());
229 			}
230 		}
231 
232 		if (marginLeft != null) {
233 			if (marginLeft.isLiteralText()==false) {
234 				component.setValueExpression(Properties.MARGIN_LEFT, marginLeft);
235 
236 			} else {
237 				component.setMarginLeft(marginLeft.getExpressionString());
238 			}
239 		}
240 
241 		if (marginRight != null) {
242 			if (marginRight.isLiteralText()==false) {
243 				component.setValueExpression(Properties.MARGIN_RIGHT, marginRight);
244 
245 			} else {
246 				component.setMarginRight(marginRight.getExpressionString());
247 			}
248 		}
249 
250 		if (marginTop != null) {
251 			if (marginTop.isLiteralText()==false) {
252 				component.setValueExpression(Properties.MARGIN_TOP, marginTop);
253 
254 			} else {
255 				component.setMarginTop(marginTop.getExpressionString());
256 			}
257 		}
258 
259 		if (width != null) {
260 			if (width.isLiteralText()==false) {
261 				component.setValueExpression(Properties.WIDTH, width);
262 
263 			} else {
264 				component.setWidth(width.getExpressionString());
265 			}
266 		}
267 
268 		if (height != null) {
269 			if (height.isLiteralText()==false) {
270 				component.setValueExpression(Properties.HEIGHT, height);
271 
272 			} else {
273 				component.setHeight(height.getExpressionString());
274 			}
275 		}
276 
277 		if (visible != null) {
278 			if (visible.isLiteralText()==false) {
279 				component.setValueExpression(Properties.VISIBLE, visible);
280 
281 			} else {
282 				component.setVisible(getBool(visible.getExpressionString()));
283 			}
284 		}
285 
286 		if (hiddenMode != null) {
287 			if (hiddenMode.isLiteralText()==false) {
288 				component.setValueExpression(Properties.HIDDEN_MODE, hiddenMode);
289 
290 			} else {
291 				component.setHiddenMode(hiddenMode.getExpressionString());
292 			}
293 		}
294 
295 		if (lookId != null) {
296 			if (lookId.isLiteralText()==false) {
297 				component.setValueExpression(Properties.LOOK_ID, lookId);
298 
299 			} else {
300 				component.setLookId(lookId.getExpressionString());
301 			}
302 		}
303 
304 		if (orientation != null) {
305 			if (orientation.isLiteralText()==false) {
306 				component.setValueExpression(Properties.ORIENTATION, orientation);
307 
308 			} else {
309 				component.setOrientation(orientation.getExpressionString());
310 			}
311 		}
312 
313 		if (backgroundColor != null) {
314 			if (backgroundColor.isLiteralText()==false) {
315 				component.setValueExpression(Properties.BACKGROUND_COLOR, backgroundColor);
316 
317 			} else {
318 				component.setBackgroundColor(backgroundColor.getExpressionString());
319 			}
320 		}
321 
322 		if (foregroundColor != null) {
323 			if (foregroundColor.isLiteralText()==false) {
324 				component.setValueExpression(Properties.FOREGROUND_COLOR, foregroundColor);
325 
326 			} else {
327 				component.setForegroundColor(foregroundColor.getExpressionString());
328 			}
329 		}
330 
331 		if (alignment != null) {
332 			if (alignment.isLiteralText()==false) {
333 				component.setValueExpression(Properties.ALIGNMENT, alignment);
334 
335 			} else {
336 				component.setAlignment(alignment.getExpressionString());
337 			}
338 		}
339 
340 		if (rendered != null) {
341 			if (rendered.isLiteralText()==false) {
342 				component.setValueExpression(Properties.RENDERED, rendered);
343 
344 			} else {
345 				component.setRendered(getBool(rendered.getExpressionString()));
346 			}
347 		}
348 
349 		if (margins != null) {
350 			if (margins.isLiteralText()==false) {
351 				throw new javax.faces.FacesException("Attribute 'margins' does not accept binding !");
352 			}
353 				component.setMargins(margins.getExpressionString());
354 		}
355 	}
356 
357 	public void release() {
358 		x = null;
359 		y = null;
360 		bottom = null;
361 		left = null;
362 		right = null;
363 		top = null;
364 		marginBottom = null;
365 		marginLeft = null;
366 		marginRight = null;
367 		marginTop = null;
368 		width = null;
369 		height = null;
370 		visible = null;
371 		hiddenMode = null;
372 		lookId = null;
373 		orientation = null;
374 		backgroundColor = null;
375 		foregroundColor = null;
376 		alignment = null;
377 		rendered = null;
378 		margins = null;
379 
380 		super.release();
381 	}
382 
383 }