View Javadoc

1   package net.sf.tacos.components.dojo;
2   
3   import java.util.Collection;
4   import java.util.HashMap;
5   import java.util.Map;
6   
7   import org.apache.tapestry.IActionListener;
8   import org.apache.tapestry.IDirect;
9   import org.apache.tapestry.IMarkupWriter;
10  import org.apache.tapestry.IRequestCycle;
11  import org.apache.tapestry.IScript;
12  import org.apache.tapestry.Tapestry;
13  import org.apache.tapestry.TapestryUtils;
14  import org.apache.tapestry.dojo.AbstractWidget;
15  import org.apache.tapestry.engine.DirectServiceParameter;
16  import org.apache.tapestry.engine.IEngineService;
17  import org.apache.tapestry.engine.ILink;
18  import org.apache.tapestry.listener.ListenerInvoker;
19  
20  public abstract class DropTarget extends AbstractWidget implements IDirect{
21  	/**
22  	 * Name of the {@link IRequestCycle} parameter whose value is the
23  	 * identifier of the dropped draggable source
24  	 * @see {@link IRequestCycle#getParameter(String)}
25  	 */
26  	public static final String DRAG_SOURCE_PARAMETER = "dragSourceId";
27  	
28  	/**
29  	 * {@inheritDoc}
30  	 */
31  	public void renderWidget(IMarkupWriter writer, IRequestCycle cycle) {
32          writer.begin(getTemplateTagName());
33          renderIdAttribute(writer, cycle);
34          renderInformalParameters(writer, cycle);
35          renderBody(writer, cycle);
36          writer.end();
37          
38          if (!cycle.isRewinding()) {
39              Map params = new HashMap();
40              params.put("component", this);
41              params.put("dragSource", getDragSource());
42              params.put("dragSourceElement", getDragSourceElement());
43              params.put("dragSourceTag", getDragSourceTag());
44              params.put("acceptedTypes", getAcceptedTypes());
45              params.put("insertDragSource", new Boolean(isInsertDragSource()));
46              params.put("onDrop", getOnDrop());
47              if (getListener()!=null)
48                  params.put("url", getLink().getURL());        
49  
50              getScript().execute(this, cycle, TapestryUtils.getPageRenderSupport(cycle, this), params);
51          }
52  	}
53  	
54  	/**
55  	 * {@inheritDoc}
56  	 */
57  	public void trigger(IRequestCycle cycle) {
58          IActionListener listener = getListener();
59          if (listener == null)
60              throw Tapestry.createRequiredParameterException(this, "listener");
61          
62          getListenerInvoker().invokeListener(listener, this, cycle);
63  	}
64  	
65  	/**Returns a link*/
66  	private ILink getLink(){
67  		DirectServiceParameter dsp = new DirectServiceParameter(this);
68  		return getEngine().getLink(isStateful(), dsp);
69  	}
70  	
71      /** Reference to js function - called when a drop event is generated.*/
72      public abstract String getOnDrop();        
73      /** List item source parameter */
74      public abstract Object getDragSource();
75      /** Drag source element */
76      public abstract String getDragSourceElement();
77      /** Drag source tag */
78      public abstract String getDragSourceTag();
79      /** Type of tags target accepts */
80      public abstract Collection getAcceptedTypes();
81      /** Whether or not to allow insertion of source element */
82      public abstract boolean isInsertDragSource();
83      /** Injected listener parameter, may be null. */
84      public abstract IActionListener getListener();
85      /** Injected script. */
86      public abstract IScript getScript();
87      /** Injected listener invoker. */
88      public abstract ListenerInvoker getListenerInvoker();
89      /** Injected engine service . */
90      public abstract IEngineService getEngine();
91  
92  }