View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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   * PanelGroup which supports a partialTriggers Attribute similar to the one in Trinidad
37   * 
38   * @JSFRenderer
39   *   renderKitId = "HTML_BASIC" 
40   *   family = "javax.faces.Output"
41   *   type = "org.apache.myfaces.FloatingPaneBaseRenderer"
42   *
43   * @author werpu
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 }