### Eclipse Workspace Patch 1.0 #P web_client_utils Index: src/com/servoy/plugins/ReferencesBehaviorProvider.java =================================================================== --- src/com/servoy/plugins/ReferencesBehaviorProvider.java (revision 0) +++ src/com/servoy/plugins/ReferencesBehaviorProvider.java (working copy) @@ -0,0 +1,209 @@ +/* + * BehaviorProvider.java + * + * Created on November 29, 2007, 1:23 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package com.servoy.plugins; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.wicket.Component; +import org.apache.wicket.RequestCycle; +import org.apache.wicket.ResourceReference; +import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.markup.html.IHeaderResponse; +import org.apache.wicket.util.string.Strings; + +import com.servoy.j2db.server.headlessclient.IWebClientPluginAccess; +import com.servoy.j2db.ui.IProviderStylePropertyChanges; +import com.servoy.j2db.ui.IStylePropertyChanges; + +/** + * A behavior that can link CSS and JS references to Wicket components. + * + * @author Sean Devlin + * @author Servoy Stuff + * @author Andrei Costescu + */ +public class ReferencesBehaviorProvider extends AbstractDefaultAjaxBehavior { + + private static final long serialVersionUID = 7666601280436256255L; + + protected final IWebClientPluginAccess app; + + protected final List references = new ArrayList(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) + + protected static class Ref { + + public static final byte JS = 0; + public static final byte CSS = 1; + + protected final byte type; + protected final Object value; + + public Ref(byte type, Object value) { + this.type = type; + this.value = value; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Ref other = (Ref) obj; + if (type != other.type) + return false; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equals(other.value)) + return false; + return true; + } + + } + + public ReferencesBehaviorProvider(IWebClientPluginAccess app) { + this.app = app; + } + + @Override + public void renderHead(IHeaderResponse response) { + super.renderHead(response); + ResourceReference resourceReference = new ResourceReference("media"); + String solutionName = app.getSolutionName(); + for (Ref ref : references) { + if (Ref.JS == ref.type) { + if (ref.value instanceof ResourceReference) { + response.renderJavascriptReference((ResourceReference)ref.value); + } else { + response.renderJavascriptReference(Strings.replaceAll((String)ref.value, "media:///", RequestCycle.get().urlFor(resourceReference) + "?s=" + solutionName + "&id=").toString()); + } + } else if (Ref.CSS == ref.type) { + if (ref.value instanceof ResourceReference) { + response.renderCSSReference((ResourceReference)ref.value); + } else { + response.renderCSSReference(Strings.replaceAll((String)ref.value, "media:///", RequestCycle.get().urlFor(resourceReference) + "?s=" + solutionName + "&id=").toString()); + } + } + } + } + + @Override + protected void respond(AjaxRequestTarget target) { + // not interested + } + + protected int getReferencesCount() + { + return references.size(); + } + + private void markComponentAsChanged(Component component) { + // if the component is already showing mark it for re-render so that our behavior gets rendered as well + Component c = component; + while (c != null && !(c instanceof IProviderStylePropertyChanges)) + { + c = c.getParent(); + } + if (c instanceof IProviderStylePropertyChanges) { + IStylePropertyChanges spc = ((IProviderStylePropertyChanges) c).getStylePropertyChanges(); + if (spc != null) spc.setChanged(); + } + } + + public void addCssReference(String url, Component component) { + if (url != null) { + Ref r = new Ref(Ref.CSS, url); + if (!references.contains(r)) { + if (getReferencesCount() == 0) component.add(this); + references.add(r); + markComponentAsChanged(component); + } + } + } + + public void addJsReference(String url, Component component) { + if (url != null) { + Ref r = new Ref(Ref.JS, url); + if (!references.contains(r)) { + if (getReferencesCount() == 0) component.add(this); + references.add(r); + markComponentAsChanged(component); + } + } + } + + public void addCssReference(ResourceReference ref, Component component) { + if (ref != null) { + Ref r = new Ref(Ref.CSS, ref); + if (!references.contains(r)) { + if (getReferencesCount() == 0) component.add(this); + references.add(r); + markComponentAsChanged(component); + } + } + } + + public void addJsReference(ResourceReference ref, Component component) { + if (ref != null) { + Ref r = new Ref(Ref.JS, ref); + if (!references.contains(r)) { + if (getReferencesCount() == 0) component.add(this); + references.add(r); + markComponentAsChanged(component); + } + } + } + + public void removeCssReference(ResourceReference ref, Component component) { + if (ref != null) { + Ref r = new Ref(Ref.CSS, ref); + if (references.remove(r)) { + if (getReferencesCount() == 0) component.remove(this); + markComponentAsChanged(component); + } + } + } + + public void removeCssReference(String url, Component component) { + if (url != null) { + Ref r = new Ref(Ref.CSS, url); + if (references.remove(r)) { + if (getReferencesCount() == 0) component.remove(this); + markComponentAsChanged(component); + } + } + } + + public void removeJsReference(ResourceReference ref, Component component) { + if (ref != null) { + Ref r = new Ref(Ref.JS, ref); + if (references.remove(r)) { + if (getReferencesCount() == 0) component.remove(this); + markComponentAsChanged(component); + } + } + } + + public void removeJsReference(String url, Component component) { + if (url != null) { + Ref r = new Ref(Ref.JS, url); + if (references.remove(r)) { + if (getReferencesCount() == 0) component.remove(this); + markComponentAsChanged(component); + } + } + } + +} \ No newline at end of file Index: src/com/servoy/plugins/BehaviorProvider.java =================================================================== --- src/com/servoy/plugins/BehaviorProvider.java (revision 54) +++ src/com/servoy/plugins/BehaviorProvider.java (working copy) @@ -9,8 +9,7 @@ package com.servoy.plugins; -import java.util.ArrayList; -import java.util.List; +import java.lang.reflect.Method; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -17,15 +16,13 @@ import org.apache.wicket.Request; import org.apache.wicket.RequestCycle; import org.apache.wicket.ResourceReference; -import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior; import org.apache.wicket.ajax.AjaxRequestTarget; -import org.apache.wicket.markup.html.IHeaderResponse; import org.apache.wicket.protocol.http.servlet.ServletWebRequest; import org.apache.wicket.request.RequestParameters; -import org.apache.wicket.util.string.Strings; import org.mozilla.javascript.Function; import com.servoy.j2db.scripting.FunctionDefinition; +import com.servoy.j2db.server.headlessclient.IPageContributor; import com.servoy.j2db.server.headlessclient.IWebClientPluginAccess; import com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor; import com.servoy.j2db.util.Utils; @@ -36,50 +33,19 @@ * @author Sean Devlin * @author Servoy Stuff */ -public class BehaviorProvider extends AbstractDefaultAjaxBehavior { +public class BehaviorProvider extends ReferencesBehaviorProvider { - private static final long serialVersionUID = 7666601280436256255L; + private static final long serialVersionUID = 7666601280436256256L; - public final static String CALLBACK_BEHAVIOR = "com.servoy.jscallback"; + public final static String BEHAVIOR_ID = "com.servoy.jscallback"; protected Map callbacks = new ConcurrentHashMap(); - - protected final IWebClientPluginAccess app; - - private final List jsReferences = new ArrayList(2); - private final List cssReferences = new ArrayList(2); - + protected boolean showIndicator = true; + public BehaviorProvider(IWebClientPluginAccess app) { - this.app = app; + super(app); } - @Override - public void renderHead(IHeaderResponse response) { - super.renderHead(response); - ResourceReference resourceReference = new ResourceReference("media"); - String solutionName = app.getSolutionName(); - for (Object url : jsReferences) { - if (url instanceof ResourceReference) - { - response.renderJavascriptReference((ResourceReference)url); - } - else { - url = Strings.replaceAll((String)url, "media:///", RequestCycle.get().urlFor(resourceReference) + "?s=" + solutionName + "&id="); - response.renderJavascriptReference(url.toString()); - } - } - for (Object url : cssReferences) { - if (url instanceof ResourceReference) - { - response.renderCSSReference((ResourceReference)url); - } - else { - url = Strings.replaceAll((String)url, "media:///", RequestCycle.get().urlFor(resourceReference) + "?s=" + solutionName + "&id="); - response.renderCSSReference(url.toString()); - } - } - } - protected void respond(final AjaxRequestTarget target){ Request request = RequestCycle.get().getRequest(); final String param = request.getParameter("m"); @@ -114,8 +80,6 @@ } } - private boolean showIndicator = true; - @Override protected String findIndicatorId() { if (showIndicator) @@ -126,7 +90,7 @@ public String getUrlForCallback(Function callback, String[] args, boolean showLoadingIndicator) { // make sure it is added the the current page. - app.getPageContributor().addBehavior(CALLBACK_BEHAVIOR, this); + app.getPageContributor().addBehavior(BEHAVIOR_ID, this); FunctionDefinition fd = addCallBack(callback); @@ -183,41 +147,81 @@ } public void addCssReference(String url) { - app.getPageContributor().addBehavior(CALLBACK_BEHAVIOR, this); - if (url != null && !cssReferences.contains(url)) cssReferences.add(url); + if(!executeGlobalMethod("addGlobalCSSResourceReference", String.class, url)) { + app.getPageContributor().addBehavior(BEHAVIOR_ID, this); + if (url != null) { + Ref r = new Ref(Ref.CSS, url); + if (!references.contains(r)) references.add(r); + } + } } public void addJsReference(String url) { - app.getPageContributor().addBehavior(CALLBACK_BEHAVIOR, this); - if (url != null && !jsReferences.contains(url)) jsReferences.add(url); + if(!executeGlobalMethod("addGlobalJSResourceReference", String.class, url)) { + app.getPageContributor().addBehavior(BEHAVIOR_ID, this); + if (url != null) { + Ref r = new Ref(Ref.JS, url); + if (!references.contains(r)) references.add(r); + } + } } public void addCssReference(ResourceReference url) { - app.getPageContributor().addBehavior(CALLBACK_BEHAVIOR, this); - if (url != null && !cssReferences.contains(url)) cssReferences.add(url); + if(!executeGlobalMethod("addGlobalCSSResourceReference", ResourceReference.class, url)) { + app.getPageContributor().addBehavior(BEHAVIOR_ID, this); + if (url != null) { + Ref r = new Ref(Ref.CSS, url); + if (!references.contains(r)) references.add(r); + } + } } public void addJsReference(ResourceReference url) { - app.getPageContributor().addBehavior(CALLBACK_BEHAVIOR, this); - if (url != null && !jsReferences.contains(url)) jsReferences.add(url); + if(!executeGlobalMethod("addGlobalJSResourceReference", ResourceReference.class, url)) { + app.getPageContributor().addBehavior(BEHAVIOR_ID, this); + if (url != null) { + Ref r = new Ref(Ref.JS, url); + if (!references.contains(r)) references.add(r); + } + } } public void removeCssReference(ResourceReference url) { - cssReferences.remove(url); + if(!executeGlobalMethod("removeGlobalResourceReference", ResourceReference.class, url)) { + if (url != null) references.remove(new Ref(Ref.CSS, url)); + } } public void removeCssReference(String url) { - cssReferences.remove(url); + if(!executeGlobalMethod("removeGlobalResourceReference", String.class, url)) { + if (url != null) references.remove(new Ref(Ref.CSS, url)); + } } public void removeJsReference(ResourceReference url) { - jsReferences.remove(url); + if(!executeGlobalMethod("removeGlobalResourceReference", ResourceReference.class, url)) { + if (url != null) references.remove(new Ref(Ref.JS, url)); + } } public void removeJsReference(String url) { - jsReferences.remove(url); + if(!executeGlobalMethod("removeGlobalResourceReference", String.class, url)) { + if (url != null) references.remove(new Ref(Ref.JS, url)); + } } + private boolean executeGlobalMethod(String methodName, Class parameterType, Object url) { + try { + IPageContributor pageContributor = app.getPageContributor(); + Class clazz = pageContributor.getClass(); + Method m = clazz.getDeclaredMethod(methodName, new Class[]{ parameterType }); + m.invoke(pageContributor, new Object[] { url }); + return true; + } catch (Exception e) { + return false; + } + } + /* public interface ILatestPageBehaviorListener extends IBehaviorListener { Index: src/com/servoy/plugins/WebClientProvider.java =================================================================== --- src/com/servoy/plugins/WebClientProvider.java (revision 54) +++ src/com/servoy/plugins/WebClientProvider.java (working copy) @@ -13,9 +13,12 @@ import org.mozilla.javascript.NativeJavaObject; import org.mozilla.javascript.Scriptable; +import com.servoy.j2db.IForm; import com.servoy.j2db.Messages; import com.servoy.j2db.plugins.IClientPluginAccess; import com.servoy.j2db.server.headlessclient.IWebClientPluginAccess; +import com.servoy.j2db.ui.IComponent; +import com.servoy.j2db.ui.IFormUI; import com.servoy.j2db.ui.IProviderStylePropertyChanges; /** @@ -106,6 +109,32 @@ if (bp != null) bp.addCssReference(url); } + protected Component getFormUIComponent(IForm form) { + if (form != null) { + IFormUI formUI = form.getFormUI(); + return getComponent(formUI); + } + return null; + } + + protected Component getComponent(IComponent element) { + return (element instanceof Component) ? (Component) element : null; + } + + public void addCssReference(String url, Component c) { + if (c != null) { + ReferencesBehaviorProvider bp = getBehavior(c); + if (bp != null) bp.addCssReference(url, c); + } + } + + public void addCssReference(ResourceReference ref, Component c) { + if (c != null) { + ReferencesBehaviorProvider bp = getBehavior(c); + if (bp != null) bp.addCssReference(ref, c); + } + } + public void removeCssReference(ResourceReference url) { BehaviorProvider bp = getBehavior(); if (bp != null) bp.removeCssReference(url); @@ -116,6 +145,34 @@ if (bp != null) bp.removeCssReference(url); } + public void removeCssReference(ResourceReference url, Component c) { + if (c != null) { + ReferencesBehaviorProvider bp = getBehavior(c); + if (bp != null) bp.removeCssReference(url, c); + } + } + + public void removeCssReference(String url, Component c) { + if (c != null) { + ReferencesBehaviorProvider bp = getBehavior(c); + if (bp != null) bp.removeCssReference(url, c); + } + } + + public void addJsReference(String url, Component c) { + if (c != null) { + ReferencesBehaviorProvider bp = getBehavior(c); + if (bp != null) bp.addJsReference(url, c); + } + } + + public void addJsReference(ResourceReference url, Component c) { + if (c != null) { + ReferencesBehaviorProvider bp = getBehavior(c); + if (bp != null) bp.addJsReference(url, c); + } + } + public void addJsReference(String url) { BehaviorProvider bp = getBehavior(); if (bp != null) bp.addJsReference(url); @@ -136,15 +193,28 @@ if (bp != null) bp.removeJsReference(url); } + public void removeJsReference(ResourceReference url, Component c) { + if (c != null) { + ReferencesBehaviorProvider bp = getBehavior(c); + if (bp != null) bp.removeJsReference(url, c); + } + } + public void removeJsReference(String url, Component c) { + if (c != null) { + ReferencesBehaviorProvider bp = getBehavior(c); + if (bp != null) bp.removeJsReference(url, c); + } + } + private BehaviorProvider getBehavior() { if (getApp() != null) { - if (getApp().getPageContributor().getBehavior(BehaviorProvider.CALLBACK_BEHAVIOR) == null) { + if (getApp().getPageContributor().getBehavior(BehaviorProvider.BEHAVIOR_ID) == null) { behavior = new BehaviorProvider(getApp()); } else { - behavior = (BehaviorProvider)getApp().getPageContributor().getBehavior(BehaviorProvider.CALLBACK_BEHAVIOR); + behavior = (BehaviorProvider)getApp().getPageContributor().getBehavior(BehaviorProvider.BEHAVIOR_ID); } return behavior; } @@ -151,6 +221,16 @@ return null; } + private ReferencesBehaviorProvider getBehavior(Component c) { + if (getApp() == null) return null; + + List allBehaviors = c.getBehaviors(); + for (IBehavior behavior : allBehaviors) { + if (behavior instanceof ReferencesBehaviorProvider) return (ReferencesBehaviorProvider) behavior; + } + return new ReferencesBehaviorProvider(getApp()); + } + private JSONBehavior getJSONBehavior() { if (getApp() != null) { if (getApp().getPageContributor().getBehavior(JSONBehavior.CALLBACK_BEHAVIOR) == null) { @@ -195,9 +275,9 @@ } else if ("getElementMarkupId".equals(string)) { return new String[] { "formElement" }; } else if (string.startsWith("remove")) { - return new String[] { ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "stringReference" : "stringOrWebResourceReference") }; + return new String[] { ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "stringReference" : "stringOrWebResourceReference"), "[form/element]" }; } else if (string.startsWith("add")) { - return new String[] { ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "stringReference" : "stringOrWebResourceReference") }; + return new String[] { ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "stringReference" : "stringOrWebResourceReference"), "[form/element]" }; } else if ("isMarkupVisible".equals(string) || "setRendered".equals(string)) { return new String[] { "element" }; } else if ("setMarkupVisible".equals(string)) { @@ -237,17 +317,21 @@ } else if ("getElementMarkupId".equals(method)) { return "var wicketID = %%elementName%%.getElementMarkupId(elements.aField);\n"; } else if ("removeJsReference".equals(method)) { - return "%%elementName%%.removeJsReference('http://yourserver.com/js/yourscript.js');\n" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : - "\t// you can also remove Servoy internal reference scripts (like Yahoo UI widgets):\n\t%%elementName%%.removeJsReference(SERVOY_WEB_RESOURCES.YUI_JS_MENU)"); + 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" + + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : + "\t// you can also remove Servoy internal reference scripts (like Yahoo UI widgets):\n\t%%elementName%%.removeJsReference(SERVOY_WEB_RESOURCES.YUI_JS_MENU)"); } else if ("removeCssReference".equals(method)) { - return "%%elementName%%.removeCssReference('http://yourserver.com/css/yourstyle.css');\n" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : - "\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)"); + 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" + + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : + "\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)"); } else if ("addJsReference".equals(method)) { - return "%%elementName%%.addJsReference('http://yourserver.com/js/yourscript.js');\n" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : - "\t// you can also add Servoy internal reference scripts (like Yahoo UI widgets):\n\t%%elementName%%.addJsReference(SERVOY_WEB_RESOURCES.YUI_JS_MENU)"); + 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" + + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : + "\t// you can also add Servoy internal reference scripts (like Yahoo UI widgets):\n\t%%elementName%%.addJsReference(SERVOY_WEB_RESOURCES.YUI_JS_MENU)"); } else if ("addCssReference".equals(method)) { - return "%%elementName%%.addCssReference('http://yourserver.com/css/yourstyle.css');\n" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : - "\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)"); + 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" + + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : + "\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)"); } else if ("isMarkupVisible".equals(method) || "setMarkupVisible".equals(method)) { return "var visible = %%elementName%%.isMarkupVisible(elements.yourElement);\n\t%%elementName%%.setMarkupVisible(elements.yourElement,!visible);\n"; } else if ("setRendered".equals(method)) { @@ -276,13 +360,13 @@ else if ("getElementMarkupId".equals(method)) return "Returns a Servoy markup Id to be used in your browser scripts"; else if ("removeJsReference".equals(method)) - return "Removes a javascript url" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : " or build in servoy javascript reference (see SERVOY_WEB_RESOURCES)"); + 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)" ); else if ("removeCssReference".equals(method)) - return "Removes a css url" + ((SERVOY_WEB_RESOURCES.YUI_CSS_FONTS == null) ? "" : " or build in servoy css reference (see SERVOY_WEB_RESOURCES)"); + 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)"); else if ("addJsReference".equals(method)) - 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"); + 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).
\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)."); else if ("addCssReference".equals(method)) - 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"); + 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).
\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)."); else if ("isMarkupVisible".equals(method)) return "Returns true if the elements markup is visible in the page"; else if ("setMarkupVisible".equals(method)) @@ -447,6 +531,29 @@ removeCssReference(url); } + protected Component getWicketComponentFromFormOrElement(Object formOrElement) { + Component c = null; + if (formOrElement instanceof IForm) c = getFormUIComponent((IForm) formOrElement); + else if (formOrElement instanceof IComponent) c = getComponent((IComponent) formOrElement); + return c; + } + + public void js_addCssReference(String url, Object formOrElement) { + addCssReference(url, getWicketComponentFromFormOrElement(formOrElement)); + } + + public void js_addCssReference(ResourceReference ref, Object formOrElement) { + addCssReference(ref, getWicketComponentFromFormOrElement(formOrElement)); + } + + public void js_removeCssReference(ResourceReference ref, Object formOrElement) { + removeCssReference(ref, getWicketComponentFromFormOrElement(formOrElement)); + } + + public void js_removeCssReference(String url, Object formOrElement) { + removeCssReference(url, getWicketComponentFromFormOrElement(formOrElement)); + } + public void js_addJsReference(String url) { addJsReference(url); } @@ -463,6 +570,22 @@ removeJsReference(url); } + public void js_addJsReference(String url, Object formOrElement) { + addJsReference(url, getWicketComponentFromFormOrElement(formOrElement)); + } + + public void js_addJsReference(ResourceReference url, Object formOrElement) { + addJsReference(url, getWicketComponentFromFormOrElement(formOrElement)); + } + + public void js_removeJsReference(String url, Object formOrElement) { + removeJsReference(url, getWicketComponentFromFormOrElement(formOrElement)); + } + + public void js_removeJsReference(ResourceReference url, Object formOrElement) { + removeJsReference(url, getWicketComponentFromFormOrElement(formOrElement)); + } + private IWebClientPluginAccess getApp() { IClientPluginAccess app = plugin.getApp(); if (app != null && app instanceof IWebClientPluginAccess) {