001 // Copyright May 16, 2006 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014 package org.apache.tapestry.dojo.html;
015
016 import java.util.HashMap;
017 import java.util.Map;
018
019 import org.apache.hivemind.ApplicationRuntimeException;
020 import org.apache.tapestry.AbstractComponent;
021 import org.apache.tapestry.IMarkupWriter;
022 import org.apache.tapestry.IRequestCycle;
023 import org.apache.tapestry.IScript;
024 import org.apache.tapestry.PageRenderSupport;
025 import org.apache.tapestry.TapestryUtils;
026 import org.apache.tapestry.dojo.DojoUtils;
027 import org.apache.tapestry.dojo.IWidget;
028 import org.apache.tapestry.json.JSONObject;
029
030 /**
031 * Implementation of dojo's FloatingPane.
032 *
033 * @author andyhot
034 * @since 4.1
035 */
036 public abstract class FloatingPane extends AbstractComponent implements IWidget, IDojoFloatingPane
037 {
038 /** Has Tool bar. */
039 public abstract boolean getHasToolbar();
040
041 /** Allow resize. */
042 public abstract boolean isResizable();
043
044 /** Should persist position (with cookies). */
045 public abstract boolean getPersistPosition();
046
047 /** id. */
048 public abstract String getIdParameter();
049
050 /** Is this pane a taskBar? */
051 public abstract boolean getIsTaskBar();
052
053 /** More js options - JSON style. */
054 public abstract String getOptions();
055
056 /** Injected script. */
057 public abstract IScript getScript();
058
059 /** Get the id of the connected taskBar. */
060 public String getTaskBarId()
061 {
062 Object obj = getTaskBar();
063 if (obj == null)
064 return null;
065 else if (obj instanceof String)
066 return (String)obj;
067 else if (obj instanceof FloatingPane)
068 return ((FloatingPane)obj).getIdParameter();
069 else
070 throw new ApplicationRuntimeException("Parameter taskBar should either be a String or a FloatingPane");
071 }
072
073 /**
074 * {@inheritDoc}
075 */
076 public void renderWidget(IMarkupWriter writer, IRequestCycle cycle)
077 {
078 renderComponent(writer, cycle);
079 }
080
081 /**
082 * @see org.apache.tapestry.AbstractComponent#renderComponent(org.apache.tapestry.IMarkupWriter,
083 * org.apache.tapestry.IRequestCycle)
084 */
085 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
086 {
087 writer.begin("div");
088 writer.attribute("id", getIdParameter());
089
090 renderInformalParameters(writer, cycle);
091 renderBody(writer, cycle);
092
093 writer.end();
094
095 JSONObject obj = DojoUtils.parseJSONParameter(this, "options");
096
097 obj.put("title", getTitle());
098 if (getIcon() != null)
099 obj.put("iconSrc", getIcon().buildURL());
100 if (getHref() != null)
101 obj.put("href", getHref());
102 obj.put("widgetId", getId());
103 obj.put("toggle", "fade");
104 obj.put("constrainToContainer", getConstrainToContainer());
105 obj.put("displayMaximizeAction", getDisplayMaximizeAction());
106 obj.put("displayMinimizeAction", getDisplayMinimizeAction());
107 obj.put("displayCloseAction", getDisplayCloseAction());
108 obj.put("hasShadow", getHasShadow());
109 obj.put("resizable", isResizable());
110 obj.put("taskBarId", getTaskBarId());
111 //obj.put("persistenceWidgetPosition", getPersistPosition());
112
113 //Setup our script includes
114 Map scriptParms = new HashMap();
115 scriptParms.put("id", getIdParameter());
116 scriptParms.put("props", obj.toString());
117 PageRenderSupport pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, this);
118
119 getScript().execute(this, cycle, pageRenderSupport, scriptParms);
120 }
121 }