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;
015    
016    import java.util.HashMap;
017    import java.util.Map;
018    import net.sf.tacos.util.JSONMarkupWriter;
019    import org.apache.tapestry.IMarkupWriter;
020    import org.apache.tapestry.IRequestCycle;
021    import org.apache.tapestry.IScript;
022    import org.apache.tapestry.TapestryUtils;
023    import org.apache.tapestry.dojo.AbstractWidget;
024    import org.apache.tapestry.json.JSONObject;
025    
026    /**
027     * Implementation of dojo's Tooltip.
028     *
029     * @since 4.1.1
030     */
031    public abstract class Tooltip extends AbstractWidget
032    {
033        public abstract String getStyle();
034        
035        /**
036         * {@inheritDoc}
037         */
038        public void renderWidget(IMarkupWriter writer, IRequestCycle cycle)
039        {
040            if (!cycle.isRewinding()) {
041                writer.begin(getTemplateTagName()); // use element specified
042                renderIdAttribute(writer, cycle); // render id="" client id
043                writer.attribute("style", getStyle());
044                //renderInformalParameters(writer, cycle);
045            }
046            
047            renderBody(writer, cycle);
048            
049            if (!cycle.isRewinding()) {
050                writer.end();
051            }
052            
053            if (!cycle.isRewinding()) {
054                JSONMarkupWriter jsonWriter = new JSONMarkupWriter();
055                renderInformalParameters(jsonWriter, cycle);
056                JSONObject json = jsonWriter.getAttributes();
057    
058                Map parms = new HashMap();
059                parms.put("component", this);
060                parms.put("props", json.toString());
061    
062                getScript().execute(this, cycle, TapestryUtils.getPageRenderSupport(cycle, this), parms);
063            }
064        }
065    
066        /** Injected script. */
067        public abstract IScript getScript();
068    }