001    package net.sf.tacos.components.scriptaculous;
002    
003    import java.util.HashMap;
004    import java.util.List;
005    import java.util.Map;
006    
007    import org.apache.tapestry.AbstractComponent;
008    import org.apache.tapestry.IMarkupWriter;
009    import org.apache.tapestry.IRequestCycle;
010    import org.apache.tapestry.IScript;
011    import org.apache.tapestry.TapestryUtils;
012    import org.apache.tapestry.json.JSONObject;
013    
014    /**
015     * Implementation of the <a href="http://wiki.script.aculo.us/scriptaculous/show/Draggables">Draggables</a>.
016     * <p>
017     * This component makes html elements draggable. Draggables can be dragged and dropped into Droppables.
018     * </p>
019     * 
020     * <p>Example:
021     * <pre>&lt;div jwcid="@tacos:Draggable" draggables="ognl:{'id1', 'id2', 'id3'}" /&gt;</pre>
022     * </p>
023     * @author Igor Drobiazko
024     * @since 4.1
025     * @see Droppable
026     */
027    public abstract class Draggable extends AbstractComponent {
028            
029            /**
030             * {@inheritDoc}
031             */
032            protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
033            renderBody(writer, cycle);
034            
035            JSONObject json = new JSONObject();
036            json.put("revert", new Boolean(isRevert()));
037            json.put("ghosting", new Boolean(isGhosting()));
038            
039            Map parms = new HashMap();
040            parms.put("props", json.toString());
041            parms.put("draggables", getDraggables());
042            
043            getScript().execute(this, cycle, TapestryUtils.getPageRenderSupport(cycle, this), parms);
044            }
045            
046            /**
047             * Returns {@link String[]} or {@link Collection} of element ids to make draggable.
048             */
049        public abstract List getDraggables();
050        
051        /**
052         * If set to <code>true</code>, clones the element and drags the clone,
053         * leaving the original in place until the clone is dropped.
054         */
055            public abstract boolean isGhosting();
056            
057            /**
058             * If set to <code>true</code>, the element returns to its original position when the drags ends.
059             */
060            public abstract boolean isRevert();
061            
062        /** Injected {@link IScript}. */
063        public abstract IScript getScript();
064    }