4163 |
28 Feb 08 |
nicklas |
1 |
/* |
4480 |
05 Sep 08 |
jari |
$Id$ |
4163 |
28 Feb 08 |
nicklas |
3 |
|
4163 |
28 Feb 08 |
nicklas |
Copyright (C) 2008 Nicklas Nordborg |
4163 |
28 Feb 08 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
4163 |
28 Feb 08 |
nicklas |
Available at http://base.thep.lu.se/ |
4163 |
28 Feb 08 |
nicklas |
7 |
|
4163 |
28 Feb 08 |
nicklas |
BASE is free software; you can redistribute it and/or |
4163 |
28 Feb 08 |
nicklas |
modify it under the terms of the GNU General Public License |
4480 |
05 Sep 08 |
jari |
as published by the Free Software Foundation; either version 3 |
4163 |
28 Feb 08 |
nicklas |
of the License, or (at your option) any later version. |
4163 |
28 Feb 08 |
nicklas |
12 |
|
4163 |
28 Feb 08 |
nicklas |
BASE is distributed in the hope that it will be useful, |
4163 |
28 Feb 08 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4163 |
28 Feb 08 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4163 |
28 Feb 08 |
nicklas |
GNU General Public License for more details. |
4163 |
28 Feb 08 |
nicklas |
17 |
|
4163 |
28 Feb 08 |
nicklas |
You should have received a copy of the GNU General Public License |
4514 |
11 Sep 08 |
jari |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
4163 |
28 Feb 08 |
nicklas |
20 |
*/ |
7190 |
29 Aug 16 |
nicklas |
21 |
import java.io.File; |
4163 |
28 Feb 08 |
nicklas |
22 |
import java.io.FileInputStream; |
4163 |
28 Feb 08 |
nicklas |
23 |
import java.io.InputStream; |
4163 |
28 Feb 08 |
nicklas |
24 |
import java.util.List; |
4163 |
28 Feb 08 |
nicklas |
25 |
|
4163 |
28 Feb 08 |
nicklas |
26 |
import net.sf.basedb.core.BaseException; |
7190 |
29 Aug 16 |
nicklas |
27 |
import net.sf.basedb.test.extension.IActionButton; |
4207 |
04 Apr 08 |
nicklas |
28 |
import net.sf.basedb.util.Values; |
4163 |
28 Feb 08 |
nicklas |
29 |
import net.sf.basedb.util.extensions.Action; |
4163 |
28 Feb 08 |
nicklas |
30 |
import net.sf.basedb.util.extensions.ActionFactory; |
4207 |
04 Apr 08 |
nicklas |
31 |
import net.sf.basedb.util.extensions.ClientContext; |
4163 |
28 Feb 08 |
nicklas |
32 |
import net.sf.basedb.util.extensions.Extension; |
4163 |
28 Feb 08 |
nicklas |
33 |
import net.sf.basedb.util.extensions.ExtensionPoint; |
4163 |
28 Feb 08 |
nicklas |
34 |
import net.sf.basedb.util.extensions.ExtensionsInvoker; |
4207 |
04 Apr 08 |
nicklas |
35 |
import net.sf.basedb.util.extensions.InvokationContext; |
4163 |
28 Feb 08 |
nicklas |
36 |
import net.sf.basedb.util.extensions.Registry; |
4163 |
28 Feb 08 |
nicklas |
37 |
import net.sf.basedb.util.extensions.Renderer; |
4163 |
28 Feb 08 |
nicklas |
38 |
import net.sf.basedb.util.extensions.RendererFactory; |
7190 |
29 Aug 16 |
nicklas |
39 |
import net.sf.basedb.util.extensions.manager.ExtensionsManager; |
7190 |
29 Aug 16 |
nicklas |
40 |
import net.sf.basedb.util.extensions.manager.processor.RegisterExtensionsProcessor; |
4208 |
07 Apr 08 |
nicklas |
41 |
import net.sf.basedb.util.extensions.xml.PathConverter; |
4207 |
04 Apr 08 |
nicklas |
42 |
import net.sf.basedb.util.extensions.xml.PathSetter; |
4170 |
07 Mar 08 |
nicklas |
43 |
import net.sf.basedb.util.extensions.xml.VariableConverter; |
4170 |
07 Mar 08 |
nicklas |
44 |
import net.sf.basedb.util.extensions.xml.VariableSetter; |
4170 |
07 Mar 08 |
nicklas |
45 |
import net.sf.basedb.util.extensions.xml.XmlLoader; |
4163 |
28 Feb 08 |
nicklas |
46 |
|
4163 |
28 Feb 08 |
nicklas |
47 |
|
4163 |
28 Feb 08 |
nicklas |
48 |
|
4163 |
28 Feb 08 |
nicklas |
49 |
public class TestExtensions |
4163 |
28 Feb 08 |
nicklas |
50 |
{ |
4163 |
28 Feb 08 |
nicklas |
51 |
static boolean ok = true; |
4163 |
28 Feb 08 |
nicklas |
52 |
public static void main(String[] args) |
4163 |
28 Feb 08 |
nicklas |
53 |
{ |
4163 |
28 Feb 08 |
nicklas |
54 |
TestUtil.checkArgs(args); |
4163 |
28 Feb 08 |
nicklas |
55 |
TestUtil.begin(); |
4163 |
28 Feb 08 |
nicklas |
56 |
ok = test_all(); |
4163 |
28 Feb 08 |
nicklas |
57 |
TestUtil.stop(); |
4163 |
28 Feb 08 |
nicklas |
58 |
} |
4163 |
28 Feb 08 |
nicklas |
59 |
|
4163 |
28 Feb 08 |
nicklas |
60 |
static boolean test_all() |
4163 |
28 Feb 08 |
nicklas |
61 |
{ |
4163 |
28 Feb 08 |
nicklas |
62 |
write("++Testing extensions"); |
4163 |
28 Feb 08 |
nicklas |
63 |
|
4163 |
28 Feb 08 |
nicklas |
64 |
Registry registry = new Registry(); |
7190 |
29 Aug 16 |
nicklas |
65 |
ExtensionsManager manager = new ExtensionsManager(registry, null); |
4208 |
07 Apr 08 |
nicklas |
66 |
|
4163 |
28 Feb 08 |
nicklas |
67 |
test_load_extension_points_from_xml(registry, "data/test.extensions.xml", 1); |
4236 |
18 Apr 08 |
nicklas |
68 |
test_load_extensions_from_xml(registry, "data/test.extensions.xml", 5); |
7190 |
29 Aug 16 |
nicklas |
69 |
test_load_extensions_from_jar(manager, 3, "ExtensionOne.jar", "ExtensionTwo.jar", "ExtensionThree.jar"); |
4163 |
28 Feb 08 |
nicklas |
70 |
test_render_default(registry, "test.tools"); |
4163 |
28 Feb 08 |
nicklas |
71 |
|
4163 |
28 Feb 08 |
nicklas |
72 |
write("++Testing extensions " + (ok ? "OK" : "Failed") + "\n"); |
4163 |
28 Feb 08 |
nicklas |
73 |
return ok; |
4163 |
28 Feb 08 |
nicklas |
74 |
} |
4163 |
28 Feb 08 |
nicklas |
75 |
|
4163 |
28 Feb 08 |
nicklas |
76 |
static void write(String message) |
4163 |
28 Feb 08 |
nicklas |
77 |
{ |
4163 |
28 Feb 08 |
nicklas |
78 |
System.out.println(message); |
4163 |
28 Feb 08 |
nicklas |
79 |
} |
4163 |
28 Feb 08 |
nicklas |
80 |
|
6875 |
20 Apr 15 |
nicklas |
81 |
static void write_item(int i, ExtensionPoint<?> ep) |
4163 |
28 Feb 08 |
nicklas |
82 |
{ |
4163 |
28 Feb 08 |
nicklas |
83 |
if (!TestUtil.getSilent()) |
4163 |
28 Feb 08 |
nicklas |
84 |
{ |
4163 |
28 Feb 08 |
nicklas |
85 |
System.out.println(i+":\t"+ep.getId()+"\t"+ep.getActionClass()+"\t"+ep.getDescription() +"\t" + |
4163 |
28 Feb 08 |
nicklas |
86 |
ep.getRendererFactory() + "\t" + ep.allowRendererOverride()); |
4163 |
28 Feb 08 |
nicklas |
87 |
} |
4163 |
28 Feb 08 |
nicklas |
88 |
} |
4163 |
28 Feb 08 |
nicklas |
89 |
|
6875 |
20 Apr 15 |
nicklas |
90 |
static void write_item(int i, Extension<?> ext) |
4163 |
28 Feb 08 |
nicklas |
91 |
{ |
4163 |
28 Feb 08 |
nicklas |
92 |
if (!TestUtil.getSilent()) |
4163 |
28 Feb 08 |
nicklas |
93 |
{ |
4163 |
28 Feb 08 |
nicklas |
94 |
System.out.println(i+":\t"+ext.getId()+"\t"+ext.getExtends()+"\t"+ext.getActionFactory() + "\t" + |
4163 |
28 Feb 08 |
nicklas |
95 |
ext.getRendererFactory()); |
4163 |
28 Feb 08 |
nicklas |
96 |
} |
4163 |
28 Feb 08 |
nicklas |
97 |
} |
4163 |
28 Feb 08 |
nicklas |
98 |
|
4163 |
28 Feb 08 |
nicklas |
99 |
|
4163 |
28 Feb 08 |
nicklas |
100 |
static void test_load_extension_points_from_xml(Registry registry, String xmlFile, int expected) |
4163 |
28 Feb 08 |
nicklas |
101 |
{ |
4163 |
28 Feb 08 |
nicklas |
102 |
try |
4163 |
28 Feb 08 |
nicklas |
103 |
{ |
4163 |
28 Feb 08 |
nicklas |
104 |
InputStream in = new FileInputStream(xmlFile); |
4163 |
28 Feb 08 |
nicklas |
105 |
|
4163 |
28 Feb 08 |
nicklas |
106 |
XmlLoader loader = new XmlLoader(); |
4170 |
07 Mar 08 |
nicklas |
107 |
VariableConverter converter = new VariableConverter(); |
4208 |
07 Apr 08 |
nicklas |
108 |
converter.setVariable("HOME", "/home"); |
4208 |
07 Apr 08 |
nicklas |
109 |
converter.setVariable("ROOT", "/root"); |
4208 |
07 Apr 08 |
nicklas |
110 |
PathConverter path = new PathConverter("/root", "/home"); |
4208 |
07 Apr 08 |
nicklas |
111 |
loader.addValueConverter(path); |
4170 |
07 Mar 08 |
nicklas |
112 |
loader.addValueConverter(converter); |
4198 |
28 Mar 08 |
nicklas |
113 |
loader.loadXmlFile(in, xmlFile, null, true); |
4163 |
28 Feb 08 |
nicklas |
114 |
|
4163 |
28 Feb 08 |
nicklas |
115 |
List<ExtensionPoint<Action>> list = loader.getExtensionPoints(); |
4163 |
28 Feb 08 |
nicklas |
116 |
for (int i = 0; i < list.size(); ++i) |
4163 |
28 Feb 08 |
nicklas |
117 |
{ |
4163 |
28 Feb 08 |
nicklas |
118 |
ExtensionPoint<Action> ep = list.get(i); |
6030 |
28 Mar 12 |
nicklas |
119 |
registry.registerExtensionPoint(ep, null); |
4163 |
28 Feb 08 |
nicklas |
120 |
write_item(i, ep); |
4163 |
28 Feb 08 |
nicklas |
121 |
} |
4163 |
28 Feb 08 |
nicklas |
122 |
if (expected >= 0 && expected != list.size()) |
4163 |
28 Feb 08 |
nicklas |
123 |
{ |
4163 |
28 Feb 08 |
nicklas |
124 |
throw new BaseException("Expected "+expected+" extensions, not " + list.size()); |
4163 |
28 Feb 08 |
nicklas |
125 |
} |
4163 |
28 Feb 08 |
nicklas |
126 |
write("--Load extension points from xml OK (" + list.size() + ")"); |
4163 |
28 Feb 08 |
nicklas |
127 |
} |
4163 |
28 Feb 08 |
nicklas |
128 |
catch (Throwable t) |
4163 |
28 Feb 08 |
nicklas |
129 |
{ |
4163 |
28 Feb 08 |
nicklas |
130 |
write("--Load extension points from xml FAILED"); |
4163 |
28 Feb 08 |
nicklas |
131 |
t.printStackTrace(); |
4163 |
28 Feb 08 |
nicklas |
132 |
ok = false; |
4163 |
28 Feb 08 |
nicklas |
133 |
} |
4163 |
28 Feb 08 |
nicklas |
134 |
} |
4163 |
28 Feb 08 |
nicklas |
135 |
|
4163 |
28 Feb 08 |
nicklas |
136 |
static void test_load_extensions_from_xml(Registry registry, String xmlFile, int expected) |
4163 |
28 Feb 08 |
nicklas |
137 |
{ |
4163 |
28 Feb 08 |
nicklas |
138 |
try |
4163 |
28 Feb 08 |
nicklas |
139 |
{ |
4163 |
28 Feb 08 |
nicklas |
140 |
InputStream in = new FileInputStream(xmlFile); |
4163 |
28 Feb 08 |
nicklas |
141 |
|
4163 |
28 Feb 08 |
nicklas |
142 |
XmlLoader loader = new XmlLoader(); |
4170 |
07 Mar 08 |
nicklas |
143 |
VariableConverter converter = new VariableConverter(); |
4208 |
07 Apr 08 |
nicklas |
144 |
converter.setVariable("HOME", "/home"); |
4208 |
07 Apr 08 |
nicklas |
145 |
converter.setVariable("ROOT", "/root"); |
4208 |
07 Apr 08 |
nicklas |
146 |
PathConverter path = new PathConverter("/root", "/home"); |
4208 |
07 Apr 08 |
nicklas |
147 |
loader.addValueConverter(path); |
4170 |
07 Mar 08 |
nicklas |
148 |
loader.addValueConverter(converter); |
4198 |
28 Mar 08 |
nicklas |
149 |
loader.loadXmlFile(in, xmlFile, null, true); |
4163 |
28 Feb 08 |
nicklas |
150 |
|
4163 |
28 Feb 08 |
nicklas |
151 |
List<Extension<Action>> list = loader.getExtensions(); |
4163 |
28 Feb 08 |
nicklas |
152 |
for (int i = 0; i < list.size(); ++i) |
4163 |
28 Feb 08 |
nicklas |
153 |
{ |
4163 |
28 Feb 08 |
nicklas |
154 |
Extension<Action> ext = list.get(i); |
6030 |
28 Mar 12 |
nicklas |
155 |
registry.registerExtension(ext, null); |
4163 |
28 Feb 08 |
nicklas |
156 |
write_item(i, ext); |
4163 |
28 Feb 08 |
nicklas |
157 |
} |
4163 |
28 Feb 08 |
nicklas |
158 |
if (expected >= 0 && expected != list.size()) |
4163 |
28 Feb 08 |
nicklas |
159 |
{ |
4163 |
28 Feb 08 |
nicklas |
160 |
throw new BaseException("Expected "+expected+" extensions, not " + list.size()); |
4163 |
28 Feb 08 |
nicklas |
161 |
} |
4163 |
28 Feb 08 |
nicklas |
162 |
|
4163 |
28 Feb 08 |
nicklas |
163 |
write("--Load extensions from xml OK (" + list.size() + ")"); |
4163 |
28 Feb 08 |
nicklas |
164 |
} |
4163 |
28 Feb 08 |
nicklas |
165 |
catch (Throwable t) |
4163 |
28 Feb 08 |
nicklas |
166 |
{ |
4163 |
28 Feb 08 |
nicklas |
167 |
write("--Load extensions from xml FAILED"); |
4163 |
28 Feb 08 |
nicklas |
168 |
t.printStackTrace(); |
4163 |
28 Feb 08 |
nicklas |
169 |
ok = false; |
4163 |
28 Feb 08 |
nicklas |
170 |
} |
4163 |
28 Feb 08 |
nicklas |
171 |
} |
4163 |
28 Feb 08 |
nicklas |
172 |
|
7190 |
29 Aug 16 |
nicklas |
173 |
static void test_load_extensions_from_jar(ExtensionsManager manager, int expected, String... jarFiles) |
7190 |
29 Aug 16 |
nicklas |
174 |
{ |
7190 |
29 Aug 16 |
nicklas |
175 |
try |
7190 |
29 Aug 16 |
nicklas |
176 |
{ |
7190 |
29 Aug 16 |
nicklas |
177 |
for (String jarFile : jarFiles) |
7190 |
29 Aug 16 |
nicklas |
178 |
{ |
7190 |
29 Aug 16 |
nicklas |
179 |
manager.addFile(new File(jarFile)); |
7190 |
29 Aug 16 |
nicklas |
180 |
} |
7190 |
29 Aug 16 |
nicklas |
181 |
|
7190 |
29 Aug 16 |
nicklas |
182 |
RegisterExtensionsProcessor register = new RegisterExtensionsProcessor(new XmlLoader(), null); |
7190 |
29 Aug 16 |
nicklas |
183 |
manager.processFiles(register); |
7190 |
29 Aug 16 |
nicklas |
184 |
|
7190 |
29 Aug 16 |
nicklas |
185 |
int numRegistered = register.getNumRegistered(); |
7190 |
29 Aug 16 |
nicklas |
186 |
if (expected >= 0 && expected != numRegistered) |
7190 |
29 Aug 16 |
nicklas |
187 |
{ |
7190 |
29 Aug 16 |
nicklas |
188 |
throw new BaseException("Expected "+expected+" extensions, not " + numRegistered); |
7190 |
29 Aug 16 |
nicklas |
189 |
} |
7190 |
29 Aug 16 |
nicklas |
190 |
|
7190 |
29 Aug 16 |
nicklas |
191 |
write("--Load extensions from JAR OK (" + numRegistered + ")"); |
7190 |
29 Aug 16 |
nicklas |
192 |
} |
7190 |
29 Aug 16 |
nicklas |
193 |
catch (Throwable t) |
7190 |
29 Aug 16 |
nicklas |
194 |
{ |
7190 |
29 Aug 16 |
nicklas |
195 |
write("--Register extensions from JAR FAILED"); |
7190 |
29 Aug 16 |
nicklas |
196 |
t.printStackTrace(); |
7190 |
29 Aug 16 |
nicklas |
197 |
ok = false; |
7190 |
29 Aug 16 |
nicklas |
198 |
} |
7190 |
29 Aug 16 |
nicklas |
199 |
|
7190 |
29 Aug 16 |
nicklas |
200 |
} |
7190 |
29 Aug 16 |
nicklas |
201 |
|
4163 |
28 Feb 08 |
nicklas |
202 |
static void test_render_default(Registry registry, String extensionPoint) |
4163 |
28 Feb 08 |
nicklas |
203 |
{ |
4163 |
28 Feb 08 |
nicklas |
204 |
try |
4163 |
28 Feb 08 |
nicklas |
205 |
{ |
4207 |
04 Apr 08 |
nicklas |
206 |
ClientContext clientContext = new ClientContext(TestUtil.getSessionControl()); |
7605 |
26 Feb 19 |
nicklas |
207 |
ExtensionsInvoker<ActionButton> manager = registry.useExtensions(clientContext, null, extensionPoint); |
4163 |
28 Feb 08 |
nicklas |
208 |
|
4163 |
28 Feb 08 |
nicklas |
209 |
manager.renderDefault(); |
7190 |
29 Aug 16 |
nicklas |
210 |
write("--NOTE!! There should be 4 actions, 1 error message and then 3 more actions above"); |
4163 |
28 Feb 08 |
nicklas |
211 |
write("--Render default OK"); |
4163 |
28 Feb 08 |
nicklas |
212 |
} |
4163 |
28 Feb 08 |
nicklas |
213 |
catch (Throwable t) |
4163 |
28 Feb 08 |
nicklas |
214 |
{ |
4163 |
28 Feb 08 |
nicklas |
215 |
write("--Render default FAILED"); |
4163 |
28 Feb 08 |
nicklas |
216 |
t.printStackTrace(); |
4163 |
28 Feb 08 |
nicklas |
217 |
ok = false; |
4163 |
28 Feb 08 |
nicklas |
218 |
} |
4163 |
28 Feb 08 |
nicklas |
219 |
|
4163 |
28 Feb 08 |
nicklas |
220 |
} |
4163 |
28 Feb 08 |
nicklas |
221 |
|
4163 |
28 Feb 08 |
nicklas |
222 |
public static class ActionButton |
4207 |
04 Apr 08 |
nicklas |
223 |
implements IActionButton |
4163 |
28 Feb 08 |
nicklas |
224 |
{ |
4208 |
07 Apr 08 |
nicklas |
225 |
private String title; |
4208 |
07 Apr 08 |
nicklas |
226 |
private String icon; |
4208 |
07 Apr 08 |
nicklas |
227 |
private int type; |
4208 |
07 Apr 08 |
nicklas |
228 |
private boolean disabled; |
4170 |
07 Mar 08 |
nicklas |
229 |
|
4208 |
07 Apr 08 |
nicklas |
230 |
public ActionButton() |
4208 |
07 Apr 08 |
nicklas |
231 |
{} |
4208 |
07 Apr 08 |
nicklas |
232 |
|
4207 |
04 Apr 08 |
nicklas |
233 |
public ActionButton(String title, String icon, int type, boolean disabled) |
4163 |
28 Feb 08 |
nicklas |
234 |
{ |
4163 |
28 Feb 08 |
nicklas |
235 |
this.title = title; |
4170 |
07 Mar 08 |
nicklas |
236 |
this.icon = icon; |
4207 |
04 Apr 08 |
nicklas |
237 |
this.type = type; |
4207 |
04 Apr 08 |
nicklas |
238 |
this.disabled = disabled; |
4163 |
28 Feb 08 |
nicklas |
239 |
} |
4163 |
28 Feb 08 |
nicklas |
240 |
|
6127 |
14 Sep 12 |
nicklas |
241 |
@Override |
4163 |
28 Feb 08 |
nicklas |
242 |
public String getTitle() |
4163 |
28 Feb 08 |
nicklas |
243 |
{ |
4163 |
28 Feb 08 |
nicklas |
244 |
return title; |
4163 |
28 Feb 08 |
nicklas |
245 |
} |
4170 |
07 Mar 08 |
nicklas |
246 |
|
4208 |
07 Apr 08 |
nicklas |
247 |
public void setTitle(String title) |
4208 |
07 Apr 08 |
nicklas |
248 |
{ |
4208 |
07 Apr 08 |
nicklas |
249 |
this.title = title; |
4208 |
07 Apr 08 |
nicklas |
250 |
} |
4208 |
07 Apr 08 |
nicklas |
251 |
|
6127 |
14 Sep 12 |
nicklas |
252 |
@Override |
4170 |
07 Mar 08 |
nicklas |
253 |
public String getIcon() |
4170 |
07 Mar 08 |
nicklas |
254 |
{ |
4170 |
07 Mar 08 |
nicklas |
255 |
return icon; |
4170 |
07 Mar 08 |
nicklas |
256 |
} |
4207 |
04 Apr 08 |
nicklas |
257 |
|
4208 |
07 Apr 08 |
nicklas |
258 |
public void setIcon(String icon) |
4208 |
07 Apr 08 |
nicklas |
259 |
{ |
4208 |
07 Apr 08 |
nicklas |
260 |
this.icon = icon; |
4208 |
07 Apr 08 |
nicklas |
261 |
} |
4208 |
07 Apr 08 |
nicklas |
262 |
|
6127 |
14 Sep 12 |
nicklas |
263 |
@Override |
4207 |
04 Apr 08 |
nicklas |
264 |
public int getType() |
4207 |
04 Apr 08 |
nicklas |
265 |
{ |
4207 |
04 Apr 08 |
nicklas |
266 |
return type; |
4207 |
04 Apr 08 |
nicklas |
267 |
} |
4207 |
04 Apr 08 |
nicklas |
268 |
|
4208 |
07 Apr 08 |
nicklas |
269 |
public void setType(int type) |
4208 |
07 Apr 08 |
nicklas |
270 |
{ |
4208 |
07 Apr 08 |
nicklas |
271 |
this.type = type; |
4208 |
07 Apr 08 |
nicklas |
272 |
} |
4208 |
07 Apr 08 |
nicklas |
273 |
|
6127 |
14 Sep 12 |
nicklas |
274 |
@Override |
4207 |
04 Apr 08 |
nicklas |
275 |
public boolean isDisabled() |
4207 |
04 Apr 08 |
nicklas |
276 |
{ |
4207 |
04 Apr 08 |
nicklas |
277 |
return disabled; |
4207 |
04 Apr 08 |
nicklas |
278 |
} |
4208 |
07 Apr 08 |
nicklas |
279 |
|
4208 |
07 Apr 08 |
nicklas |
280 |
public void setDisabled(boolean disabled) |
4208 |
07 Apr 08 |
nicklas |
281 |
{ |
4208 |
07 Apr 08 |
nicklas |
282 |
this.disabled = disabled; |
4208 |
07 Apr 08 |
nicklas |
283 |
} |
4163 |
28 Feb 08 |
nicklas |
284 |
} |
4163 |
28 Feb 08 |
nicklas |
285 |
|
4163 |
28 Feb 08 |
nicklas |
286 |
public static class ActionButtonFactory |
4207 |
04 Apr 08 |
nicklas |
287 |
implements ActionFactory<IActionButton> |
4163 |
28 Feb 08 |
nicklas |
288 |
{ |
4163 |
28 Feb 08 |
nicklas |
289 |
|
4163 |
28 Feb 08 |
nicklas |
290 |
private String title; |
4170 |
07 Mar 08 |
nicklas |
291 |
private String icon; |
4207 |
04 Apr 08 |
nicklas |
292 |
private int type; |
4207 |
04 Apr 08 |
nicklas |
293 |
private boolean disabled; |
4163 |
28 Feb 08 |
nicklas |
294 |
|
4207 |
04 Apr 08 |
nicklas |
295 |
private IActionButton button; |
4207 |
04 Apr 08 |
nicklas |
296 |
|
4163 |
28 Feb 08 |
nicklas |
297 |
public ActionButtonFactory() |
4163 |
28 Feb 08 |
nicklas |
298 |
{} |
4163 |
28 Feb 08 |
nicklas |
299 |
|
4163 |
28 Feb 08 |
nicklas |
300 |
@Override |
4207 |
04 Apr 08 |
nicklas |
301 |
public IActionButton[] getActions(InvokationContext<? super IActionButton> context) |
4163 |
28 Feb 08 |
nicklas |
302 |
{ |
4163 |
28 Feb 08 |
nicklas |
303 |
if (button == null) |
4163 |
28 Feb 08 |
nicklas |
304 |
{ |
4207 |
04 Apr 08 |
nicklas |
305 |
button = new ActionButton(title, icon, type, disabled); |
4163 |
28 Feb 08 |
nicklas |
306 |
} |
4207 |
04 Apr 08 |
nicklas |
307 |
return new IActionButton[] { button }; |
4163 |
28 Feb 08 |
nicklas |
308 |
} |
4163 |
28 Feb 08 |
nicklas |
309 |
|
4163 |
28 Feb 08 |
nicklas |
310 |
@Override |
4207 |
04 Apr 08 |
nicklas |
311 |
public boolean prepareContext(InvokationContext<? super IActionButton> context) |
4163 |
28 Feb 08 |
nicklas |
312 |
{ |
4163 |
28 Feb 08 |
nicklas |
313 |
return true; |
4163 |
28 Feb 08 |
nicklas |
314 |
} |
4163 |
28 Feb 08 |
nicklas |
315 |
|
4163 |
28 Feb 08 |
nicklas |
316 |
public void setTitle(String title) |
4163 |
28 Feb 08 |
nicklas |
317 |
{ |
4163 |
28 Feb 08 |
nicklas |
318 |
this.title = title; |
4163 |
28 Feb 08 |
nicklas |
319 |
} |
4163 |
28 Feb 08 |
nicklas |
320 |
|
4170 |
07 Mar 08 |
nicklas |
321 |
@VariableSetter |
4207 |
04 Apr 08 |
nicklas |
322 |
@PathSetter |
4170 |
07 Mar 08 |
nicklas |
323 |
public void setIcon(String icon) |
4170 |
07 Mar 08 |
nicklas |
324 |
{ |
4170 |
07 Mar 08 |
nicklas |
325 |
this.icon = icon; |
4170 |
07 Mar 08 |
nicklas |
326 |
} |
4170 |
07 Mar 08 |
nicklas |
327 |
|
4207 |
04 Apr 08 |
nicklas |
328 |
public void setType(String type) |
4207 |
04 Apr 08 |
nicklas |
329 |
{ |
4207 |
04 Apr 08 |
nicklas |
330 |
this.type = Values.getInt(type); |
4207 |
04 Apr 08 |
nicklas |
331 |
} |
4207 |
04 Apr 08 |
nicklas |
332 |
|
4207 |
04 Apr 08 |
nicklas |
333 |
public void setDisabled(String disabled) |
4207 |
04 Apr 08 |
nicklas |
334 |
{ |
4207 |
04 Apr 08 |
nicklas |
335 |
this.disabled = Values.getBoolean(disabled); |
4207 |
04 Apr 08 |
nicklas |
336 |
} |
4207 |
04 Apr 08 |
nicklas |
337 |
|
4163 |
28 Feb 08 |
nicklas |
338 |
} |
4163 |
28 Feb 08 |
nicklas |
339 |
|
4236 |
18 Apr 08 |
nicklas |
340 |
public static class InvalidActionFactory |
4236 |
18 Apr 08 |
nicklas |
341 |
implements ActionFactory<Action> |
4236 |
18 Apr 08 |
nicklas |
342 |
{ |
4236 |
18 Apr 08 |
nicklas |
343 |
|
4236 |
18 Apr 08 |
nicklas |
344 |
public InvalidActionFactory() |
4236 |
18 Apr 08 |
nicklas |
345 |
{} |
4236 |
18 Apr 08 |
nicklas |
346 |
|
4236 |
18 Apr 08 |
nicklas |
347 |
@Override |
6875 |
20 Apr 15 |
nicklas |
348 |
public Action[] getActions(InvokationContext<? super Action> context) |
4236 |
18 Apr 08 |
nicklas |
349 |
{ |
4236 |
18 Apr 08 |
nicklas |
350 |
return new Action[] { new InvalidAction() }; |
4236 |
18 Apr 08 |
nicklas |
351 |
} |
4236 |
18 Apr 08 |
nicklas |
352 |
|
4236 |
18 Apr 08 |
nicklas |
353 |
@Override |
6875 |
20 Apr 15 |
nicklas |
354 |
public boolean prepareContext(InvokationContext<? super Action> context) |
4236 |
18 Apr 08 |
nicklas |
355 |
{ |
4236 |
18 Apr 08 |
nicklas |
356 |
return true; |
4236 |
18 Apr 08 |
nicklas |
357 |
} |
4236 |
18 Apr 08 |
nicklas |
358 |
} |
4236 |
18 Apr 08 |
nicklas |
359 |
|
4236 |
18 Apr 08 |
nicklas |
360 |
|
4236 |
18 Apr 08 |
nicklas |
361 |
public static class InvalidAction |
4236 |
18 Apr 08 |
nicklas |
362 |
implements Action |
4236 |
18 Apr 08 |
nicklas |
363 |
{} |
4236 |
18 Apr 08 |
nicklas |
364 |
|
4163 |
28 Feb 08 |
nicklas |
365 |
public static class ActionButtonRendererFactory |
4207 |
04 Apr 08 |
nicklas |
366 |
implements RendererFactory<IActionButton>, Renderer<IActionButton> |
4163 |
28 Feb 08 |
nicklas |
367 |
{ |
4163 |
28 Feb 08 |
nicklas |
368 |
|
4163 |
28 Feb 08 |
nicklas |
369 |
private String color = "#ffffff"; |
4163 |
28 Feb 08 |
nicklas |
370 |
|
4163 |
28 Feb 08 |
nicklas |
371 |
public ActionButtonRendererFactory() |
4163 |
28 Feb 08 |
nicklas |
372 |
{} |
4163 |
28 Feb 08 |
nicklas |
373 |
|
4163 |
28 Feb 08 |
nicklas |
374 |
public void setColor(String color) |
4163 |
28 Feb 08 |
nicklas |
375 |
{ |
4163 |
28 Feb 08 |
nicklas |
376 |
this.color = color; |
4163 |
28 Feb 08 |
nicklas |
377 |
} |
4163 |
28 Feb 08 |
nicklas |
378 |
|
4163 |
28 Feb 08 |
nicklas |
379 |
@Override |
4207 |
04 Apr 08 |
nicklas |
380 |
public void prepareContext(InvokationContext<? extends IActionButton> context) |
4163 |
28 Feb 08 |
nicklas |
381 |
{ |
4170 |
07 Mar 08 |
nicklas |
382 |
} |
4170 |
07 Mar 08 |
nicklas |
383 |
|
4170 |
07 Mar 08 |
nicklas |
384 |
@Override |
4207 |
04 Apr 08 |
nicklas |
385 |
public Renderer<IActionButton> getRenderer(InvokationContext<? extends IActionButton> context) |
4170 |
07 Mar 08 |
nicklas |
386 |
{ |
4163 |
28 Feb 08 |
nicklas |
387 |
return this; |
4163 |
28 Feb 08 |
nicklas |
388 |
} |
8144 |
21 Apr 23 |
nicklas |
389 |
|
4163 |
28 Feb 08 |
nicklas |
390 |
@Override |
8144 |
21 Apr 23 |
nicklas |
391 |
@Deprecated |
4207 |
04 Apr 08 |
nicklas |
392 |
public void render(IActionButton action) |
4163 |
28 Feb 08 |
nicklas |
393 |
{ |
8144 |
21 Apr 23 |
nicklas |
394 |
render(action, null); |
8144 |
21 Apr 23 |
nicklas |
395 |
} |
8144 |
21 Apr 23 |
nicklas |
396 |
|
8144 |
21 Apr 23 |
nicklas |
397 |
@Override |
8144 |
21 Apr 23 |
nicklas |
398 |
public void render(IActionButton action, Extension<? extends IActionButton> ext) |
8144 |
21 Apr 23 |
nicklas |
399 |
{ |
4207 |
04 Apr 08 |
nicklas |
400 |
if (!TestUtil.getSilent() && !action.isDisabled()) |
4163 |
28 Feb 08 |
nicklas |
401 |
{ |
4163 |
28 Feb 08 |
nicklas |
402 |
System.out.println("<div class=\"actionbutton\" style=\"color: " + |
4170 |
07 Mar 08 |
nicklas |
403 |
color + ";\"><img src=\"" + action.getIcon() + "\">" + |
4207 |
04 Apr 08 |
nicklas |
404 |
action.getTitle() + " (type=" + action.getType() + ")</div>"); |
4163 |
28 Feb 08 |
nicklas |
405 |
} |
4163 |
28 Feb 08 |
nicklas |
406 |
} |
4163 |
28 Feb 08 |
nicklas |
407 |
} |
4163 |
28 Feb 08 |
nicklas |
408 |
|
4163 |
28 Feb 08 |
nicklas |
409 |
} |