diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-06-20 14:36:21 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-06-20 14:36:29 +0300 |
commit | f505d99754fa0139fbbe1b52236ad622c8c3246d (patch) | |
tree | ef1a33af9503b202045c60c6fdb1f8a738595aba /src/com/vaadin/ui/JavaScript.java | |
parent | 29d592938cabec07c72e007008d019136fbe5f4f (diff) | |
download | vaadin-framework-f505d99754fa0139fbbe1b52236ad622c8c3246d.tar.gz vaadin-framework-f505d99754fa0139fbbe1b52236ad622c8c3246d.zip |
Javadocs and minor tweaks for extensions, JavaScript and js wrappers
Diffstat (limited to 'src/com/vaadin/ui/JavaScript.java')
-rw-r--r-- | src/com/vaadin/ui/JavaScript.java | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/com/vaadin/ui/JavaScript.java b/src/com/vaadin/ui/JavaScript.java index 241d477506..d256717711 100644 --- a/src/com/vaadin/ui/JavaScript.java +++ b/src/com/vaadin/ui/JavaScript.java @@ -15,6 +15,16 @@ import com.vaadin.terminal.gwt.client.communication.ServerRpc; import com.vaadin.terminal.gwt.client.extensions.javascriptmanager.ExecuteJavaScriptRpc; import com.vaadin.terminal.gwt.client.extensions.javascriptmanager.JavaScriptManagerState; +/** + * Provides access to JavaScript functionality in the web browser. To get an + * instance of JavaScript, either use Page.getJavaScript() or + * JavaScript.getCurrent() as a shorthand for getting the JavaScript object + * corresponding to the current Page. + * + * @author Vaadin Ltd + * @version @VERSION@ + * @since 7.0.0 + */ public class JavaScript extends AbstractExtension { private Map<String, JavaScriptCallback> callbacks = new HashMap<String, JavaScriptCallback>(); @@ -24,6 +34,11 @@ public class JavaScript extends AbstractExtension { public void call(String name, JSONArray arguments); } + /** + * Creates a new JavaScript object. You should typically not this, but + * instead use the JavaScript object already associated with your Page + * object. + */ public JavaScript() { registerRpc(new JavaScriptCallbackRpc() { public void call(String name, JSONArray arguments) { @@ -43,6 +58,27 @@ public class JavaScript extends AbstractExtension { return (JavaScriptManagerState) super.getState(); } + /** + * Add a new function to the global JavaScript namespace (i.e. the window + * object). The <code>call</code> method in the passed + * {@link JavaScriptCallback} object will be invoked with the same + * parameters whenever the JavaScript function is called in the browser. + * + * A callback added with the name <code>"myCallback"</code> can thus be + * invoked with the following JavaScript code: + * <code>window.myCallback(argument1, argument2)</code>. + * + * If the name parameter contains dots, simple objects are created on demand + * to allow calling the function using the same name (e.g. + * <code>window.myObject.myFunction</code>). + * + * @param name + * the name that the callback function should get in the global + * JavaScript namespace. + * @param callback + * the JavaScriptCallback that will be invoked if the JavaScript + * function is called. + */ public void addCallback(String name, JavaScriptCallback callback) { callbacks.put(name, callback); if (getState().getNames().add(name)) { @@ -50,6 +86,17 @@ public class JavaScript extends AbstractExtension { } } + /** + * Removes a JavaScripCallback from the browser's global JavaScript + * namespace. + * + * If the name contains dots and intermediate were created by + * {@link #addCallback(String, JavaScriptCallback)}addCallback, these + * objects will not be removed when the callback is removed. + * + * @param name + * the name of the callback to remove + */ public void removeCallback(String name) { callbacks.remove(name); if (getState().getNames().remove(name)) { @@ -57,10 +104,25 @@ public class JavaScript extends AbstractExtension { } } + /** + * Executes the given JavaScript code in the browser. + * + * @param script + * The JavaScript code to run. + */ public void execute(String script) { getRpcProxy(ExecuteJavaScriptRpc.class).executeJavaScript(script); } + /** + * Get the JavaScript object for the current Page, or null if there is no + * current page. + * + * @see Page#getCurrent() + * + * @return the JavaScript object corresponding to the current Page, or + * <code>null</code> if there is no current page. + */ public static JavaScript getCurrent() { Page page = Page.getCurrent(); if (page == null) { @@ -69,4 +131,16 @@ public class JavaScript extends AbstractExtension { return page.getJavaScript(); } + /** + * JavaScript is not designed to be removed. + * + * @throws UnsupportedOperationException + * when invoked + */ + @Override + public void removeFromTarget() { + throw new UnsupportedOperationException( + "JavaScript is not designed to be removed."); + } + } |