1
|
### Eclipse Workspace Patch 1.0
|
2
|
#P web_client_utils
|
3
|
Index: src/com/servoy/plugins/ReferencesBehaviorProvider.java
|
4
|
===================================================================
|
5
|
--- src/com/servoy/plugins/ReferencesBehaviorProvider.java (revision 0)
|
6
|
+++ src/com/servoy/plugins/ReferencesBehaviorProvider.java (working copy)
|
7
|
@@ -0,0 +1,209 @@
|
8
|
+/*
|
9
|
+ * BehaviorProvider.java
|
10
|
+ *
|
11
|
+ * Created on November 29, 2007, 1:23 PM
|
12
|
+ *
|
13
|
+ * To change this template, choose Tools | Template Manager
|
14
|
+ * and open the template in the editor.
|
15
|
+ */
|
16
|
+
|
17
|
+package com.servoy.plugins;
|
18
|
+
|
19
|
+import java.util.ArrayList;
|
20
|
+import java.util.List;
|
21
|
+
|
22
|
+import org.apache.wicket.Component;
|
23
|
+import org.apache.wicket.RequestCycle;
|
24
|
+import org.apache.wicket.ResourceReference;
|
25
|
+import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
|
26
|
+import org.apache.wicket.ajax.AjaxRequestTarget;
|
27
|
+import org.apache.wicket.markup.html.IHeaderResponse;
|
28
|
+import org.apache.wicket.util.string.Strings;
|
29
|
+
|
30
|
+import com.servoy.j2db.server.headlessclient.IWebClientPluginAccess;
|
31
|
+import com.servoy.j2db.ui.IProviderStylePropertyChanges;
|
32
|
+import com.servoy.j2db.ui.IStylePropertyChanges;
|
33
|
+
|
34
|
+/**
|
35
|
+ * A behavior that can link CSS and JS references to Wicket components.
|
36
|
+ *
|
37
|
+ * @author Sean Devlin
|
38
|
+ * @author Servoy Stuff
|
39
|
+ * @author Andrei Costescu
|
40
|
+ */
|
41
|
+public class ReferencesBehaviorProvider extends AbstractDefaultAjaxBehavior {
|
42
|
+
|
43
|
+ private static final long serialVersionUID = 7666601280436256255L;
|
44
|
+
|
45
|
+ protected final IWebClientPluginAccess app;
|
46
|
+
|
47
|
+ protected final List<Ref> references = new ArrayList<Ref>(2); // all reference types are kept in the order they were added (for example some js files need to load after a css file they use is loaded)
|
48
|
+
|
49
|
+ protected static class Ref {
|
50
|
+
|
51
|
+ public static final byte JS = 0;
|
52
|
+ public static final byte CSS = 1;
|
53
|
+
|
54
|
+ protected final byte type;
|
55
|
+ protected final Object value;
|
56
|
+
|
57
|
+ public Ref(byte type, Object value) {
|
58
|
+ this.type = type;
|
59
|
+ this.value = value;
|
60
|
+ }
|
61
|
+
|
62
|
+ @Override
|
63
|
+ public boolean equals(Object obj) {
|
64
|
+ if (this == obj)
|
65
|
+ return true;
|
66
|
+ if (obj == null)
|
67
|
+ return false;
|
68
|
+ if (getClass() != obj.getClass())
|
69
|
+ return false;
|
70
|
+ Ref other = (Ref) obj;
|
71
|
+ if (type != other.type)
|
72
|
+ return false;
|
73
|
+ if (value == null) {
|
74
|
+ if (other.value != null)
|
75
|
+ return false;
|
76
|
+ } else if (!value.equals(other.value))
|
77
|
+ return false;
|
78
|
+ return true;
|
79
|
+ }
|
80
|
+
|
81
|
+ }
|
82
|
+
|
83
|
+ public ReferencesBehaviorProvider(IWebClientPluginAccess app) {
|
84
|
+ this.app = app;
|
85
|
+ }
|
86
|
+
|
87
|
+ @Override
|
88
|
+ public void renderHead(IHeaderResponse response) {
|
89
|
+ super.renderHead(response);
|
90
|
+ ResourceReference resourceReference = new ResourceReference("media");
|
91
|
+ String solutionName = app.getSolutionName();
|
92
|
+ for (Ref ref : references) {
|
93
|
+ if (Ref.JS == ref.type) {
|
94
|
+ if (ref.value instanceof ResourceReference) {
|
95
|
+ response.renderJavascriptReference((ResourceReference)ref.value);
|
96
|
+ } else {
|
97
|
+ response.renderJavascriptReference(Strings.replaceAll((String)ref.value, "media:///", RequestCycle.get().urlFor(resourceReference) + "?s=" + solutionName + "&id=").toString());
|
98
|
+ }
|
99
|
+ } else if (Ref.CSS == ref.type) {
|
100
|
+ if (ref.value instanceof ResourceReference) {
|
101
|
+ response.renderCSSReference((ResourceReference)ref.value);
|
102
|
+ } else {
|
103
|
+ response.renderCSSReference(Strings.replaceAll((String)ref.value, "media:///", RequestCycle.get().urlFor(resourceReference) + "?s=" + solutionName + "&id=").toString());
|
104
|
+ }
|
105
|
+ }
|
106
|
+ }
|
107
|
+ }
|
108
|
+
|
109
|
+ @Override
|
110
|
+ protected void respond(AjaxRequestTarget target) {
|
111
|
+ // not interested
|
112
|
+ }
|
113
|
+
|
114
|
+ protected int getReferencesCount()
|
115
|
+ {
|
116
|
+ return references.size();
|
117
|
+ }
|
118
|
+
|
119
|
+ private void markComponentAsChanged(Component component) {
|
120
|
+ // if the component is already showing mark it for re-render so that our behavior gets rendered as well
|
121
|
+ Component c = component;
|
122
|
+ while (c != null && !(c instanceof IProviderStylePropertyChanges))
|
123
|
+ {
|
124
|
+ c = c.getParent();
|
125
|
+ }
|
126
|
+ if (c instanceof IProviderStylePropertyChanges) {
|
127
|
+ IStylePropertyChanges spc = ((IProviderStylePropertyChanges) c).getStylePropertyChanges();
|
128
|
+ if (spc != null) spc.setChanged();
|
129
|
+ }
|
130
|
+ }
|
131
|
+
|
132
|
+ public void addCssReference(String url, Component component) {
|
133
|
+ if (url != null) {
|
134
|
+ Ref r = new Ref(Ref.CSS, url);
|
135
|
+ if (!references.contains(r)) {
|
136
|
+ if (getReferencesCount() == 0) component.add(this);
|
137
|
+ references.add(r);
|
138
|
+ markComponentAsChanged(component);
|
139
|
+ }
|
140
|
+ }
|
141
|
+ }
|
142
|
+
|
143
|
+ public void addJsReference(String url, Component component) {
|
144
|
+ if (url != null) {
|
145
|
+ Ref r = new Ref(Ref.JS, url);
|
146
|
+ if (!references.contains(r)) {
|
147
|
+ if (getReferencesCount() == 0) component.add(this);
|
148
|
+ references.add(r);
|
149
|
+ markComponentAsChanged(component);
|
150
|
+ }
|
151
|
+ }
|
152
|
+ }
|
153
|
+
|
154
|
+ public void addCssReference(ResourceReference ref, Component component) {
|
155
|
+ if (ref != null) {
|
156
|
+ Ref r = new Ref(Ref.CSS, ref);
|
157
|
+ if (!references.contains(r)) {
|
158
|
+ if (getReferencesCount() == 0) component.add(this);
|
159
|
+ references.add(r);
|
160
|
+ markComponentAsChanged(component);
|
161
|
+ }
|
162
|
+ }
|
163
|
+ }
|
164
|
+
|
165
|
+ public void addJsReference(ResourceReference ref, Component component) {
|
166
|
+ if (ref != null) {
|
167
|
+ Ref r = new Ref(Ref.JS, ref);
|
168
|
+ if (!references.contains(r)) {
|
169
|
+ if (getReferencesCount() == 0) component.add(this);
|
170
|
+ references.add(r);
|
171
|
+ markComponentAsChanged(component);
|
172
|
+ }
|
173
|
+ }
|
174
|
+ }
|
175
|
+
|
176
|
+ public void removeCssReference(ResourceReference ref, Component component) {
|
177
|
+ if (ref != null) {
|
178
|
+ Ref r = new Ref(Ref.CSS, ref);
|
179
|
+ if (references.remove(r)) {
|
180
|
+ if (getReferencesCount() == 0) component.remove(this);
|
181
|
+ markComponentAsChanged(component);
|
182
|
+ }
|
183
|
+ }
|
184
|
+ }
|
185
|
+
|
186
|
+ public void removeCssReference(String url, Component component) {
|
187
|
+ if (url != null) {
|
188
|
+ Ref r = new Ref(Ref.CSS, url);
|
189
|
+ if (references.remove(r)) {
|
190
|
+ if (getReferencesCount() == 0) component.remove(this);
|
191
|
+ markComponentAsChanged(component);
|
192
|
+ }
|
193
|
+ }
|
194
|
+ }
|
195
|
+
|
196
|
+ public void removeJsReference(ResourceReference ref, Component component) {
|
197
|
+ if (ref != null) {
|
198
|
+ Ref r = new Ref(Ref.JS, ref);
|
199
|
+ if (references.remove(r)) {
|
200
|
+ if (getReferencesCount() == 0) component.remove(this);
|
201
|
+ markComponentAsChanged(component);
|
202
|
+ }
|
203
|
+ }
|
204
|
+ }
|
205
|
+
|
206
|
+ public void removeJsReference(String url, Component component) {
|
207
|
+ if (url != null) {
|
208
|
+ Ref r = new Ref(Ref.JS, url);
|
209
|
+ if (references.remove(r)) {
|
210
|
+ if (getReferencesCount() == 0) component.remove(this);
|
211
|
+ markComponentAsChanged(component);
|
212
|
+ }
|
213
|
+ }
|
214
|
+ }
|
215
|
+
|
216
|
+}
|
217
|
\ No newline at end of file
|
218
|
Index: src/com/servoy/plugins/BehaviorProvider.java
|
219
|
===================================================================
|
220
|
--- src/com/servoy/plugins/BehaviorProvider.java (revision 54)
|
221
|
+++ src/com/servoy/plugins/BehaviorProvider.java (working copy)
|
222
|
@@ -9,8 +9,7 @@
|
223
|
|
224
|
package com.servoy.plugins;
|
225
|
|
226
|
-import java.util.ArrayList;
|
227
|
-import java.util.List;
|
228
|
+import java.lang.reflect.Method;
|
229
|
import java.util.Map;
|
230
|
import java.util.concurrent.ConcurrentHashMap;
|
231
|
|
232
|
@@ -17,15 +16,13 @@
|
233
|
import org.apache.wicket.Request;
|
234
|
import org.apache.wicket.RequestCycle;
|
235
|
import org.apache.wicket.ResourceReference;
|
236
|
-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
|
237
|
import org.apache.wicket.ajax.AjaxRequestTarget;
|
238
|
-import org.apache.wicket.markup.html.IHeaderResponse;
|
239
|
import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
|
240
|
import org.apache.wicket.request.RequestParameters;
|
241
|
-import org.apache.wicket.util.string.Strings;
|
242
|
import org.mozilla.javascript.Function;
|
243
|
|
244
|
import com.servoy.j2db.scripting.FunctionDefinition;
|
245
|
+import com.servoy.j2db.server.headlessclient.IPageContributor;
|
246
|
import com.servoy.j2db.server.headlessclient.IWebClientPluginAccess;
|
247
|
import com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor;
|
248
|
import com.servoy.j2db.util.Utils;
|
249
|
@@ -36,50 +33,19 @@
|
250
|
* @author Sean Devlin
|
251
|
* @author Servoy Stuff
|
252
|
*/
|
253
|
-public class BehaviorProvider extends AbstractDefaultAjaxBehavior {
|
254
|
+public class BehaviorProvider extends ReferencesBehaviorProvider {
|
255
|
|
256
|
- private static final long serialVersionUID = 7666601280436256255L;
|
257
|
+ private static final long serialVersionUID = 7666601280436256256L;
|
258
|
|
259
|
- public final static String CALLBACK_BEHAVIOR = "com.servoy.jscallback";
|
260
|
+ public final static String BEHAVIOR_ID = "com.servoy.jscallback";
|
261
|
|
262
|
protected Map<Integer,FunctionDefinition> callbacks = new ConcurrentHashMap<Integer,FunctionDefinition>();
|
263
|
-
|
264
|
- protected final IWebClientPluginAccess app;
|
265
|
-
|
266
|
- private final List<Object> jsReferences = new ArrayList<Object>(2);
|
267
|
- private final List<Object> cssReferences = new ArrayList<Object>(2);
|
268
|
-
|
269
|
+ protected boolean showIndicator = true;
|
270
|
+
|
271
|
public BehaviorProvider(IWebClientPluginAccess app) {
|
272
|
- this.app = app;
|
273
|
+ super(app);
|
274
|
}
|
275
|
|
276
|
- @Override
|
277
|
- public void renderHead(IHeaderResponse response) {
|
278
|
- super.renderHead(response);
|
279
|
- ResourceReference resourceReference = new ResourceReference("media");
|
280
|
- String solutionName = app.getSolutionName();
|
281
|
- for (Object url : jsReferences) {
|
282
|
- if (url instanceof ResourceReference)
|
283
|
- {
|
284
|
- response.renderJavascriptReference((ResourceReference)url);
|
285
|
- }
|
286
|
- else {
|
287
|
- url = Strings.replaceAll((String)url, "media:///", RequestCycle.get().urlFor(resourceReference) + "?s=" + solutionName + "&id=");
|
288
|
- response.renderJavascriptReference(url.toString());
|
289
|
- }
|
290
|
- }
|
291
|
- for (Object url : cssReferences) {
|
292
|
- if (url instanceof ResourceReference)
|
293
|
- {
|
294
|
- response.renderCSSReference((ResourceReference)url);
|
295
|
- }
|
296
|
- else {
|
297
|
- url = Strings.replaceAll((String)url, "media:///", RequestCycle.get().urlFor(resourceReference) + "?s=" + solutionName + "&id=");
|
298
|
- response.renderCSSReference(url.toString());
|
299
|
- }
|
300
|
- }
|
301
|
- }
|
302
|
-
|
303
|
protected void respond(final AjaxRequestTarget target){
|
304
|
Request request = RequestCycle.get().getRequest();
|
305
|
final String param = request.getParameter("m");
|
306
|
@@ -114,8 +80,6 @@
|
307
|
}
|
308
|
}
|
309
|
|
310
|
- private boolean showIndicator = true;
|
311
|
-
|
312
|
@Override
|
313
|
protected String findIndicatorId() {
|
314
|
if (showIndicator)
|
315
|
@@ -126,7 +90,7 @@
|
316
|
|
317
|
public String getUrlForCallback(Function callback, String[] args, boolean showLoadingIndicator) {
|
318
|
// make sure it is added the the current page.
|
319
|
- app.getPageContributor().addBehavior(CALLBACK_BEHAVIOR, this);
|
320
|
+ app.getPageContributor().addBehavior(BEHAVIOR_ID, this);
|
321
|
|
322
|
FunctionDefinition fd = addCallBack(callback);
|
323
|
|
324
|
@@ -183,41 +147,81 @@
|
325
|
}
|
326
|
|
327
|
public void addCssReference(String url) {
|
328
|
- app.getPageContributor().addBehavior(CALLBACK_BEHAVIOR, this);
|
329
|
- if (url != null && !cssReferences.contains(url)) cssReferences.add(url);
|
330
|
+ if(!executeGlobalMethod("addGlobalCSSResourceReference", String.class, url)) {
|
331
|
+ app.getPageContributor().addBehavior(BEHAVIOR_ID, this);
|
332
|
+ if (url != null) {
|
333
|
+ Ref r = new Ref(Ref.CSS, url);
|
334
|
+ if (!references.contains(r)) references.add(r);
|
335
|
+ }
|
336
|
+ }
|
337
|
}
|
338
|
|
339
|
public void addJsReference(String url) {
|
340
|
- app.getPageContributor().addBehavior(CALLBACK_BEHAVIOR, this);
|
341
|
- if (url != null && !jsReferences.contains(url)) jsReferences.add(url);
|
342
|
+ if(!executeGlobalMethod("addGlobalJSResourceReference", String.class, url)) {
|
343
|
+ app.getPageContributor().addBehavior(BEHAVIOR_ID, this);
|
344
|
+ if (url != null) {
|
345
|
+ Ref r = new Ref(Ref.JS, url);
|
346
|
+ if (!references.contains(r)) references.add(r);
|
347
|
+ }
|
348
|
+ }
|
349
|
}
|
350
|
|
351
|
public void addCssReference(ResourceReference url) {
|
352
|
- app.getPageContributor().addBehavior(CALLBACK_BEHAVIOR, this);
|
353
|
- if (url != null && !cssReferences.contains(url)) cssReferences.add(url);
|
354
|
+ if(!executeGlobalMethod("addGlobalCSSResourceReference", ResourceReference.class, url)) {
|
355
|
+ app.getPageContributor().addBehavior(BEHAVIOR_ID, this);
|
356
|
+ if (url != null) {
|
357
|
+ Ref r = new Ref(Ref.CSS, url);
|
358
|
+ if (!references.contains(r)) references.add(r);
|
359
|
+ }
|
360
|
+ }
|
361
|
}
|
362
|
|
363
|
public void addJsReference(ResourceReference url) {
|
364
|
- app.getPageContributor().addBehavior(CALLBACK_BEHAVIOR, this);
|
365
|
- if (url != null && !jsReferences.contains(url)) jsReferences.add(url);
|
366
|
+ if(!executeGlobalMethod("addGlobalJSResourceReference", ResourceReference.class, url)) {
|
367
|
+ app.getPageContributor().addBehavior(BEHAVIOR_ID, this);
|
368
|
+ if (url != null) {
|
369
|
+ Ref r = new Ref(Ref.JS, url);
|
370
|
+ if (!references.contains(r)) references.add(r);
|
371
|
+ }
|
372
|
+ }
|
373
|
}
|
374
|
|
375
|
public void removeCssReference(ResourceReference url) {
|
376
|
- cssReferences.remove(url);
|
377
|
+ if(!executeGlobalMethod("removeGlobalResourceReference", ResourceReference.class, url)) {
|
378
|
+ if (url != null) references.remove(new Ref(Ref.CSS, url));
|
379
|
+ }
|
380
|
}
|
381
|
|
382
|
public void removeCssReference(String url) {
|
383
|
- cssReferences.remove(url);
|
384
|
+ if(!executeGlobalMethod("removeGlobalResourceReference", String.class, url)) {
|
385
|
+ if (url != null) references.remove(new Ref(Ref.CSS, url));
|
386
|
+ }
|
387
|
}
|
388
|
|
389
|
public void removeJsReference(ResourceReference url) {
|
390
|
- jsReferences.remove(url);
|
391
|
+ if(!executeGlobalMethod("removeGlobalResourceReference", ResourceReference.class, url)) {
|
392
|
+ if (url != null) references.remove(new Ref(Ref.JS, url));
|
393
|
+ }
|
394
|
}
|
395
|
|
396
|
public void removeJsReference(String url) {
|
397
|
- jsReferences.remove(url);
|
398
|
+ if(!executeGlobalMethod("removeGlobalResourceReference", String.class, url)) {
|
399
|
+ if (url != null) references.remove(new Ref(Ref.JS, url));
|
400
|
+ }
|
401
|
}
|
402
|
|
403
|
+ private boolean executeGlobalMethod(String methodName, Class<?> parameterType, Object url) {
|
404
|
+ try {
|
405
|
+ IPageContributor pageContributor = app.getPageContributor();
|
406
|
+ Class<? extends IPageContributor> clazz = pageContributor.getClass();
|
407
|
+ Method m = clazz.getDeclaredMethod(methodName, new Class[]{ parameterType });
|
408
|
+ m.invoke(pageContributor, new Object[] { url });
|
409
|
+ return true;
|
410
|
+ } catch (Exception e) {
|
411
|
+ return false;
|
412
|
+ }
|
413
|
+ }
|
414
|
+
|
415
|
/*
|
416
|
public interface ILatestPageBehaviorListener extends IBehaviorListener
|
417
|
{
|
418
|
Index: src/com/servoy/plugins/WebClientProvider.java
|
419
|
===================================================================
|
420
|
--- src/com/servoy/plugins/WebClientProvider.java (revision 54)
|
421
|
+++ src/com/servoy/plugins/WebClientProvider.java (working copy)
|
422
|
@@ -13,9 +13,12 @@
|
423
|
import org.mozilla.javascript.NativeJavaObject;
|
424
|
import org.mozilla.javascript.Scriptable;
|
425
|
|
426
|
+import com.servoy.j2db.IForm;
|
427
|
import com.servoy.j2db.Messages;
|
428
|
import com.servoy.j2db.plugins.IClientPluginAccess;
|
429
|
import com.servoy.j2db.server.headlessclient.IWebClientPluginAccess;
|
430
|
+import com.servoy.j2db.ui.IComponent;
|
431
|
+import com.servoy.j2db.ui.IFormUI;
|
432
|
import com.servoy.j2db.ui.IProviderStylePropertyChanges;
|
433
|
|
434
|
/**
|
435
|
@@ -106,6 +109,32 @@
|
436
|
if (bp != null) bp.addCssReference(url);
|
437
|
}
|
438
|
|
439
|
+ protected Component getFormUIComponent(IForm form) {
|
440
|
+ if (form != null) {
|
441
|
+ IFormUI formUI = form.getFormUI();
|
442
|
+ return getComponent(formUI);
|
443
|
+ }
|
444
|
+ return null;
|
445
|
+ }
|
446
|
+
|
447
|
+ protected Component getComponent(IComponent element) {
|
448
|
+ return (element instanceof Component) ? (Component) element : null;
|
449
|
+ }
|
450
|
+
|
451
|
+ public void addCssReference(String url, Component c) {
|
452
|
+ if (c != null) {
|
453
|
+ ReferencesBehaviorProvider bp = getBehavior(c);
|
454
|
+ if (bp != null) bp.addCssReference(url, c);
|
455
|
+ }
|
456
|
+ }
|
457
|
+
|
458
|
+ public void addCssReference(ResourceReference ref, Component c) {
|
459
|
+ if (c != null) {
|
460
|
+ ReferencesBehaviorProvider bp = getBehavior(c);
|
461
|
+ if (bp != null) bp.addCssReference(ref, c);
|
462
|
+ }
|
463
|
+ }
|
464
|
+
|
465
|
public void removeCssReference(ResourceReference url) {
|
466
|
BehaviorProvider bp = getBehavior();
|
467
|
if (bp != null) bp.removeCssReference(url);
|
468
|
@@ -116,6 +145,34 @@
|
469
|
if (bp != null) bp.removeCssReference(url);
|
470
|
}
|
471
|
|
472
|
+ public void removeCssReference(ResourceReference url, Component c) {
|
473
|
+ if (c != null) {
|
474
|
+ ReferencesBehaviorProvider bp = getBehavior(c);
|
475
|
+ if (bp != null) bp.removeCssReference(url, c);
|
476
|
+ }
|
477
|
+ }
|
478
|
+
|
479
|
+ public void removeCssReference(String url, Component c) {
|
480
|
+ if (c != null) {
|
481
|
+ ReferencesBehaviorProvider bp = getBehavior(c);
|
482
|
+ if (bp != null) bp.removeCssReference(url, c);
|
483
|
+ }
|
484
|
+ }
|
485
|
+
|
486
|
+ public void addJsReference(String url, Component c) {
|
487
|
+ if (c != null) {
|
488
|
+ ReferencesBehaviorProvider bp = getBehavior(c);
|
489
|
+ if (bp != null) bp.addJsReference(url, c);
|
490
|
+ }
|
491
|
+ }
|
492
|
+
|
493
|
+ public void addJsReference(ResourceReference url, Component c) {
|
494
|
+ if (c != null) {
|
495
|
+ ReferencesBehaviorProvider bp = getBehavior(c);
|
496
|
+ if (bp != null) bp.addJsReference(url, c);
|
497
|
+ }
|
498
|
+ }
|
499
|
+
|
500
|
public void addJsReference(String url) {
|
501
|
BehaviorProvider bp = getBehavior();
|
502
|
if (bp != null) bp.addJsReference(url);
|
503
|
@@ -136,15 +193,28 @@
|
504
|
if (bp != null) bp.removeJsReference(url);
|
505
|
}
|
506
|
|
507
|
+ public void removeJsReference(ResourceReference url, Component c) {
|
508
|
+ if (c != null) {
|
509
|
+ ReferencesBehaviorProvider bp = getBehavior(c);
|
510
|
+ if (bp != null) bp.removeJsReference(url, c);
|
511
|
+ }
|
512
|
+ }
|
513
|
|
514
|
+ public void removeJsReference(String url, Component c) {
|
515
|
+ if (c != null) {
|
516
|
+ ReferencesBehaviorProvider bp = getBehavior(c);
|
517
|
+ if (bp != null) bp.removeJsReference(url, c);
|
518
|
+ }
|
519
|
+ }
|
520
|
+
|
521
|
private BehaviorProvider getBehavior() {
|
522
|
if (getApp() != null) {
|
523
|
- if (getApp().getPageContributor().getBehavior(BehaviorProvider.CALLBACK_BEHAVIOR) == null) {
|
524
|
+ if (getApp().getPageContributor().getBehavior(BehaviorProvider.BEHAVIOR_ID) == null) {
|
525
|
behavior = new BehaviorProvider(getApp());
|
526
|
}
|
527
|
else
|
528
|
{
|
529
|
- behavior = (BehaviorProvider)getApp().getPageContributor().getBehavior(BehaviorProvider.CALLBACK_BEHAVIOR);
|
530
|
+ behavior = (BehaviorProvider)getApp().getPageContributor().getBehavior(BehaviorProvider.BEHAVIOR_ID);
|
531
|
}
|
532
|
return behavior;
|
533
|
}
|
534
|
@@ -151,6 +221,16 @@
|
535
|
return null;
|
536
|
}
|
537
|
|
538
|
+ private ReferencesBehaviorProvider getBehavior(Component c) {
|
539
|
+ if (getApp() == null) return null;
|
540
|
+
|
541
|
+ List<IBehavior> allBehaviors = c.getBehaviors();
|
542
|
+ for (IBehavior behavior : allBehaviors) {
|
543
|
+ if (behavior instanceof ReferencesBehaviorProvider) return (ReferencesBehaviorProvider) behavior;
|
544
|
+ }
|
545
|
+ return new ReferencesBehaviorProvider(getApp());
|
546
|
+ }
|
547
|
+
|
548
|
private JSONBehavior getJSONBehavior() {
|
549
|
if (getApp() != null) {
|
550
|
if (getApp().getPageContributor().getBehavior(JSONBehavior.CALLBACK_BEHAVIOR) == null) {
|
551
|
@@ -195,9 +275,9 @@
|
552
|
} else if ("getElementMarkupId".equals(string)) {
|
553
|
return new String[] { "formElement" };
|
554
|
} else if (string.startsWith("remove")) {
|
555
|
- return new String[] { ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "stringReference" : "stringOrWebResourceReference") };
|
556
|
+ return new String[] { ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "stringReference" : "stringOrWebResourceReference"), "[form/element]" };
|
557
|
} else if (string.startsWith("add")) {
|
558
|
- return new String[] { ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "stringReference" : "stringOrWebResourceReference") };
|
559
|
+ return new String[] { ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "stringReference" : "stringOrWebResourceReference"), "[form/element]" };
|
560
|
} else if ("isMarkupVisible".equals(string) || "setRendered".equals(string)) {
|
561
|
return new String[] { "element" };
|
562
|
} else if ("setMarkupVisible".equals(string)) {
|
563
|
@@ -237,17 +317,21 @@
|
564
|
} else if ("getElementMarkupId".equals(method)) {
|
565
|
return "var wicketID = %%elementName%%.getElementMarkupId(elements.aField);\n";
|
566
|
} else if ("removeJsReference".equals(method)) {
|
567
|
- return "%%elementName%%.removeJsReference('http://yourserver.com/js/yourscript.js');\n" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" :
|
568
|
- "\t// you can also remove Servoy internal reference scripts (like Yahoo UI widgets):\n\t%%elementName%%.removeJsReference(SERVOY_WEB_RESOURCES.YUI_JS_MENU)");
|
569
|
+ return "// remove global reference\n\t%%elementName%%.removeJsReference('http://yourserver.com/js/yourscript.js');\n\t//remove form reference\n\t%%elementName%%.removeJsReference('http://yourserver.com/js/yourscript.js', forms.myFormWithSpecialJS);\n\t//remove form element reference\n\t%%elementName%%.removeJsReference('http://yourserver.com/js/yourscript.js', elements.myElementWithSpecialJS);\n" +
|
570
|
+ ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" :
|
571
|
+ "\t// you can also remove Servoy internal reference scripts (like Yahoo UI widgets):\n\t%%elementName%%.removeJsReference(SERVOY_WEB_RESOURCES.YUI_JS_MENU)");
|
572
|
} else if ("removeCssReference".equals(method)) {
|
573
|
- return "%%elementName%%.removeCssReference('http://yourserver.com/css/yourstyle.css');\n" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" :
|
574
|
- "\t// you can also remove Servoy internal CSS style sheets (like Yahoo UI widgets styles):\n\t%%elementName%%.removeCssReference(SERVOY_WEB_RESOURCES.YUI_CSS_MENU)");
|
575
|
+ return "// remove global reference\n\t%%elementName%%.removeCssReference('http://yourserver.com/css/yourstyle.css');\n\t//remove form reference\n\t%%elementName%%.removeCssReference('http://yourserver.com/css/yourstyle.css', forms.myFormWithSpecialCSS);\n\t//remove form element reference\n\t%%elementName%%.removeCssReference('http://yourserver.com/css/yourstyle.css', elements.myElementWithSpecialCSS);\n" +
|
576
|
+ ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" :
|
577
|
+ "\t// you can also remove Servoy internal CSS style sheets (like Yahoo UI widgets styles):\n\t%%elementName%%.removeCssReference(SERVOY_WEB_RESOURCES.YUI_CSS_MENU)");
|
578
|
} else if ("addJsReference".equals(method)) {
|
579
|
- return "%%elementName%%.addJsReference('http://yourserver.com/js/yourscript.js');\n" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" :
|
580
|
- "\t// you can also add Servoy internal reference scripts (like Yahoo UI widgets):\n\t%%elementName%%.addJsReference(SERVOY_WEB_RESOURCES.YUI_JS_MENU)");
|
581
|
+ return "// add global reference (to all pages)\n\t%%elementName%%.addJsReference('http://yourserver.com/js/yourscript.js');\n\t//add form reference\n\t%%elementName%%.addJsReference('http://yourserver.com/js/yourscript.js', forms.myFormWithSpecialJS);\n\t//add form element reference\n\t%%elementName%%.addJsReference('http://yourserver.com/js/yourscript.js', elements.myElementWithSpecialJS);\n" +
|
582
|
+ ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" :
|
583
|
+ "\t// you can also add Servoy internal reference scripts (like Yahoo UI widgets):\n\t%%elementName%%.addJsReference(SERVOY_WEB_RESOURCES.YUI_JS_MENU)");
|
584
|
} else if ("addCssReference".equals(method)) {
|
585
|
- return "%%elementName%%.addCssReference('http://yourserver.com/css/yourstyle.css');\n" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" :
|
586
|
- "\t// you can also add Servoy internal CSS style sheets (like Yahoo UI widgets styles):\n\t%%elementName%%.addCssReference(SERVOY_WEB_RESOURCES.YUI_CSS_MENU)");
|
587
|
+ return "// add global reference (to all pages)\n\t%%elementName%%.addCssReference('http://yourserver.com/css/yourstyle.css');\n\t//add form reference\n\t%%elementName%%.addCssReference('http://yourserver.com/css/yourstyle.css', forms.myFormWithSpecialCSS);\n\t//add form element reference\n\t%%elementName%%.addCssReference('http://yourserver.com/css/yourstyle.css', elements.myElementWithSpecialCSS);\n" +
|
588
|
+ ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" :
|
589
|
+ "\t// you can also add Servoy internal CSS style sheets (like Yahoo UI widgets styles):\n\t%%elementName%%.addCssReference(SERVOY_WEB_RESOURCES.YUI_CSS_MENU)");
|
590
|
} else if ("isMarkupVisible".equals(method) || "setMarkupVisible".equals(method)) {
|
591
|
return "var visible = %%elementName%%.isMarkupVisible(elements.yourElement);\n\t%%elementName%%.setMarkupVisible(elements.yourElement,!visible);\n";
|
592
|
} else if ("setRendered".equals(method)) {
|
593
|
@@ -276,13 +360,13 @@
|
594
|
else if ("getElementMarkupId".equals(method))
|
595
|
return "Returns a Servoy markup Id to be used in your browser scripts";
|
596
|
else if ("removeJsReference".equals(method))
|
597
|
- return "Removes a javascript url" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : " or build in servoy javascript reference (see SERVOY_WEB_RESOURCES)");
|
598
|
+ return "Removes a global (or form/element when the second arg. is provided) javascript url" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : " or built-in Servoy javascript reference (see SERVOY_WEB_RESOURCES)" );
|
599
|
else if ("removeCssReference".equals(method))
|
600
|
- return "Removes a css url" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : " or build in servoy css reference (see SERVOY_WEB_RESOURCES)");
|
601
|
+ return "Removes a global (or form/element when the second arg. is provided) css url" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : " or built-in Servoy css reference (see SERVOY_WEB_RESOURCES)");
|
602
|
else if ("addJsReference".equals(method))
|
603
|
- return "Adds a javascript url" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : " or build in servoy javascript reference (see SERVOY_WEB_RESOURCES) to the page");
|
604
|
+ return "Adds a global (or form/element when the second arg. is provided) javascript url" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : " or built-in servoy javascript reference (see SERVOY_WEB_RESOURCES) to all pages (when global) or only to pages containing that form/element (when the second arg. is provided).<br/>\nNote: up to plugin version v1.3.6, global references had a bug - they were only added to current request's page (each time the API was used).");
|
605
|
else if ("addCssReference".equals(method))
|
606
|
- return "Adds a css url" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : " or build in servoy css reference (see SERVOY_WEB_RESOURCES) to the page");
|
607
|
+ return "Adds a global (or form/element when the second arg. is provided) css url" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : " or built-in servoy css reference (see SERVOY_WEB_RESOURCES) to all pages (when global) or only to pages containing that form/element (when the second arg. is provided).<br/>\nNote: up to plugin version v1.3.6, global references had a bug - they were only added to current request's page (each time the API was used).");
|
608
|
else if ("isMarkupVisible".equals(method))
|
609
|
return "Returns true if the elements markup is visible in the page";
|
610
|
else if ("setMarkupVisible".equals(method))
|
611
|
@@ -447,6 +531,29 @@
|
612
|
removeCssReference(url);
|
613
|
}
|
614
|
|
615
|
+ protected Component getWicketComponentFromFormOrElement(Object formOrElement) {
|
616
|
+ Component c = null;
|
617
|
+ if (formOrElement instanceof IForm) c = getFormUIComponent((IForm) formOrElement);
|
618
|
+ else if (formOrElement instanceof IComponent) c = getComponent((IComponent) formOrElement);
|
619
|
+ return c;
|
620
|
+ }
|
621
|
+
|
622
|
+ public void js_addCssReference(String url, Object formOrElement) {
|
623
|
+ addCssReference(url, getWicketComponentFromFormOrElement(formOrElement));
|
624
|
+ }
|
625
|
+
|
626
|
+ public void js_addCssReference(ResourceReference ref, Object formOrElement) {
|
627
|
+ addCssReference(ref, getWicketComponentFromFormOrElement(formOrElement));
|
628
|
+ }
|
629
|
+
|
630
|
+ public void js_removeCssReference(ResourceReference ref, Object formOrElement) {
|
631
|
+ removeCssReference(ref, getWicketComponentFromFormOrElement(formOrElement));
|
632
|
+ }
|
633
|
+
|
634
|
+ public void js_removeCssReference(String url, Object formOrElement) {
|
635
|
+ removeCssReference(url, getWicketComponentFromFormOrElement(formOrElement));
|
636
|
+ }
|
637
|
+
|
638
|
public void js_addJsReference(String url) {
|
639
|
addJsReference(url);
|
640
|
}
|
641
|
@@ -463,6 +570,22 @@
|
642
|
removeJsReference(url);
|
643
|
}
|
644
|
|
645
|
+ public void js_addJsReference(String url, Object formOrElement) {
|
646
|
+ addJsReference(url, getWicketComponentFromFormOrElement(formOrElement));
|
647
|
+ }
|
648
|
+
|
649
|
+ public void js_addJsReference(ResourceReference url, Object formOrElement) {
|
650
|
+ addJsReference(url, getWicketComponentFromFormOrElement(formOrElement));
|
651
|
+ }
|
652
|
+
|
653
|
+ public void js_removeJsReference(String url, Object formOrElement) {
|
654
|
+ removeJsReference(url, getWicketComponentFromFormOrElement(formOrElement));
|
655
|
+ }
|
656
|
+
|
657
|
+ public void js_removeJsReference(ResourceReference url, Object formOrElement) {
|
658
|
+ removeJsReference(url, getWicketComponentFromFormOrElement(formOrElement));
|
659
|
+ }
|
660
|
+
|
661
|
private IWebClientPluginAccess getApp() {
|
662
|
IClientPluginAccess app = plugin.getApp();
|
663
|
if (app != null && app instanceof IWebClientPluginAccess) {
|