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 javax.servlet.jsp.tagext.Tag;
10  import org.apache.commons.logging.LogFactory;
11  import org.rcfaces.core.component.ToolBarComponent;
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 ToolBarTag extends AbstractBasicTag implements Tag {
17  
18  
19  	private static final Log LOG=LogFactory.getLog(ToolBarTag.class);
20  
21  	private ValueExpression initListeners;
22  	private ValueExpression verticalAlignment;
23  	private ValueExpression borderType;
24  	private ValueExpression separatorImageURL;
25  	private ValueExpression separatorImageWidth;
26  	private ValueExpression separatorImageHeight;
27  	private ValueExpression separatorAlternateText;
28  	private ValueExpression controlImageURL;
29  	private ValueExpression controlImageWidth;
30  	private ValueExpression controlImageHeight;
31  	private ValueExpression controlAlternateText;
32  	private ValueExpression itemPadding;
33  	private ValueExpression locked;
34  	public String getComponentType() {
35  		return ToolBarComponent.COMPONENT_TYPE;
36  	}
37  
38  	public final void setInitListener(ValueExpression initListeners) {
39  		this.initListeners = initListeners;
40  	}
41  
42  	public final void setVerticalAlignment(ValueExpression verticalAlignment) {
43  		this.verticalAlignment = verticalAlignment;
44  	}
45  
46  	public final void setBorderType(ValueExpression borderType) {
47  		this.borderType = borderType;
48  	}
49  
50  	public final void setSeparatorImageURL(ValueExpression separatorImageURL) {
51  		this.separatorImageURL = separatorImageURL;
52  	}
53  
54  	public final void setSeparatorImageWidth(ValueExpression separatorImageWidth) {
55  		this.separatorImageWidth = separatorImageWidth;
56  	}
57  
58  	public final void setSeparatorImageHeight(ValueExpression separatorImageHeight) {
59  		this.separatorImageHeight = separatorImageHeight;
60  	}
61  
62  	public final void setSeparatorAlternateText(ValueExpression separatorAlternateText) {
63  		this.separatorAlternateText = separatorAlternateText;
64  	}
65  
66  	public final void setControlImageURL(ValueExpression controlImageURL) {
67  		this.controlImageURL = controlImageURL;
68  	}
69  
70  	public final void setControlImageWidth(ValueExpression controlImageWidth) {
71  		this.controlImageWidth = controlImageWidth;
72  	}
73  
74  	public final void setControlImageHeight(ValueExpression controlImageHeight) {
75  		this.controlImageHeight = controlImageHeight;
76  	}
77  
78  	public final void setControlAlternateText(ValueExpression controlAlternateText) {
79  		this.controlAlternateText = controlAlternateText;
80  	}
81  
82  	public final void setItemPadding(ValueExpression itemPadding) {
83  		this.itemPadding = itemPadding;
84  	}
85  
86  	public final void setLocked(ValueExpression locked) {
87  		this.locked = locked;
88  	}
89  
90  	protected void setProperties(UIComponent uiComponent) {
91  		if (LOG.isDebugEnabled()) {
92  			if (ToolBarComponent.COMPONENT_TYPE==getComponentType()) {
93  				LOG.debug("Component id='"+getId()+"' type='"+getComponentType()+"'.");
94  			}
95  			LOG.debug("  verticalAlignment='"+verticalAlignment+"'");
96  			LOG.debug("  borderType='"+borderType+"'");
97  			LOG.debug("  separatorImageURL='"+separatorImageURL+"'");
98  			LOG.debug("  separatorImageWidth='"+separatorImageWidth+"'");
99  			LOG.debug("  separatorImageHeight='"+separatorImageHeight+"'");
100 			LOG.debug("  separatorAlternateText='"+separatorAlternateText+"'");
101 			LOG.debug("  controlImageURL='"+controlImageURL+"'");
102 			LOG.debug("  controlImageWidth='"+controlImageWidth+"'");
103 			LOG.debug("  controlImageHeight='"+controlImageHeight+"'");
104 			LOG.debug("  controlAlternateText='"+controlAlternateText+"'");
105 			LOG.debug("  itemPadding='"+itemPadding+"'");
106 			LOG.debug("  locked='"+locked+"'");
107 		}
108 		if ((uiComponent instanceof ToolBarComponent)==false) {
109 			if (uiComponent instanceof UIViewRoot) {
110 				throw new IllegalStateException("The first component of the page must be a UIViewRoot component !");
111 			}
112 			throw new IllegalStateException("Component specified by tag is not instanceof of 'ToolBarComponent'.");
113 		}
114 
115 		super.setProperties(uiComponent);
116 
117 		ToolBarComponent component = (ToolBarComponent) uiComponent;
118 		FacesContext facesContext = getFacesContext();
119 
120 		if (initListeners != null) {
121 			ListenersTools1_2.parseListener(facesContext, component, ListenersTools.INIT_LISTENER_TYPE, initListeners);
122 		}
123 
124 		if (verticalAlignment != null) {
125 			if (verticalAlignment.isLiteralText()==false) {
126 				component.setValueExpression(Properties.VERTICAL_ALIGNMENT, verticalAlignment);
127 
128 			} else {
129 				component.setVerticalAlignment(verticalAlignment.getExpressionString());
130 			}
131 		}
132 
133 		if (borderType != null) {
134 			if (borderType.isLiteralText()==false) {
135 				component.setValueExpression(Properties.BORDER_TYPE, borderType);
136 
137 			} else {
138 				component.setBorderType(borderType.getExpressionString());
139 			}
140 		}
141 
142 		if (separatorImageURL != null) {
143 			if (separatorImageURL.isLiteralText()==false) {
144 				component.setValueExpression(Properties.SEPARATOR_IMAGE_URL, separatorImageURL);
145 
146 			} else {
147 				component.setSeparatorImageURL(separatorImageURL.getExpressionString());
148 			}
149 		}
150 
151 		if (separatorImageWidth != null) {
152 			if (separatorImageWidth.isLiteralText()==false) {
153 				component.setValueExpression(Properties.SEPARATOR_IMAGE_WIDTH, separatorImageWidth);
154 
155 			} else {
156 				component.setSeparatorImageWidth(getInt(separatorImageWidth.getExpressionString()));
157 			}
158 		}
159 
160 		if (separatorImageHeight != null) {
161 			if (separatorImageHeight.isLiteralText()==false) {
162 				component.setValueExpression(Properties.SEPARATOR_IMAGE_HEIGHT, separatorImageHeight);
163 
164 			} else {
165 				component.setSeparatorImageHeight(getInt(separatorImageHeight.getExpressionString()));
166 			}
167 		}
168 
169 		if (separatorAlternateText != null) {
170 			if (separatorAlternateText.isLiteralText()==false) {
171 				component.setValueExpression(Properties.SEPARATOR_ALTERNATE_TEXT, separatorAlternateText);
172 
173 			} else {
174 				component.setSeparatorAlternateText(separatorAlternateText.getExpressionString());
175 			}
176 		}
177 
178 		if (controlImageURL != null) {
179 			if (controlImageURL.isLiteralText()==false) {
180 				component.setValueExpression(Properties.CONTROL_IMAGE_URL, controlImageURL);
181 
182 			} else {
183 				component.setControlImageURL(controlImageURL.getExpressionString());
184 			}
185 		}
186 
187 		if (controlImageWidth != null) {
188 			if (controlImageWidth.isLiteralText()==false) {
189 				component.setValueExpression(Properties.CONTROL_IMAGE_WIDTH, controlImageWidth);
190 
191 			} else {
192 				component.setControlImageWidth(getInt(controlImageWidth.getExpressionString()));
193 			}
194 		}
195 
196 		if (controlImageHeight != null) {
197 			if (controlImageHeight.isLiteralText()==false) {
198 				component.setValueExpression(Properties.CONTROL_IMAGE_HEIGHT, controlImageHeight);
199 
200 			} else {
201 				component.setControlImageHeight(getInt(controlImageHeight.getExpressionString()));
202 			}
203 		}
204 
205 		if (controlAlternateText != null) {
206 			if (controlAlternateText.isLiteralText()==false) {
207 				component.setValueExpression(Properties.CONTROL_ALTERNATE_TEXT, controlAlternateText);
208 
209 			} else {
210 				component.setControlAlternateText(controlAlternateText.getExpressionString());
211 			}
212 		}
213 
214 		if (itemPadding != null) {
215 			if (itemPadding.isLiteralText()==false) {
216 				component.setValueExpression(Properties.ITEM_PADDING, itemPadding);
217 
218 			} else {
219 				component.setItemPadding(getInt(itemPadding.getExpressionString()));
220 			}
221 		}
222 
223 		if (locked != null) {
224 			if (locked.isLiteralText()==false) {
225 				component.setValueExpression(Properties.LOCKED, locked);
226 
227 			} else {
228 				component.setLocked(getBool(locked.getExpressionString()));
229 			}
230 		}
231 	}
232 
233 	public void release() {
234 		initListeners = null;
235 		verticalAlignment = null;
236 		borderType = null;
237 		separatorImageURL = null;
238 		separatorImageWidth = null;
239 		separatorImageHeight = null;
240 		separatorAlternateText = null;
241 		controlImageURL = null;
242 		controlImageWidth = null;
243 		controlImageHeight = null;
244 		controlAlternateText = null;
245 		itemPadding = null;
246 		locked = null;
247 
248 		super.release();
249 	}
250 
251 }