View Javadoc

1   package net.sf.tacos.components.scriptaculous;
2   
3   import java.util.HashMap;
4   import java.util.List;
5   import java.util.Map;
6   
7   import org.apache.tapestry.AbstractComponent;
8   import org.apache.tapestry.IMarkupWriter;
9   import org.apache.tapestry.IRequestCycle;
10  import org.apache.tapestry.IScript;
11  import org.apache.tapestry.TapestryUtils;
12  import org.apache.tapestry.json.JSONObject;
13  
14  /**
15   * Implementation of the <a href="http://wiki.script.aculo.us/scriptaculous/show/Draggables">Draggables</a>.
16   * <p>
17   * This component makes html elements draggable. Draggables can be dragged and dropped into Droppables.
18   * </p>
19   * 
20   * <p>Example:
21   * <pre>&lt;div jwcid="@tacos:Draggable" draggables="ognl:{'id1', 'id2', 'id3'}" /&gt;</pre>
22   * </p>
23   * @author Igor Drobiazko
24   * @since 4.1
25   * @see Droppable
26   */
27  public abstract class Draggable extends AbstractComponent {
28  	
29  	/**
30  	 * {@inheritDoc}
31  	 */
32  	protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
33          renderBody(writer, cycle);
34          
35          JSONObject json = new JSONObject();
36          json.put("revert", new Boolean(isRevert()));
37          json.put("ghosting", new Boolean(isGhosting()));
38          
39          Map parms = new HashMap();
40          parms.put("props", json.toString());
41          parms.put("draggables", getDraggables());
42          
43          getScript().execute(this, cycle, TapestryUtils.getPageRenderSupport(cycle, this), parms);
44  	}
45  	
46  	/**
47  	 * Returns {@link String[]} or {@link Collection} of element ids to make draggable.
48  	 */
49      public abstract List getDraggables();
50      
51      /**
52       * If set to <code>true</code>, clones the element and drags the clone,
53       * leaving the original in place until the clone is dropped.
54       */
55  	public abstract boolean isGhosting();
56  	
57  	/**
58  	 * If set to <code>true</code>, the element returns to its original position when the drags ends.
59  	 */
60  	public abstract boolean isRevert();
61  	
62      /** Injected {@link IScript}. */
63      public abstract IScript getScript();
64  }