1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
package org.apache.tapestry.dojo.html; |
15 |
|
|
16 |
|
import org.apache.hivemind.ApplicationRuntimeException; |
17 |
|
import org.apache.tapestry.*; |
18 |
|
import org.apache.tapestry.dojo.AbstractWidget; |
19 |
|
import org.apache.tapestry.engine.DirectServiceParameter; |
20 |
|
import org.apache.tapestry.engine.IEngineService; |
21 |
|
import org.apache.tapestry.json.JSONObject; |
22 |
|
import org.apache.tapestry.link.DirectLink; |
23 |
|
import org.apache.tapestry.listener.ListenerInvoker; |
24 |
|
|
25 |
|
import java.util.Collections; |
26 |
|
import java.util.HashMap; |
27 |
|
import java.util.List; |
28 |
|
import java.util.Map; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
2 |
public abstract class InlineEditBox extends AbstractWidget implements IDirect |
55 |
|
{ |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
public static final String TEXT_MODE = "text"; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
public static final String TEXT_AREA_MODE = "textarea"; |
67 |
|
|
68 |
|
public abstract String getValue(); |
69 |
|
public abstract void setValue(String value); |
70 |
|
|
71 |
|
public abstract String getMode(); |
72 |
|
|
73 |
|
public abstract int getMinWidth(); |
74 |
|
|
75 |
|
public abstract int getMinHeight(); |
76 |
|
|
77 |
|
public abstract boolean getDoFade(); |
78 |
|
|
79 |
|
public abstract boolean isDisabled(); |
80 |
|
|
81 |
|
public abstract IActionListener getListener(); |
82 |
|
|
83 |
|
public abstract Object getParameters(); |
84 |
|
|
85 |
|
public abstract void setStateful(boolean value); |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
public void renderWidget(IMarkupWriter writer, IRequestCycle cycle) |
91 |
|
{ |
92 |
2 |
if (!cycle.isRewinding()) |
93 |
|
{ |
94 |
1 |
writer.begin(getTemplateTagName()); |
95 |
1 |
renderInformalParameters(writer, cycle); |
96 |
1 |
renderIdAttribute(writer, cycle); |
97 |
|
} |
98 |
|
|
99 |
2 |
renderBody(writer, cycle); |
100 |
|
|
101 |
2 |
if (!cycle.isRewinding()) |
102 |
|
{ |
103 |
1 |
writer.end(); |
104 |
|
} |
105 |
|
|
106 |
2 |
if(getMode() == null || (!TEXT_MODE.equals(getMode()) && !TEXT_AREA_MODE.equals(getMode()))) |
107 |
0 |
throw new ApplicationRuntimeException(WidgetMessages.invalidTextMode(getMode())); |
108 |
|
|
109 |
2 |
if (cycle.isRewinding()) |
110 |
1 |
return; |
111 |
|
|
112 |
1 |
JSONObject prop = new JSONObject(); |
113 |
1 |
prop.put("widgetId", getClientId()); |
114 |
1 |
prop.put("value", getValue()); |
115 |
1 |
prop.put("mode", getMode()); |
116 |
1 |
prop.put("minWidth", getMinWidth()); |
117 |
1 |
prop.put("minHeight", getMinHeight()); |
118 |
1 |
prop.put("doFade", getDoFade()); |
119 |
|
|
120 |
1 |
Map parms = new HashMap(); |
121 |
1 |
parms.put("component", this); |
122 |
1 |
parms.put("props", prop.toString()); |
123 |
|
|
124 |
1 |
PageRenderSupport prs = TapestryUtils.getPageRenderSupport(cycle, this); |
125 |
1 |
getScript().execute(this, cycle, prs, parms); |
126 |
1 |
} |
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
public String getUpdateUrl() |
135 |
|
{ |
136 |
0 |
Object[] parameters = DirectLink.constructServiceParameters(getParameters()); |
137 |
|
|
138 |
0 |
DirectServiceParameter dsp = new DirectServiceParameter(this, parameters); |
139 |
|
|
140 |
0 |
return getEngine().getLink(isStateful(), dsp).getURL(); |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
public List getUpdateComponents() |
147 |
|
{ |
148 |
0 |
return Collections.EMPTY_LIST; |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
public boolean isAsync() |
155 |
|
{ |
156 |
0 |
return true; |
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
public boolean isJson() |
163 |
|
{ |
164 |
0 |
return false; |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
public void trigger(IRequestCycle cycle) |
171 |
|
{ |
172 |
0 |
String newValue = cycle.getParameter(getClientId()); |
173 |
|
|
174 |
0 |
setValue(newValue); |
175 |
|
|
176 |
0 |
if (getListener() != null) |
177 |
|
{ |
178 |
0 |
getListenerInvoker().invokeListener(getListener(), this, cycle); |
179 |
|
} |
180 |
0 |
} |
181 |
|
|
182 |
|
|
183 |
|
public abstract IEngineService getEngine(); |
184 |
|
|
185 |
|
|
186 |
|
public abstract IScript getScript(); |
187 |
|
|
188 |
|
|
189 |
|
public abstract ListenerInvoker getListenerInvoker(); |
190 |
|
} |