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 net.sf.tacos.components.dojo.old;
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.0
035     * @deprecated Use the {@link DojoWidget} component.
036     */
037    public abstract class FloatingPane extends AbstractComponent implements IWidget, IDojoFloatingPane 
038    {
039        /** Has Tool bar. */
040        public abstract boolean getHasToolbar();
041    
042        /** Allow resize. */
043        public abstract boolean isResizable();
044    
045        /** Should persist position (with cookies). */
046        public abstract boolean getPersistPosition();
047    
048        /** id. */
049        public abstract String getIdParameter();
050    
051        /** Is this pane a taskBar? */
052        public abstract boolean getIsTaskBar();
053    
054        /** More js options - JSON style. */
055        public abstract String getOptions();
056    
057        /** Injected script. */
058        public abstract IScript getScript();
059        
060        /** Get the id of the connected taskBar. */
061        public String getTaskBarId()
062        {
063            Object obj = getTaskBar();
064            if (obj == null)
065                return null;
066            else if (obj instanceof String)
067                return (String)obj;
068            else if (obj instanceof FloatingPane)
069                return ((FloatingPane)obj).getIdParameter();
070            else
071                throw new ApplicationRuntimeException("Parameter taskBar should either be a String or a FloatingPane");
072        }
073        
074        /**
075         * {@inheritDoc}
076         */
077        public void renderWidget(IMarkupWriter writer, IRequestCycle cycle)
078        {
079            renderComponent(writer, cycle);
080        }    
081    
082        /**
083         * @see org.apache.tapestry.AbstractComponent#renderComponent(org.apache.tapestry.IMarkupWriter,
084         *      org.apache.tapestry.IRequestCycle)
085         */
086        protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
087        {
088            writer.begin("div");
089            writer.attribute("id", getIdParameter());
090            
091            renderInformalParameters(writer, cycle);
092            renderBody(writer, cycle);
093            
094            writer.end();
095            
096            JSONObject obj = DojoUtils.parseJSONParameter(this, "options");
097    
098            obj.put("title", getTitle());
099            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    }