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
23
24
25
26 public static final String DRAG_SOURCE_PARAMETER = "dragSourceId";
27
28
29
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
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
66 private ILink getLink(){
67 DirectServiceParameter dsp = new DirectServiceParameter(this);
68 return getEngine().getLink(isStateful(), dsp);
69 }
70
71
72 public abstract String getOnDrop();
73
74 public abstract Object getDragSource();
75
76 public abstract String getDragSourceElement();
77
78 public abstract String getDragSourceTag();
79
80 public abstract Collection getAcceptedTypes();
81
82 public abstract boolean isInsertDragSource();
83
84 public abstract IActionListener getListener();
85
86 public abstract IScript getScript();
87
88 public abstract ListenerInvoker getListenerInvoker();
89
90 public abstract IEngineService getEngine();
91
92 }