1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.myfaces.trinidad.component.core.layout;
23
24 import java.util.Arrays;
25 import java.util.Collection;
26 import java.util.Collections;
27 import java.util.List;
28 import java.util.Map;
29 import javax.faces.component.UIComponent;
30 import javax.faces.component.behavior.ClientBehavior;
31 import javax.faces.component.behavior.ClientBehaviorHolder;
32 import javax.faces.component.visit.VisitCallback;
33 import javax.faces.component.visit.VisitContext;
34 import javax.faces.component.visit.VisitContextWrapper;
35 import javax.faces.component.visit.VisitHint;
36 import javax.faces.component.visit.VisitResult;
37 import javax.faces.event.AbortProcessingException;
38 import javax.faces.event.FacesEvent;
39 import org.apache.myfaces.trinidad.bean.FacesBean;
40 import org.apache.myfaces.trinidad.bean.PropertyKey;
41 import org.apache.myfaces.trinidad.component.FlattenedComponent;
42 import org.apache.myfaces.trinidad.component.UIXPanel;
43 import org.apache.myfaces.trinidad.component.UIXShowDetail;
44 import org.apache.myfaces.trinidad.event.DisclosureEvent;
45 import org.apache.myfaces.trinidad.util.ComponentUtils;
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 public class CorePanelAccordion extends UIXPanel
71 implements ClientBehaviorHolder
72 {
73 static public final FacesBean.Type TYPE = new FacesBean.Type(
74 UIXPanel.TYPE);
75 static public final PropertyKey INLINE_STYLE_KEY =
76 TYPE.registerKey("inlineStyle", String.class);
77 static public final PropertyKey STYLE_CLASS_KEY =
78 TYPE.registerKey("styleClass", String.class);
79 static public final PropertyKey SHORT_DESC_KEY =
80 TYPE.registerKey("shortDesc", String.class);
81 static public final PropertyKey PARTIAL_TRIGGERS_KEY =
82 TYPE.registerKey("partialTriggers", String[].class, null, 0, PropertyKey.Mutable.RARELY);
83 static public final PropertyKey ONCLICK_KEY =
84 TYPE.registerKey("onclick", String.class);
85 static public final PropertyKey ONDBLCLICK_KEY =
86 TYPE.registerKey("ondblclick", String.class);
87 static public final PropertyKey ONMOUSEDOWN_KEY =
88 TYPE.registerKey("onmousedown", String.class);
89 static public final PropertyKey ONMOUSEUP_KEY =
90 TYPE.registerKey("onmouseup", String.class);
91 static public final PropertyKey ONMOUSEOVER_KEY =
92 TYPE.registerKey("onmouseover", String.class);
93 static public final PropertyKey ONMOUSEMOVE_KEY =
94 TYPE.registerKey("onmousemove", String.class);
95 static public final PropertyKey ONMOUSEOUT_KEY =
96 TYPE.registerKey("onmouseout", String.class);
97 static public final PropertyKey ONKEYPRESS_KEY =
98 TYPE.registerKey("onkeypress", String.class);
99 static public final PropertyKey ONKEYDOWN_KEY =
100 TYPE.registerKey("onkeydown", String.class);
101 static public final PropertyKey ONKEYUP_KEY =
102 TYPE.registerKey("onkeyup", String.class);
103 static public final PropertyKey DISCLOSE_NONE_KEY =
104 TYPE.registerKey("discloseNone", Boolean.class, Boolean.FALSE);
105 static public final PropertyKey DISCLOSE_MANY_KEY =
106 TYPE.registerKey("discloseMany", Boolean.class, Boolean.FALSE);
107
108 static public final String COMPONENT_FAMILY =
109 "org.apache.myfaces.trinidad.Panel";
110 static public final String COMPONENT_TYPE =
111 "org.apache.myfaces.trinidad.CorePanelAccordion";
112
113 private final static Collection<String> _EVENT_NAMES = Collections.unmodifiableCollection(
114 Arrays.asList(
115 "click", "dblclick", "mousedown", "mouseup", "mouseover", "mousemove",
116 "mouseout", "keypress", "keydown", "keyup"
117 ));
118
119
120
121
122 public CorePanelAccordion()
123 {
124 super("org.apache.myfaces.trinidad.Accordion");
125 }
126
127
128
129
130
131
132 @Override
133 public void queueEvent(FacesEvent event)
134 throws AbortProcessingException
135 {
136
137
138
139 if ((event instanceof DisclosureEvent) &&
140 !isDiscloseMany() &&
141 (this == event.getComponent().getParent()) &&
142 ((DisclosureEvent) event).isExpanded())
143
144 {
145 for (UIComponent comp : ((List<UIComponent>) getChildren()))
146 {
147
148 if (comp == event.getComponent())
149 continue;
150
151 if (comp instanceof UIXShowDetail)
152 {
153 UIXShowDetail showDetail = (UIXShowDetail) comp;
154
155 if (showDetail.isDisclosed())
156 (new DisclosureEvent(showDetail, false)).queue();
157 }
158 }
159 }
160 super.queueEvent(event);
161 }
162
163 @Override
164 public boolean visitTree(
165 VisitContext visitContext,
166 VisitCallback callback)
167 {
168 if (visitContext.getHints().contains(VisitHint.SKIP_UNRENDERED) &&
169 !isDiscloseMany())
170 {
171
172
173 visitContext = new PartialVisitContext(visitContext);
174 }
175 return super.visitTree(visitContext, callback);
176 }
177
178 protected boolean isChildSelected(
179 UIXShowDetail component)
180 {
181 return component.isDisclosed();
182 }
183
184 private class PartialVisitContext
185 extends VisitContextWrapper
186 {
187 PartialVisitContext(
188 VisitContext wrapped)
189 {
190 _wrapped = wrapped;
191 }
192
193 public VisitContext getWrapped()
194 {
195 return _wrapped;
196 }
197
198 @Override
199 public VisitResult invokeVisitCallback(
200 UIComponent component,
201 VisitCallback visitCallback)
202 {
203 if (component instanceof UIXShowDetail)
204 {
205 UIXShowDetail showDetail = (UIXShowDetail)component;
206 if (_isShowDetailForCurrentComponent(showDetail))
207 {
208 if (_foundItemToRender || !isChildSelected(showDetail))
209 {
210
211 return VisitResult.REJECT;
212 }
213 else
214 {
215 _foundItemToRender = true;
216 }
217 }
218 }
219
220 return super.invokeVisitCallback(component, visitCallback);
221 }
222
223 private boolean _isShowDetailForCurrentComponent(
224 UIXShowDetail showDetail)
225 {
226 for (UIComponent parent = showDetail.getParent(); parent != null;
227 parent = parent.getParent())
228 {
229 if (parent == CorePanelAccordion.this)
230 {
231 return true;
232 }
233
234 if (parent instanceof FlattenedComponent &&
235 ((FlattenedComponent)parent).isFlatteningChildren(getFacesContext()))
236 {
237 continue;
238 }
239
240
241 return false;
242 }
243
244 return false;
245 }
246
247 private boolean _foundItemToRender;
248 private VisitContext _wrapped;
249 }
250
251
252
253
254
255
256 final public String getInlineStyle()
257 {
258 return ComponentUtils.resolveString(getProperty(INLINE_STYLE_KEY));
259 }
260
261
262
263
264
265
266 final public void setInlineStyle(String inlineStyle)
267 {
268 setProperty(INLINE_STYLE_KEY, (inlineStyle));
269 }
270
271
272
273
274
275
276 final public String getStyleClass()
277 {
278 return ComponentUtils.resolveString(getProperty(STYLE_CLASS_KEY));
279 }
280
281
282
283
284
285
286 final public void setStyleClass(String styleClass)
287 {
288 setProperty(STYLE_CLASS_KEY, (styleClass));
289 }
290
291
292
293
294
295
296 final public String getShortDesc()
297 {
298 return ComponentUtils.resolveString(getProperty(SHORT_DESC_KEY));
299 }
300
301
302
303
304
305
306 final public void setShortDesc(String shortDesc)
307 {
308 setProperty(SHORT_DESC_KEY, (shortDesc));
309 }
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331 final public String[] getPartialTriggers()
332 {
333 return (String[])getProperty(PARTIAL_TRIGGERS_KEY);
334 }
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356 final public void setPartialTriggers(String[] partialTriggers)
357 {
358 setProperty(PARTIAL_TRIGGERS_KEY, (partialTriggers));
359 }
360
361
362
363
364
365
366 final public String getOnclick()
367 {
368 return ComponentUtils.resolveString(getProperty(ONCLICK_KEY));
369 }
370
371
372
373
374
375
376 final public void setOnclick(String onclick)
377 {
378 setProperty(ONCLICK_KEY, (onclick));
379 }
380
381
382
383
384
385
386 final public String getOndblclick()
387 {
388 return ComponentUtils.resolveString(getProperty(ONDBLCLICK_KEY));
389 }
390
391
392
393
394
395
396 final public void setOndblclick(String ondblclick)
397 {
398 setProperty(ONDBLCLICK_KEY, (ondblclick));
399 }
400
401
402
403
404
405
406 final public String getOnmousedown()
407 {
408 return ComponentUtils.resolveString(getProperty(ONMOUSEDOWN_KEY));
409 }
410
411
412
413
414
415
416 final public void setOnmousedown(String onmousedown)
417 {
418 setProperty(ONMOUSEDOWN_KEY, (onmousedown));
419 }
420
421
422
423
424
425
426 final public String getOnmouseup()
427 {
428 return ComponentUtils.resolveString(getProperty(ONMOUSEUP_KEY));
429 }
430
431
432
433
434
435
436 final public void setOnmouseup(String onmouseup)
437 {
438 setProperty(ONMOUSEUP_KEY, (onmouseup));
439 }
440
441
442
443
444
445
446 final public String getOnmouseover()
447 {
448 return ComponentUtils.resolveString(getProperty(ONMOUSEOVER_KEY));
449 }
450
451
452
453
454
455
456 final public void setOnmouseover(String onmouseover)
457 {
458 setProperty(ONMOUSEOVER_KEY, (onmouseover));
459 }
460
461
462
463
464
465
466 final public String getOnmousemove()
467 {
468 return ComponentUtils.resolveString(getProperty(ONMOUSEMOVE_KEY));
469 }
470
471
472
473
474
475
476 final public void setOnmousemove(String onmousemove)
477 {
478 setProperty(ONMOUSEMOVE_KEY, (onmousemove));
479 }
480
481
482
483
484
485
486 final public String getOnmouseout()
487 {
488 return ComponentUtils.resolveString(getProperty(ONMOUSEOUT_KEY));
489 }
490
491
492
493
494
495
496 final public void setOnmouseout(String onmouseout)
497 {
498 setProperty(ONMOUSEOUT_KEY, (onmouseout));
499 }
500
501
502
503
504
505
506 final public String getOnkeypress()
507 {
508 return ComponentUtils.resolveString(getProperty(ONKEYPRESS_KEY));
509 }
510
511
512
513
514
515
516 final public void setOnkeypress(String onkeypress)
517 {
518 setProperty(ONKEYPRESS_KEY, (onkeypress));
519 }
520
521
522
523
524
525
526 final public String getOnkeydown()
527 {
528 return ComponentUtils.resolveString(getProperty(ONKEYDOWN_KEY));
529 }
530
531
532
533
534
535
536 final public void setOnkeydown(String onkeydown)
537 {
538 setProperty(ONKEYDOWN_KEY, (onkeydown));
539 }
540
541
542
543
544
545
546 final public String getOnkeyup()
547 {
548 return ComponentUtils.resolveString(getProperty(ONKEYUP_KEY));
549 }
550
551
552
553
554
555
556 final public void setOnkeyup(String onkeyup)
557 {
558 setProperty(ONKEYUP_KEY, (onkeyup));
559 }
560
561
562
563
564
565
566
567
568
569 final public boolean isDiscloseNone()
570 {
571 return ComponentUtils.resolveBoolean(getProperty(DISCLOSE_NONE_KEY), false);
572 }
573
574
575
576
577
578
579
580
581
582 final public void setDiscloseNone(boolean discloseNone)
583 {
584 setProperty(DISCLOSE_NONE_KEY, discloseNone ? Boolean.TRUE : Boolean.FALSE);
585 }
586
587
588
589
590
591
592
593
594
595 final public boolean isDiscloseMany()
596 {
597 return ComponentUtils.resolveBoolean(getProperty(DISCLOSE_MANY_KEY), false);
598 }
599
600
601
602
603
604
605
606
607
608 final public void setDiscloseMany(boolean discloseMany)
609 {
610 setProperty(DISCLOSE_MANY_KEY, discloseMany ? Boolean.TRUE : Boolean.FALSE);
611 }
612
613 @Override
614 public String getDefaultEventName()
615 {
616 return "click";
617 }
618
619 @Override
620 public Collection<String> getEventNames()
621 {
622 return _EVENT_NAMES;
623 }
624
625 @Override
626 public Map<String, List<ClientBehavior>> getClientBehaviors()
627 {
628 return super.getClientBehaviors();
629 }
630
631 @Override
632 public void addClientBehavior(
633 String eventName,
634 ClientBehavior behavior)
635 {
636 super.addClientBehavior(eventName, behavior);
637 }
638
639 @Override
640 public String getFamily()
641 {
642 return COMPONENT_FAMILY;
643 }
644
645 @Override
646 protected FacesBean.Type getBeanType()
647 {
648 return TYPE;
649 }
650
651
652
653
654 protected CorePanelAccordion(
655 String rendererType
656 )
657 {
658 super(rendererType);
659 }
660
661 static
662 {
663 TYPE.lockAndRegister("org.apache.myfaces.trinidad.Panel","org.apache.myfaces.trinidad.Accordion");
664 }
665 }