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.wso2.jsplumb.client.injectors.ScriptInjectorHelper.java

License:Open Source License

public static void injectScript() {
    ScriptInjector.fromString(JsClientBundle.INSTANCE.jquerysource().getText())
            .setWindow(ScriptInjector.TOP_WINDOW).inject();
    ScriptInjector.fromString(JsClientBundle.INSTANCE.jqueryuimin().getText())
            .setWindow(ScriptInjector.TOP_WINDOW).inject();
    ScriptInjector.fromString(JsClientBundle.INSTANCE.jsplumbsource().getText())
            .setWindow(ScriptInjector.TOP_WINDOW).inject();
    ScriptInjector.fromString(JsClientBundle.INSTANCE.gwtresource().getText())
            .setWindow(ScriptInjector.TOP_WINDOW).inject();

}

From source file:de.fhrt.codenvy.bpmn.editor.widget.diagram.BpmnEditorDiagramWidget.java

License:Open Source License

private void initDiagramSourceWidget() {
    ScriptInjector.fromString(bpmnResource.codemirrorModeXml().getText()).setWindow(ScriptInjector.TOP_WINDOW)
            .inject();//from  www.  j  a va2 s . c  o  m

    cmWidget = new BpmnEditorSourceWidget("xml", "codenvy");
    cmWidget.setEnabled(false);
}

From source file:de.fhrt.codenvy.bpmn.editor.widget.diagram.BpmnEditorDiagramWidget.java

License:Open Source License

@Override
protected void onAttach() {
    super.onAttach();
    Log.info(BpmnEditorDiagramWidget.class, "onAttach");

    ScriptInjector.fromString(bpmnResource.bpmnIoIndexJsFile().getText()).setWindow(ScriptInjector.TOP_WINDOW)
            .setRemoveTag(false).inject();

    bpmnIoModelerJso = BpmnIoModelerJso.nativeCreateInstance(diagramHtmlWrapperId, this);
}

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");
    }/*from w w w . j a  v a 2s  .c o  m*/

    // 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  w  w  .j a v a  2 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:gwt.material.design.addins.client.MaterialResourceInjector.java

License:Apache License

public static void injectJs(TextResource resource, final boolean removeTag, boolean sourceUrl,
        boolean isScheduleDeferred) {
    final String text = resource.getText() + (sourceUrl ? "//# sourceURL=" + resource.getName() + ".js" : "");

    if (isScheduleDeferred) {
        Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

            @Override/*from w w  w.  java 2 s  .  c om*/
            public void execute() {
                // Inject the script resource
                ScriptInjector.fromString(text).setWindow(ScriptInjector.TOP_WINDOW).setRemoveTag(removeTag)
                        .inject();
            }
        });
    } else {
        ScriptInjector.fromString(text).setWindow(ScriptInjector.TOP_WINDOW).setRemoveTag(removeTag).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.// w  ww  . ja v a  2s . 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:gwt.material.design.client.resources.ResourcesLoader.java

License:Apache License

private void injectJQuery(MaterialResources resources) {
    if (!isjQueryLoaded()) {
        ScriptInjector.fromString(resources.jQuery().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject();
    }/*w w  w .  j  a  v a 2s .  c  om*/
}

From source file:gwt.material.design.client.resources.ResourcesLoader.java

License:Apache License

private void injectMaterializeJs(MaterialResources resources) {
    ScriptInjector.fromString(resources.materializeJs().getText()).setWindow(ScriptInjector.TOP_WINDOW)
            .inject();
}

From source file:gwt.material.design.components.client.GwtMDC.java

License:Apache License

public static void injectJs(TextResource resource, boolean removeTag, boolean sourceUrl) {

    final String text = resource.getText() + (sourceUrl ? "//# sourceURL=" + resource.getName() + ".js" : "");

    // Inject the script resource
    ScriptInjector.fromString(text).setWindow(ScriptInjector.TOP_WINDOW).setRemoveTag(removeTag).inject();

}