Example usage for com.google.gwt.core.client ScriptInjector fromUrl

List of usage examples for com.google.gwt.core.client ScriptInjector fromUrl

Introduction

In this page you can find the example usage for com.google.gwt.core.client ScriptInjector fromUrl.

Prototype

public static FromUrl fromUrl(String scriptUrl) 

Source Link

Document

Build an injection call for adding a script by URL.

Usage

From source file:org.eclipse.kura.web.client.denali.java

License:Open Source License

/**
 * This is the 'real' entry point method.
 *///from  w  w w. j a  v  a2  s .c  om
public void onModuleLoad2() {

    // set the default theme
    GXT.setDefaultTheme(Theme.GRAY, true);

    // load custom CSS/JS
    loadCss("denali/skin/skin.css");
    ScriptInjector.fromUrl("skin/skin.js?v=1").inject(); // Make sure this request is not cached

    gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {
        @Override
        public void onFailure(Throwable ex) {
            FailureHandler.handle(ex);
        }

        @Override
        public void onSuccess(GwtXSRFToken token) {
            gwtDeviceService.findSystemProperties(token, new AsyncCallback<ListLoadResult<GwtGroupedNVPair>>() {
                public void onSuccess(ListLoadResult<GwtGroupedNVPair> results) {

                    final GwtSession gwtSession = new GwtSession();

                    if (results != null) {
                        List<GwtGroupedNVPair> pairs = results.getData();
                        if (pairs != null) {
                            for (GwtGroupedNVPair pair : pairs) {
                                String name = pair.getName();
                                if (name != null && name.equals("kura.have.net.admin")) {
                                    Boolean value = Boolean.valueOf(pair.getValue());
                                    gwtSession.setNetAdminAvailable(value);
                                }
                                if (name != null && name.equals("kura.version")) {
                                    gwtSession.setKuraVersion(pair.getValue());
                                }
                                if (name != null && name.equals("kura.os.version")) {
                                    gwtSession.setOsVersion(pair.getValue());
                                }
                            }
                        }
                    }

                    gwtSecurityService.isDebugMode(new AsyncCallback<Boolean>() {

                        public void onFailure(Throwable caught) {
                            Info.display("Bad", "Is debug mode error");
                            render(gwtSession);
                        }

                        public void onSuccess(Boolean result) {
                            if (result) {
                                isDevelopMode = true;
                            }
                            render(gwtSession);
                        }
                    });
                }

                public void onFailure(Throwable caught) {
                    FailureHandler.handle(caught);
                    render(new GwtSession());
                }
            });
        }
    });
}

From source file:org.gwt.dynamic.common.client.module.AbstractModule.java

License:MIT License

@Override
public final void onModuleLoad() {
    LOG.info("AbstractModule.onModuleLoad: moduleName=" + GWT.getModuleName());
    ScriptInjector.fromUrl(GWT.getModuleBaseURL() + "config.js").setRemoveTag(true)
            .setWindow(ScriptInjector.TOP_WINDOW).setCallback(new Callback<Void, Exception>() {

                @Override/*  w  w w .  j  ava2  s .c o m*/
                public void onSuccess(Void result) {
                    LOG.info("AbstractModule.onModuleLoad#fromUrl#onSuccess");
                    onModuleConfigured();
                }

                @Override
                public void onFailure(Exception reason) {
                    LOG.log(Level.SEVERE, "AbstractModule.onModuleLoad#fromUrl#onFailure:", reason);
                }
            }).inject();
}

From source file:org.gwt.dynamic.host.client.module.ScriptInjectorModuleLoader.java

License:MIT License

@Override
public void load(List<ModuleBean> modules) {
    LOG.info("ScriptInjectorModuleLoader.load: modules=" + modules);
    if (isEmpty(modules))
        return;//ww w.  j a v  a 2s .co m
    for (ModuleBean module : modules) {
        String url = module.getUrl();
        if (!isEmpty(url) && !url.endsWith("/"))
            url += "/";
        ScriptInjector.fromUrl(url + module.getName() + "/" + module.getName() + ".nocache.js")
                .setRemoveTag(true).setWindow(ScriptInjector.TOP_WINDOW).inject();
    }
}

From source file:org.jbpm.workbench.cm.client.CaseManagementEntryPoint.java

License:Apache License

@AfterInitialization
public void init() {
    PatternFlyBootstrapper.ensurejQueryIsAvailable();
    ScriptInjector.fromUrl(GWT.getModuleBaseURL() + "js/bootstrap-select.min.js")
            .setWindow(ScriptInjector.TOP_WINDOW).inject();
}

From source file:org.ol3cesium.client.ol.OLInitializer.java

License:Apache License

public void initialize() {
    final String url = _path + _name;

    ScriptInjector.fromUrl(url).setWindow(getWindow(_document)).setCallback(new Callback<Void, Exception>() {
        @Override//from  w  w  w  .  j ava  2  s .c  o  m
        public void onFailure(Exception reason) {
            for (Callback<Void, Exception> callback : _callbacks) {
                callback.onFailure(reason);
            }
        }

        @Override
        public void onSuccess(Void result) {
            createSetter(_document);

            String script;
            if (olcsDefined()) {
                script = "document.setGlobalInGWT(ol, olcs);";
            } else {
                script = "document.setGlobalInGWT(ol, undefined);";
            }
            ScriptInjector.fromString(script).setWindow(getWindow(_document)).inject();
        }
    }).inject();
}

From source file:org.ow2.proactive_grid_cloud_portal.common.client.JSUtil.java

License:Open Source License

private static void injectScriptOneAfterAnother(final List<String> pathAsList) {
    ScriptInjector.fromUrl(pathAsList.remove(0)).setWindow(ScriptInjector.TOP_WINDOW)
            .setCallback(new Callback<Void, Exception>() {
                @Override//from   w  w w . j a  v a 2 s .  co m
                public void onFailure(Exception reason) {
                }

                @Override
                public void onSuccess(Void result) {
                    if (!pathAsList.isEmpty()) {
                        injectScriptOneAfterAnother(pathAsList);
                    }
                }
            }).inject();
}

From source file:org.primordion.xholon.io.gwt.HtmlScriptHelper.java

License:Open Source License

/**
 * Inject a script into the app.//w ww  .j  a  v a2  s  .  c om
 * @param scriptBody 
 * @param removeTag Whether or not to remove the HTML tag after the script is run.
 *        GWT default is true
 * @return 
 */
public static JavaScriptObject fromUrl(String scriptUrl, boolean removeTag) {
    JavaScriptObject jso = ScriptInjector.fromUrl(scriptUrl).setWindow(ScriptInjector.TOP_WINDOW)
            .setRemoveTag(removeTag).inject();
    consoleLog(jso);
    return jso;
}

From source file:org.primordion.xholon.io.gwt.HtmlScriptHelper.java

License:Open Source License

/**
 * USE require.js INSTEAD./* w  w  w  . ja v a 2 s  . c  om*/
 * This method should only be used for very simple cases,
 * where only one script is being loaded.
 * Make a required script available.
 * Load it into a script element in html head, if it's not already loaded.
 * Do nothing if it's already loaded.
 * TYpically, this is invoked from the user's postConfigure() code.
 * @param scriptName The name of the script file (ex: 'd3.v2.min.js').
 * @param scriptPath The path to the script (ex: 'http://www.primordion.com/Xholon/webEdition/lib/').
 *   If null or missing, then a default path is assumed.
 */
public static void requireScript(String scriptName, String scriptPath) {
    if ((scriptName == null) || (scriptName.length() == 0)) {
        return;
    }
    if (!scriptName.endsWith(".js")) {
        scriptName = scriptName + ".js";
    }
    if ((scriptPath == null) || (scriptPath.length() == 0)) {
        scriptPath = DEFAULT_REQUIRE_PATH;
    } else if (!(scriptPath.startsWith("http://")) && !(scriptPath.startsWith("https://"))) {
        // this may be a malicious URI, perhaps starting with "javascript:"
        return;
    }
    if ("http://127.0.0.1:9876/xholon/lib/".equals(scriptPath)) {
        // for use with devmode
        scriptPath = "http://127.0.0.1:8888/xholon/lib/";
    }
    if (!isLoaded(scriptName)) {
        final JavaScriptObject jso = ScriptInjector.fromUrl(scriptPath + scriptName)
                .setWindow(ScriptInjector.TOP_WINDOW).setRemoveTag(false)
                .setCallback(new Callback<Void, Exception>() {
                    public void onSuccess(Void result) {
                        consoleLog("Script load success.");
                    }

                    public void onFailure(Exception reason) {
                        consoleLog("Script load failed.");
                        // TODO if it's a 404 or other error where the script can't be loaded, delete the script tag
                        // the following code won't compile "error: variable jso might not have been initialized"
                        /*if (jso != null) {
                          Node scriptNode = (Node)jso.cast();
                          consoleLog(scriptNode);
                          scriptNode.removeFromParent();
                        }*/
                    }
                }).inject();
        consoleLog(jso); // nodeName/tagName="SCRIPT" localName="script"
    }
}

From source file:org.rstudio.studio.client.workbench.views.source.editors.text.ChunkDataWidget.java

License:Open Source License

public static void injectPagedTableResources() {
    injectStyleElement("rmd_data/pagedtable.css", "pagedtable-css");
    ScriptInjector.fromUrl("rmd_data/pagedtable.js").inject();
}

From source file:org.swellrt.web.wave.atmosphere.WaveSocketAtmosphere.java

License:Apache License

@Override
public void connect() {

    if (socket == null) {

        // Build the atmosphere.js URL using the Websocket URL
        final String scriptHost = urlBase.startsWith("wss://") ? "https://" + urlBase.substring(6)
                : "http://" + urlBase.substring(5);

        String scriptUrl = new String(scriptHost);

        // Remove trailing '/' before add context
        if (scriptUrl.lastIndexOf("/") == scriptUrl.length() - 1)
            scriptUrl = scriptUrl.substring(0, scriptUrl.length() - 1);

        scriptUrl += "/atmosphere/atmosphere.js";

        ScriptInjector.fromUrl(scriptUrl).setCallback(new Callback<Void, Exception>() {
            public void onFailure(Exception reason) {
                throw new IllegalStateException("atmosphere.js load failed!");
            }/*from   w  ww. j a va 2 s. co m*/

            public void onSuccess(Void result) {
                // We assume Atmosphere is going to work only with http(s) schemas
                socket = AtmosphereSocket.create(WaveSocketAtmosphere.this, scriptHost,
                        true ? "websocket" : "long-polling", "long-polling", clientVersion, sessionId);
                socket.connect();
            }

        }).setWindow(ScriptInjector.TOP_WINDOW).inject();

    } else {
        socket.connect();
    }
}