List of usage examples for com.google.gwt.core.client ScriptInjector fromUrl
public static FromUrl fromUrl(String scriptUrl)
From source file:fi.jasoft.remoteconnection.client.ClientRemoteConnection.java
License:Apache License
@Override public void connect() { if (peer != null) { throw new IllegalStateException("Already connected, call terminate() before connecting again"); }/* w w w. jav a 2 s . com*/ // Inject the script if needed if (!scriptLoaded && !scriptFailedToLoad && !isPeerAvailable()) { ScriptInjector.fromUrl(PEER_JS_URL).setWindow(ScriptInjector.TOP_WINDOW) .setCallback(new Callback<Void, Exception>() { @Override public void onSuccess(Void result) { getLogger().info("Loaded peer.js successfully"); scriptLoaded = true; if (isPeerAvailable()) { connect(); } else { getLogger().severe("Peer is not available in DOM after loading script. Aborting."); scriptFailedToLoad = true; } } @Override public void onFailure(Exception reason) { scriptFailedToLoad = true; getLogger().severe("Failed to load Peer.js from " + PEER_JS_URL); } }).inject(); return; } if (configuration.getKey().equals(RemoteConnectionConfiguration.DEVELOPMENT_PEER_JS_KEY)) { getLogger().warning("You are using the development key of RemoteConnection " + "with a very limited amount of connections shared among all " + "RemoteConnection users. You are strongly encoraged to apply " + "for your own developer key at http://peerjs.com/peerserver or " + "run your own server which can be downloaded from https://github.com/peers/peerjs-server. " + "You can supply your own peer server details through the RemoteConnection.getConfiguration() " + "option. Thank you."); } if (!isPeerAvailable()) { throw new IllegalStateException("Peer library is missing from DOM. Cannot connect."); } if (!scriptLoaded) { throw new IllegalStateException("Peer script is not loaded. Cannot connect."); } // Create peer try { peer = Peer.create(configuration.getId(), getOptionsFromConfiguration(configuration)); } catch (Exception e) { throw new RuntimeException("Could not create peer connection.", e); } // Register with signaling server peer.addListener("open", new StringPeerListener() { @Override public void execute(String peerId) { connectionTimeoutTimer.cancel(); onOpen(peerId); } }); // Triggered when another remote connection is established peer.addListener("connection", new ObjectPeerListener() { @Override public void execute(JavaScriptObject obj) { onConnection((DataConnection) obj); } }); // Triggered when an error occurs peer.addListener("error", new ObjectPeerListener() { @Override public void execute(JavaScriptObject obj) { connectionTimeoutTimer.cancel(); onError((PeerError) obj); } }); // Triggered when the connection is closed peer.addListener("close", new PeerListener() { @Override public void execute() { onClose(); } }); // Listen for timeout connectionTimeoutTimer.schedule(10000); }
From source file:fr.emmenemoi.gwt.widgets.jwplayer.client.JWPlayer.java
public JWPlayer(JWPlayerOptions options) { this.options = options; // if first player: add JWPlayer source if (count == 0 && !scriptLoaded) { ScriptInjector.fromUrl(this.getCloudSrc()).setCallback(new Callback<Void, Exception>() { public void onFailure(Exception reason) { Window.alert("JWPlayer Cloudhosted script load failed."); }/*from w ww. j a v a2 s . c o m*/ public void onSuccess(Void result) { JWPlayer.scriptLoaded = true; JWPlayer.initPlayers(); } }).setWindow(ScriptInjector.TOP_WINDOW).inject(); } playerId = idPrefix + count; playerDivId = divPrefix + count; ++count; Element element = DOM.createElement("div"); //DOM.setElementProperty(element, "id", playerDivId); element.setAttribute("id", playerDivId); // add new div which will be replaced by SWFObject setElement(element); }
From source file:fr.insalyon.creatis.vip.core.client.view.auth.SignInTab.java
License:Open Source License
private void injectScript(final String url) { ScriptInjector.fromUrl(url).setCallback(new Callback() { public void onFailure(Object reason) { Window.alert("Script load failed: " + url); }/*from ww w . j a v a 2s . c o m*/ public void onSuccess(Object result) { } }).inject(); }
From source file:fr.mncc.gwttoolbox.router.client.Router.java
License:Open Source License
private void setupAnalytics() { ScriptInjector.fromUrl(("https:".equals(Window.Location.getProtocol()) ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js").inject(); }
From source file:gwt.material.design.client.api.ApiRegistry.java
License:Apache License
/** * Will register the {@link ApiFeature} to the list of features providing also the Javascript Script element object * for later removal / update.//from w w w . j av a 2 s. c o m */ public static void register(ApiFeature apiFeature, Callback<Void, Exception> callback) { if (apiFeature != null && apiFeature.getApiKey() != null && !apiFeature.getApiKey().isEmpty()) { JavaScriptObject scriptObject = ScriptInjector.fromUrl(apiFeature.constructApiUrl()) .setWindow(ScriptInjector.TOP_WINDOW).setCallback(new Callback<Void, Exception>() { @Override public void onFailure(Exception e) { callback.onFailure(e); } @Override public void onSuccess(Void aVoid) { callback.onSuccess(aVoid); } }).inject(); features.put(apiFeature, scriptObject); } }
From source file:ilarkesto.gwt.client.integration.ace.AceEditor.java
License:Open Source License
private void activate() { if (loaded) { new Timer() { @Override/* www. ja va 2 s. c o m*/ public void run() { activateAce(div.getElement()); } }.schedule(2000); return; } ScriptInjector.fromUrl("js/ace/ace.js").setCallback(new Callback<Void, Exception>() { @Override public void onFailure(Exception ex) { throw new RuntimeException("Loading ACE failed.", ex); } @Override public void onSuccess(Void result) { loaded = true; activate(); } }).inject(); }
From source file:io.pelle.mango.client.web.MangoClientWeb.java
License:Open Source License
/** {@inheritDoc} */ @Override/*from ww w . j a va 2 s . c o m*/ public void onModuleLoad() { instance = this; String dictionaryScriptUrl = com.google.gwt.core.client.GWT.getModuleBaseURL() + "../remote/systemservice/getdictionaryi18nscript?variableName=dictionary"; ScriptInjector.fromUrl(dictionaryScriptUrl).setCallback(new Callback<Void, Exception>() { public void onFailure(Exception reason) { GWT.log("failed to load dictionary translations from ."); } public void onSuccess(Void result) { Dictionary dictionary = Dictionary.getDictionary("dictionary"); if (mangoProvider instanceof MangoGwtImplProvider) { ((MangoGwtImplProvider) mangoProvider).setDictionary(dictionary); } } }).setRemoveTag(false).setWindow(ScriptInjector.TOP_WINDOW).inject(); init(); }
From source file:mx.org.pescadormvp.core.client.components.GlobalSetup.java
private static void launchScriptInjector(final String url) { ScriptInjector.fromUrl(url).setWindow(ScriptInjector.TOP_WINDOW) .setCallback(new Callback<Void, Exception>() { public void onFailure(Exception reason) { pendingLogs.add(new PendingLog(Level.SEVERE, "Failed to load JS " + url)); scriptsFailedToLoad.add(url); scriptInjectReturned(); }// w ww . j ava 2 s. co m public void onSuccess(Void result) { pendingLogs.add(new PendingLog(Level.INFO, "Successfully loaded JS " + url)); scriptsLoaded.add(url); scriptInjectReturned(); } }).inject(); }
From source file:net.codemirror.lib.Loader.java
License:Apache License
static void injectScript(SafeUri js, final AsyncCallback<Void> callback) { final ScriptElement[] script = new ScriptElement[1]; script[0] = ScriptInjector.fromUrl(js.asString()).setWindow(ScriptInjector.TOP_WINDOW) .setCallback(new Callback<Void, Exception>() { @Override/*from w w w. ja v a2 s. c o m*/ public void onSuccess(Void result) { script[0].removeFromParent(); callback.onSuccess(result); } @Override public void onFailure(Exception reason) { error(reason); callback.onFailure(reason); } }).inject().cast(); }
From source file:org.cruxframework.crux.plugin.cordova.client.Cordova.java
License:Apache License
private static void injectCordovaScript() { ScriptInjector.fromUrl("cordova.js").setWindow(ScriptInjector.TOP_WINDOW).inject(); }