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

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

Introduction

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

Prototype

JavaScriptObject TOP_WINDOW

To view the source code for com.google.gwt.core.client ScriptInjector TOP_WINDOW.

Click Source Link

Document

Returns the top level window object.

Usage

From source file:com.google.api.explorer.client.base.http.crossdomain.CrossDomainRequestBuilder.java

License:Apache License

public CrossDomainRequest makeRequest(final ApiRequest request, AsyncCallback<ApiResponse> callback) {
    final CrossDomainRequest xdr = new CrossDomainRequest(callback, timeoutMillis);

    /** Adds a script tag to the page to load the JS library used to make requests. */
    if (!isScriptLoaded()) {
        outstandingRequests.add(new OutstandingRequest(request, xdr));

        // If we are the only request waiting, it is our responsibility to load the library.
        if (outstandingRequests.size() == 1) {
            addLoadCallback(this);
            ScriptInjector.fromUrl(JS_CLIENT_URL).setWindow(ScriptInjector.TOP_WINDOW)
                    .setCallback(new Callback<Void, Exception>() {
                        @Override
                        public void onFailure(Exception e) {
                            throw new RuntimeException(e);
                        }/* w  w  w  . j  a v a 2  s .  co  m*/

                        @Override
                        public void onSuccess(Void arg0) {
                            // Intentionally blank, callback will be invoked automatically
                        }
                    }).inject();
        }
    } else {
        doMakeRequest(request, xdr);
    }
    return xdr;
}

From source file:com.google.gerrit.client.api.PluginLoader.java

License:Apache License

private void load(List<String> pluginUrls) {
    for (String url : pluginUrls) {
        Plugin plugin = Plugin.create(url);
        plugins().put(url, plugin);/*from w  ww .  j a  v  a 2  s .com*/
        ScriptInjector.fromUrl(url).setWindow(ScriptInjector.TOP_WINDOW).setCallback(new LoadCallback(plugin))
                .inject();
    }
}

From source file:com.google.gerrit.client.Gerrit.java

License:Apache License

private void loadPlugins(HostPageData hpd, final String token) {
    if (hpd.plugins != null) {
        for (final String url : hpd.plugins) {
            ScriptInjector.fromUrl(url).setWindow(ScriptInjector.TOP_WINDOW)
                    .setCallback(new Callback<Void, Exception>() {
                        @Override
                        public void onSuccess(Void result) {
                        }//  ww  w  . j ava  2s.  c o  m

                        @Override
                        public void onFailure(Exception reason) {
                            ErrorDialog d = new ErrorDialog(reason);
                            d.setTitle(M.pluginFailed(url));
                            d.center();
                        }
                    }).inject();
        }
    }

    CallbackHandle<Void> cb = new CallbackHandle<Void>(new ResultDeserializer<Void>() {
        @Override
        public Void fromResult(JavaScriptObject responseObject) {
            return null;
        }
    }, new AsyncCallback<Void>() {
        @Override
        public void onFailure(Throwable caught) {
        }

        @Override
        public void onSuccess(Void result) {
            display(token);
        }
    });
    cb.install();
    ScriptInjector.fromString(cb.getFunctionName() + "();").setWindow(ScriptInjector.TOP_WINDOW).inject();
}

From source file:com.himamis.retex.renderer.web.font.opentype.Opentype.java

License:Open Source License

private void loadJavascriptFont(String path, final String familyName) {
    path = path.substring(0, path.length() - 3);
    path = path + "js";

    ScriptInjector.fromUrl(path).setWindow(ScriptInjector.TOP_WINDOW).setRemoveTag(true)
            .setCallback(new Callback<Void, Exception>() {

                public void onFailure(Exception reason) {
                    fireFontInactiveEvent(reason, familyName);
                }/*from   w  w w.  j  a  v a 2s  . com*/

                public void onSuccess(Void result) {
                    nativeParseFont(familyName);
                }
            }).inject();
}

From source file:com.hydro4ge.raphaelgwt.client.Injector.java

License:Apache License

static public void ensureInjected() {
    if (!loaded) {
        loaded = true;/* w  ww . ja  v a2 s .  com*/
        JsResources bundle = GWT.create(JsResources.class);
        JsPicker picker = GWT.create(JsPicker.class);
        ScriptInjector.fromString(picker.pick(bundle).getText()).setWindow(ScriptInjector.TOP_WINDOW).inject();
    }
}

From source file:com.lofidewanto.demo.client.DemoGwtWebApp.java

License:Apache License

private void injectMyFunctionScript() {
    ScriptInjector.fromUrl(MYFUNCTION_URL).setCallback(new Callback<Void, Exception>() {
        @Override/* w w  w  . j a va  2  s  . c  o m*/
        public void onFailure(Exception reason) {
            logger.info("Script load failed Info: " + reason);
        }

        @Override
        public void onSuccess(Void result) {
            logger.info("MyFunction loaded successful!");
        }

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

From source file:com.lofidewanto.demo.client.DemoGwtWebApp.java

License:Apache License

private void injectJqueryScript() {
    // Workaround: https://goo.gl/1OrFqj
    ScriptInjector.fromUrl(JQUERY_UI_URL).setCallback(new Callback<Void, Exception>() {
        @Override// w  w w . j av a  2  s .c  o  m
        public void onFailure(Exception reason) {
            logger.info("Script load failed Info: " + reason);
        }

        @Override
        public void onSuccess(Void result) {
            logger.info("JQuery for Select loaded successful!");

            init();
        }

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

From source file:com.mecatran.otp.gwt.client.PlannerWidgetEntryPoint.java

License:Open Source License

@Override
public void onModuleLoad() {

    /* Check for config */
    config = getConfig();//from   w w  w  .  j av  a 2s.  co  m
    if (config == null) {
        Window.alert("Unable to find JS object widget config 'otpPlannerWidgetConfig' in host page.");
        return;
    }

    /* Check for root panel where we want to insert the widget. */
    RootPanel mapPanel = RootPanel.get(config.getWidgetDivId());
    if (mapPanel == null) {
        Window.alert("Unable to find <div id='" + config.getWidgetDivId() + "'> in host page.");
        return;
    }

    /* Load javascript libraries. */
    ScriptInjector.fromString(PlannerResources.INSTANCE.gwtOpenLayersUtilsJs().getText())
            .setWindow(ScriptInjector.TOP_WINDOW).inject();

    /* Note: must load OSM after OpenLayers */
    ScriptInjector.fromString(PlannerResources.INSTANCE.gwtOpenStreetMapJs().getText())
            .setWindow(ScriptInjector.TOP_WINDOW).inject();
    PlannerResources.INSTANCE.css().ensureInjected();

    mapPanel.clear();

    /* Create a controller and get it's widget onto the root panel */
    PlannerController controller = new PlannerController(getConfig());
    mapPanel.add(controller.getPlannerWidget());

    /* If parameters where provided, try to restore state */
    Map<String, List<String>> parameters = Window.Location.getParameterMap();
    if (parameters.size() > 0) {
        controller.restoreState(new PlannerState(parameters));
    }

    /* Display dialog box if config has set a message. */
    showIntroDialogBox();
}

From source file:com.vaadin.client.ApplicationConfiguration.java

License:Apache License

private boolean vaadinBootstrapLoaded() {
    Element window = ScriptInjector.TOP_WINDOW.cast();
    return window.getPropertyJSO("vaadin") != null;
}

From source file:com.workingflows.js.jquery.client.api.JQuery.java

License:Apache License

@JsOverlay
public static Element window() {
    return ScriptInjector.TOP_WINDOW.<Element>cast();
}