1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.custom.collapsiblepanel;
20
21 import java.io.IOException;
22 import java.util.Iterator;
23
24 import javax.faces.component.UIComponent;
25 import javax.faces.component.UIInput;
26 import javax.faces.component.behavior.ClientBehaviorHolder;
27 import javax.faces.context.FacesContext;
28 import javax.faces.el.MethodBinding;
29
30 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
31 import org.apache.myfaces.component.EventAware;
32 import org.apache.myfaces.component.StyleAware;
33 import org.apache.myfaces.component.UniversalProperties;
34 import org.apache.myfaces.component.UserRoleAware;
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public abstract class AbstractHtmlCollapsiblePanel extends UIInput
55 implements StyleAware, UniversalProperties, EventAware,
56 UserRoleAware, ClientBehaviorHolder
57 {
58 public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlCollapsiblePanel";
59 public static final String COMPONENT_FAMILY = "javax.faces.Panel";
60 private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.CollapsiblePanel";
61
62 private static final String HEADER_FACET_NAME = "header";
63
64 private static final String CLOSED_CONTENT_FACET_NAME = "closedContent";
65
66 private boolean _currentlyCollapsed;
67
68 public void setCurrentlyCollapsed(boolean collapsed)
69 {
70 _currentlyCollapsed = collapsed;
71 }
72
73 public boolean isCurrentlyCollapsed()
74 {
75 return _currentlyCollapsed;
76 }
77
78 public void setHeader(UIComponent header)
79 {
80 getFacets().put(HEADER_FACET_NAME, header);
81 }
82
83
84
85
86 public UIComponent getHeader()
87 {
88 return (UIComponent) getFacets().get(HEADER_FACET_NAME);
89 }
90
91 public void setClosedContent(UIComponent closedContent)
92 {
93 getFacets().put(CLOSED_CONTENT_FACET_NAME, closedContent);
94 }
95
96
97
98
99 public UIComponent getClosedContent()
100 {
101 return (UIComponent) getFacets().get(CLOSED_CONTENT_FACET_NAME);
102 }
103
104
105
106 public void processDecodes(FacesContext context)
107 {
108 if (context == null) throw new NullPointerException("context");
109
110 initialiseVars(context);
111
112 if (!isRendered()) return;
113
114 try
115 {
116 decode(context);
117 }
118 catch (RuntimeException e)
119 {
120 context.renderResponse();
121 throw e;
122 }
123
124 UIComponent headerComponent = getFacet("header");
125
126 if(headerComponent != null)
127 {
128 for (Iterator it = headerComponent.getChildren().iterator(); it.hasNext(); )
129 {
130 UIComponent child = (UIComponent)it.next();
131
132 child.processDecodes(context);
133 }
134 }
135
136 if(isCurrentlyCollapsed())
137 {
138 UIComponent component = getFacet("closedContent");
139
140 if(component != null)
141 {
142 component.processDecodes(context);
143 }
144 }
145 else
146 {
147 for (Iterator it = getChildren().iterator(); it.hasNext(); )
148 {
149 UIComponent child = (UIComponent)it.next();
150 child.processDecodes(context);
151 }
152 }
153
154 removeVars(context);
155 }
156
157 public String getClientId(FacesContext context)
158 {
159 return super.getClientId(context);
160 }
161
162 public void processUpdates(FacesContext context)
163 {
164 initialiseVars(context);
165
166 super.processUpdates(context);
167
168 removeVars(context);
169 }
170
171 private void initialiseVars(FacesContext context)
172 {
173 if(getVar()!=null)
174 {
175 context.getExternalContext().getRequestMap().put(getVar(),
176 Boolean.valueOf(isCollapsed()));
177 }
178
179 if(getTitleVar()!=null)
180 {
181 context.getExternalContext().getRequestMap().put(getTitleVar(),
182 getTitle());
183 }
184 }
185
186 private void removeVars(FacesContext context)
187 {
188 if(getVar()!=null)
189 {
190 context.getExternalContext().getRequestMap().remove(getVar());
191 }
192
193 if(getTitleVar()!=null)
194 {
195 context.getExternalContext().getRequestMap().remove(getTitleVar());
196 }
197 }
198
199 public void processValidators(FacesContext context)
200 {
201 initialiseVars(context);
202
203 super.processValidators(context);
204
205 removeVars(context);
206 }
207
208 public void encodeChildren(FacesContext context) throws IOException
209 {
210 initialiseVars(context);
211
212 super.encodeChildren(context);
213
214 removeVars(context);
215 }
216
217 public void updateModel(FacesContext context)
218 {
219 super.updateModel(context);
220 }
221
222 public boolean isCollapsed()
223 {
224 return isCollapsed(getValue());
225 }
226
227 public static boolean isCollapsed(Object collapsedValue)
228 {
229 Object value = collapsedValue;
230
231 if(value instanceof Boolean)
232 {
233 return ((Boolean) value).booleanValue();
234 }
235 else if (value instanceof String)
236 {
237 return Boolean.valueOf((String) value).booleanValue();
238 }
239
240 return true;
241 }
242
243
244
245
246
247
248
249
250 public abstract String getVar();
251
252
253
254
255
256
257
258
259 public abstract String getTitleVar();
260
261
262
263
264 public MethodBinding getValidator(){
265 return super.getValidator();
266 }
267
268
269
270
271 public MethodBinding getValueChangeListener()
272 {
273 return super.getValueChangeListener();
274 }
275
276
277
278
279 public boolean isImmediate()
280 {
281 return super.isImmediate();
282 }
283
284
285
286
287 public boolean isRequired()
288 {
289 return super.isRequired();
290 }
291
292
293
294
295
296
297
298
299 @JSFProperty
300 public abstract String getIndicatorStyleClass();
301
302
303
304
305
306
307
308
309 @JSFProperty
310 public abstract String getIndicatorStyle();
311
312
313
314
315
316
317
318
319 @JSFProperty
320 public abstract String getTitleStyleClass();
321
322
323
324
325
326
327
328
329 @JSFProperty
330 public abstract String getTitleStyle();
331 }