1 package net.sf.tacos.components.scriptaculous;
2
3 import java.util.Collection;
4 import java.util.HashMap;
5 import java.util.Map;
6
7 import org.apache.tapestry.AbstractComponent;
8 import org.apache.tapestry.IActionListener;
9 import org.apache.tapestry.IDirect;
10 import org.apache.tapestry.IMarkupWriter;
11 import org.apache.tapestry.IRequestCycle;
12 import org.apache.tapestry.IScript;
13 import org.apache.tapestry.Tapestry;
14 import org.apache.tapestry.TapestryUtils;
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
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 public abstract class Droppable extends AbstractComponent implements IDirect{
37
38
39
40
41
42 public static final String DRAGGABLE_PARAMETER = "draggable";
43
44
45
46
47 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
48 writer.begin(getTemplateTagName());
49 renderIdAttribute(writer, cycle);
50 renderInformalParameters(writer, cycle);
51 renderBody(writer, cycle);
52 writer.end();
53
54 Map params = new HashMap();
55 params.put("component", this);
56 params.put("accept", getAccept());
57 params.put("hoverClass", getHoverClass());
58 if(getListener()!=null)
59 params.put("url", getLink().getURL());
60
61 getScript().execute(this, cycle, TapestryUtils.getPageRenderSupport(cycle, this), params);
62 }
63
64
65
66
67 public void trigger(IRequestCycle cycle) {
68 IActionListener listener = getListener();
69 if (listener == null)
70 throw Tapestry.createRequiredParameterException(this, "listener");
71
72 getListenerInvoker().invokeListener(listener, this, cycle);
73 }
74
75
76 private ILink getLink(){
77 return getEngine().getLink(isStateful(), new DirectServiceParameter(this));
78 }
79
80
81 public abstract IActionListener getListener();
82
83 public abstract IScript getScript();
84
85 public abstract ListenerInvoker getListenerInvoker();
86
87 public abstract IEngineService getEngine();
88
89
90
91
92 public abstract Collection getAccept();
93
94
95
96
97 public abstract String getHoverClass();
98 }