View Javadoc

1   // Copyright May 16, 2006 The Apache Software Foundation
2   //
3   // Licensed under the Apache License, Version 2.0 (the "License");
4   // you may not use this file except in compliance with the License.
5   // You may obtain a copy of the License at
6   //
7   //     http://www.apache.org/licenses/LICENSE-2.0
8   //
9   // Unless required by applicable law or agreed to in writing, software
10  // distributed under the License is distributed on an "AS IS" BASIS,
11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  // See the License for the specific language governing permissions and
13  // limitations under the License.
14  package net.sf.tacos.components.dojo.old;
15  
16  import java.util.HashMap;
17  import java.util.Map;
18  
19  import org.apache.hivemind.ApplicationRuntimeException;
20  import org.apache.tapestry.AbstractComponent;
21  import org.apache.tapestry.IMarkupWriter;
22  import org.apache.tapestry.IRequestCycle;
23  import org.apache.tapestry.IScript;
24  import org.apache.tapestry.PageRenderSupport;
25  import org.apache.tapestry.TapestryUtils;
26  import org.apache.tapestry.dojo.DojoUtils;
27  import org.apache.tapestry.dojo.IWidget;
28  import org.apache.tapestry.json.JSONObject;
29  
30  /**
31   * Implementation of dojo's FloatingPane.
32   *
33   * @author andyhot
34   * @since 4.1.0
35   * @deprecated Use the {@link DojoWidget} component.
36   */
37  public abstract class FloatingPane extends AbstractComponent implements IWidget, IDojoFloatingPane 
38  {
39      /** Has Tool bar. */
40      public abstract boolean getHasToolbar();
41  
42      /** Allow resize. */
43      public abstract boolean isResizable();
44  
45      /** Should persist position (with cookies). */
46      public abstract boolean getPersistPosition();
47  
48      /** id. */
49      public abstract String getIdParameter();
50  
51      /** Is this pane a taskBar? */
52      public abstract boolean getIsTaskBar();
53  
54      /** More js options - JSON style. */
55      public abstract String getOptions();
56  
57      /** Injected script. */
58      public abstract IScript getScript();
59      
60      /** Get the id of the connected taskBar. */
61      public String getTaskBarId()
62      {
63          Object obj = getTaskBar();
64          if (obj == null)
65              return null;
66          else if (obj instanceof String)
67              return (String)obj;
68          else if (obj instanceof FloatingPane)
69              return ((FloatingPane)obj).getIdParameter();
70          else
71              throw new ApplicationRuntimeException("Parameter taskBar should either be a String or a FloatingPane");
72      }
73      
74      /**
75       * {@inheritDoc}
76       */
77      public void renderWidget(IMarkupWriter writer, IRequestCycle cycle)
78      {
79          renderComponent(writer, cycle);
80      }    
81  
82      /**
83       * @see org.apache.tapestry.AbstractComponent#renderComponent(org.apache.tapestry.IMarkupWriter,
84       *      org.apache.tapestry.IRequestCycle)
85       */
86      protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
87      {
88          writer.begin("div");
89          writer.attribute("id", getIdParameter());
90          
91          renderInformalParameters(writer, cycle);
92          renderBody(writer, cycle);
93          
94          writer.end();
95          
96          JSONObject obj = DojoUtils.parseJSONParameter(this, "options");
97  
98          obj.put("title", getTitle());
99          if (getIcon() != null)
100             obj.put("iconSrc", getIcon().buildURL());
101         if (getHref() != null)
102             obj.put("href", getHref());
103         obj.put("widgetId", getId());
104         obj.put("toggle", "fade");
105         obj.put("constrainToContainer", getConstrainToContainer());
106         obj.put("displayMaximizeAction", getDisplayMaximizeAction());
107         obj.put("displayMinimizeAction", getDisplayMinimizeAction());
108         obj.put("displayCloseAction", getDisplayCloseAction());
109         obj.put("hasShadow", getHasShadow());
110         obj.put("resizable", isResizable());
111         obj.put("taskBarId", getTaskBarId());
112         //obj.put("persistenceWidgetPosition", getPersistPosition());        
113 
114         //Setup our script includes
115         Map scriptParms = new HashMap();
116         scriptParms.put("id", getIdParameter());
117         scriptParms.put("props", obj.toString());
118         PageRenderSupport pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, this);
119         
120         getScript().execute(this, cycle, pageRenderSupport, scriptParms);
121     }
122 }