001    // Copyright 2004, 2005 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;
015    
016    import org.apache.tapestry.AbstractComponent;
017    import org.apache.tapestry.IMarkupWriter;
018    import org.apache.tapestry.IRequestCycle;
019    
020    
021    /**
022     * The base widget class for all dojo related widget components.
023     *
024     * @author jkuhnert
025     */
026    public abstract class AbstractWidget extends AbstractComponent implements IWidget
027    {
028        
029        public abstract void setDestroy(boolean destroy);
030        
031        /**
032         * Determined dynamically at runtime during rendering, informs widget implementations
033         * if they should destroy their client side widget equivalents or leave them in tact.
034         * 
035         * @return True if the widget should be destroyed on this render, false otherwise.
036         */
037        public abstract boolean getDestroy();
038        
039        /**
040         * {@inheritDoc}
041         */
042        public void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
043        {
044            if(!cycle.isRewinding()) {
045    
046                if (!cycle.getResponseBuilder().isDynamic() 
047                        || cycle.getResponseBuilder().explicitlyContains(this)) {
048                    
049                    setDestroy(false);
050                } else {
051                    
052                    setDestroy(true);
053                }
054            }
055            
056            renderWidget(writer, cycle);
057        }
058    }