1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.custom.dojolayouts;
21
22 import java.io.IOException;
23
24 import javax.faces.component.UIComponent;
25 import javax.faces.context.FacesContext;
26 import javax.faces.context.ResponseWriter;
27
28 import org.apache.myfaces.custom.dojo.DojoConfig;
29 import org.apache.myfaces.custom.dojo.DojoUtils;
30 import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
31 import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
32 import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRenderer;
33 import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
34
35
36
37
38
39
40
41
42
43
44
45
46 public class FloatingPaneBaseRenderer extends HtmlRenderer {
47
48 public void decode(FacesContext context, UIComponent component) {
49 super.decode(context, component);
50
51 }
52
53 protected void encodeJavascriptBegin(FacesContext context, UIComponent component) throws IOException {
54 String javascriptLocation = (String) component.getAttributes().get(JSFAttr.JAVASCRIPT_LOCATION);
55 try {
56 if (javascriptLocation != null) {
57 DojoUtils.addMainInclude(context, component, javascriptLocation, new DojoConfig());
58 } else {
59 DojoUtils.addMainInclude(context, component, null, new DojoConfig());
60 }
61 } catch (IOException e) {
62 e.printStackTrace();
63 }
64
65 String[] requires = { "dojo.widget.*", "dojo.widget.TaskBar", "dojo.widget.LayoutContainer", "dojo.widget.FloatingPane" };
66 DojoUtils.addRequire(context, component, requires);
67 if (isResizable(component))
68 DojoUtils.addRequire(context, component, "dojo.widget.ResizeHandle");
69 }
70
71 private boolean isResizable(UIComponent component) {
72 return ((FloatingPaneBase) component).getResizable() != null && ((FloatingPaneBase) component).getResizable().booleanValue();
73 }
74
75 public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
76
77 if ((context == null) || (component == null)) {
78 throw new NullPointerException();
79 }
80
81 Boolean rendered = (Boolean) component.getAttributes().get("rendered");
82
83 if ((rendered != null) && (!rendered.booleanValue()))
84 return;
85 encodeJavascriptBegin(context, component);
86
87 super.encodeBegin(context, component);
88
89 ResponseWriter writer = context.getResponseWriter();
90 writer.startElement(HTML.DIV_ELEM, component);
91 HtmlRendererUtils.writeIdIfNecessary(writer, component, context);
92
93 FloatingPaneBase pane = (FloatingPaneBase) component;
94
95 String styleClass = pane.getStyleClass();
96 String style = pane.getStyle();
97 if (null != styleClass) {
98 writer.writeAttribute(HTML.CLASS_ATTR, styleClass, null);
99 }
100 if (null != style) {
101 writer.writeAttribute(HTML.STYLE_ATTR, style, null);
102 }
103 }
104
105 public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
106 super.encodeEnd(context, component);
107 ResponseWriter writer = context.getResponseWriter();
108 writer.endElement(HTML.DIV_ELEM);
109 encodeJavascriptEnd(context, component);
110 }
111
112
113 protected void encodeJavascriptEnd(FacesContext context, UIComponent component) throws IOException {
114 FloatingPaneBase pane = (FloatingPaneBase) component;
115
116 String[] attributeNames = { "title", "iconSrc", "hasShadow", "constrainToContainer", "taskBarId", "resizable", "titleBarDisplay", "windowState",
117 "displayCloseAction", "displayMinimizeAction", "widgetVar", "widgetId" };
118
119 if (pane.getModal() != null && pane.getModal().booleanValue())
120 DojoUtils.renderWidgetInitializationCode(context, component, "ModalFloatingPane", attributeNames);
121 else
122 DojoUtils.renderWidgetInitializationCode(context, component, "FloatingPane", attributeNames);
123 }
124
125 public boolean getRendersChildren() {
126 return true;
127 }
128
129 }