From cb5f080e5337c081f22eea86c0cf170ef88a2257 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Mon, 28 Nov 2011 12:59:34 +0200 Subject: [PATCH] Rework bootstrap to support loading widgetset without application --- WebContent/VAADIN/vaadinBootstrap.js | 33 ++++++------ .../gwt/client/ApplicationConfiguration.java | 50 ++++++++----------- .../gwt/client/ApplicationConnection.java | 5 -- 3 files changed, 40 insertions(+), 48 deletions(-) diff --git a/WebContent/VAADIN/vaadinBootstrap.js b/WebContent/VAADIN/vaadinBootstrap.js index 2178e2abe2..cc9829b6e4 100644 --- a/WebContent/VAADIN/vaadinBootstrap.js +++ b/WebContent/VAADIN/vaadinBootstrap.js @@ -2,8 +2,7 @@ var defaults; var apps = {}; var themesLoaded = {}; - var widgetsetsRequested = {} - var widgetsetApps = {}; + var widgetsets = {}; var log = function() { @@ -30,8 +29,7 @@ } var loadWidgetset = function(basePath, widgetset) { - if (widgetsetsRequested[widgetset]) { - //TODO Tell the widgetset to load another application + if (widgetsets[widgetset]) { return; } log("load widgetset", basePath, widgetset) @@ -48,7 +46,9 @@ scriptTag.setAttribute('src', url); document.getElementsByTagName('head')[0].appendChild(scriptTag); - widgetsetsRequested[widgetset] = true; + widgetsets[widgetset] = { + pendingApps: [] + }; } window.vaadin = window.vaadin || { @@ -127,15 +127,17 @@ var widgetset = getConfig('widgetset'); if (widgetset && widgetsetBase) { loadWidgetset(widgetsetBase, widgetset); - if (widgetsetApps[widgetset]) { - widgetsetApps[widgetset].push(appId); + if (widgetsets[widgetset].callback) { + log("Starting from bootstrap", appId); + widgetsets[widgetset].callback(appId); } else { - widgetsetApps[widgetset] = [appId]; + log("Setting pending startup of ", appId); + widgetsets[widgetset].pendingApps.push(appId); } } else if (mayDefer) { fetchRootConfig(); } else { - throw "Widgetset not defined"; + throw "Widgetset not defined: " + widgetsetBase + " -> " + widgetset; } } bootstrapApp(true); @@ -151,12 +153,15 @@ var app = apps[appId]; return app; }, - popWidgetsetApp: function(widgetset) { - if (widgetsetApps[widgetset]) { - return widgetsetApps[widgetset].pop(); - } else { - return null; + registerWidgetset: function(widgetset, callback) { + log("Widgetset registered", widgetset) + widgetsets[widgetset].callback = callback; + for(var i = 0; i < widgetsets[widgetset].pendingApps.length; i++) { + var appId = widgetsets[widgetset].pendingApps[i]; + log("Starting from register widgetset", appId); + callback(appId); } + widgetsets[widgetset].pendingApps = null; } }; diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java b/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java index 854deb6e84..75866ce646 100644 --- a/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java +++ b/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java @@ -13,6 +13,8 @@ import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT.UncaughtExceptionHandler; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArrayString; +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Timer; import com.vaadin.terminal.gwt.client.ui.VUnknownComponent; @@ -217,40 +219,23 @@ public class ApplicationConfiguration implements EntryPoint { } - /** - * Starts the next unstarted application. The WidgetSet should call this - * once to start the first application; after that, each application should - * call this once it has started. This ensures that the applications are - * started synchronously, which is neccessary to avoid session-id problems. - * - * @return true if an unstarted application was found - */ - public static boolean startNextApplication() { - String applicationId = getNextUnstartedApplicationId(GWT - .getModuleName()); - if (applicationId != null) { - ApplicationConfiguration appConf = getConfigFromDOM(applicationId); - ApplicationConnection a = GWT.create(ApplicationConnection.class); - a.init(widgetSet, appConf); - a.start(); - runningApplications.add(a); - return true; - } else { - deferredWidgetLoader = new DeferredWidgetLoader(); - return false; - } + public static void startApplication(final String applicationId) { + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + public void execute() { + ApplicationConfiguration appConf = getConfigFromDOM(applicationId); + ApplicationConnection a = GWT + .create(ApplicationConnection.class); + a.init(widgetSet, appConf); + a.start(); + runningApplications.add(a); + } + }); } public static List getRunningApplications() { return runningApplications; } - private native static String getNextUnstartedApplicationId( - String widgetsetName) - /*-{ - return $wnd.vaadin.popWidgetsetApp(widgetsetName); - }-*/; - private native static JsoConfiguration getJsoConfiguration(String appId) /*-{ return $wnd.vaadin.getApp(appId); @@ -447,9 +432,16 @@ public class ApplicationConfiguration implements EntryPoint { } }); - startNextApplication(); + registerCallback(GWT.getModuleName()); + deferredWidgetLoader = new DeferredWidgetLoader(); } + public native static void registerCallback(String widgetsetName) + /*-{ + var callbackHandler = @com.vaadin.terminal.gwt.client.ApplicationConfiguration::startApplication(Ljava/lang/String;); + $wnd.vaadin.registerWidgetset(widgetsetName, callbackHandler); + }-*/; + /** * Checks if client side is in debug mode. Practically this is invoked by * adding ?debug parameter to URI. diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java index 8f745bba80..09b3c075df 100644 --- a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java +++ b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java @@ -459,10 +459,6 @@ public class ApplicationConnection { public void onError(Request request, Throwable exception) { showCommunicationError(exception.getMessage()); endRequest(); - if (!applicationRunning) { - // start failed, let's try to start the next app - ApplicationConfiguration.startNextApplication(); - } } public void onResponseReceived(Request request, @@ -535,7 +531,6 @@ public class ApplicationConnection { } else { applicationRunning = true; handleWhenCSSLoaded(jsonText, json); - ApplicationConfiguration.startNextApplication(); } } -- 2.39.5