001    /*
002     * AbstractContainerWidget.java
003     *
004     * Created on February 3, 2007, 7:01 AM
005     */
006    
007    package net.sf.tacos.components.dojo;
008    
009    import org.apache.tapestry.IMarkupWriter;
010    import org.apache.tapestry.IRequestCycle;
011    import org.apache.tapestry.dojo.AbstractWidget;
012    
013    /**
014     * A widget that can also be a container.
015     * 
016     * @author andyhot
017     */
018    public abstract class GenericWidget extends AbstractWidget{
019        
020        public abstract boolean getIsContainer();
021        public abstract boolean getNeverDestroy();
022        
023        /**
024         * If this component is a container.
025         */
026        public boolean getContainerState()
027        {
028            return getIsContainer();
029        }
030        
031        public void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
032        {
033            if(!cycle.isRewinding() && !getNeverDestroy()) {            
034                if (!cycle.getResponseBuilder().isDynamic() 
035                        || cycle.getResponseBuilder().explicitlyContains(this)) {                
036                    setDestroy(false);
037                } else
038                    setDestroy(true);
039            }
040            
041            // don't render if not part of update response and we're not containers
042            if (!getContainerState()) {            
043                if (cycle.getResponseBuilder().isDynamic()
044                        && (!cycle.getResponseBuilder().explicitlyContains(this) 
045                                && !cycle.getResponseBuilder().contains(this))) {
046                    return;
047                }
048            }
049            
050            renderWidget(writer, cycle);
051        }    
052        
053        
054    }