Search in sources :

Example 1 with ResourceLoader

use of com.vaadin.client.ResourceLoader in project flow by vaadin.

the class AtmospherePushConnection method runWhenAtmosphereLoaded.

private void runWhenAtmosphereLoaded(final Command command) {
    if (isAtmosphereLoaded()) {
        command.execute();
    } else {
        final String pushJs = getVersionedPushJs();
        Console.log("Loading " + pushJs);
        ResourceLoader loader = registry.getResourceLoader();
        String pushScriptUrl = registry.getApplicationConfiguration().getContextRootUrl() + pushJs;
        ResourceLoadListener loadListener = new ResourceLoadListener() {

            @Override
            public void onLoad(ResourceLoadEvent event) {
                if (isAtmosphereLoaded()) {
                    Console.log(pushJs + " loaded");
                    command.execute();
                } else {
                    // If bootstrap tried to load
                    // vaadinPush.js, ResourceLoader assumes it succeeded
                    // even if it failed (#11673)
                    onError(event);
                }
            }

            @Override
            public void onError(ResourceLoadEvent event) {
                getConnectionStateHandler().pushScriptLoadError(event.getResourceUrl());
            }
        };
        loader.loadScript(pushScriptUrl, loadListener);
    }
}
Also used : ResourceLoader(com.vaadin.client.ResourceLoader) ResourceLoadEvent(com.vaadin.client.ResourceLoader.ResourceLoadEvent) ResourceLoadListener(com.vaadin.client.ResourceLoader.ResourceLoadListener)

Example 2 with ResourceLoader

use of com.vaadin.client.ResourceLoader in project flow by vaadin.

the class GwtDomApiTest method gwtSetUp.

@Override
protected void gwtSetUp() throws Exception {
    super.gwtSetUp();
    registry = new Registry() {

        {
            UILifecycle uiLifecycle = new UILifecycle();
            uiLifecycle.setState(UIState.RUNNING);
            set(UILifecycle.class, uiLifecycle);
            set(RequestResponseTracker.class, new RequestResponseTracker(this));
            set(MessageHandler.class, new MessageHandler(this));
            set(ServerRpcQueue.class, new ServerRpcQueue(this));
            set(DependencyLoader.class, new DependencyLoader(this));
            set(ResourceLoader.class, new ResourceLoader(this, false));
        }
    };
    registry.getRequestResponseTracker().startRequest();
}
Also used : ResourceLoader(com.vaadin.client.ResourceLoader) MessageHandler(com.vaadin.client.communication.MessageHandler) ServerRpcQueue(com.vaadin.client.communication.ServerRpcQueue) DependencyLoader(com.vaadin.client.DependencyLoader) Registry(com.vaadin.client.Registry) UILifecycle(com.vaadin.client.UILifecycle) RequestResponseTracker(com.vaadin.client.communication.RequestResponseTracker)

Aggregations

ResourceLoader (com.vaadin.client.ResourceLoader)2 DependencyLoader (com.vaadin.client.DependencyLoader)1 Registry (com.vaadin.client.Registry)1 ResourceLoadEvent (com.vaadin.client.ResourceLoader.ResourceLoadEvent)1 ResourceLoadListener (com.vaadin.client.ResourceLoader.ResourceLoadListener)1 UILifecycle (com.vaadin.client.UILifecycle)1 MessageHandler (com.vaadin.client.communication.MessageHandler)1 RequestResponseTracker (com.vaadin.client.communication.RequestResponseTracker)1 ServerRpcQueue (com.vaadin.client.communication.ServerRpcQueue)1