Browse Source

Rework bootstrap to support loading widgetset without application

tags/7.0.0.alpha1
Leif Åstrand 12 years ago
parent
commit
cb5f080e53

+ 19
- 14
WebContent/VAADIN/vaadinBootstrap.js View File

@@ -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;
}
};

+ 21
- 29
src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java View File

@@ -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<ApplicationConnection> 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.

+ 0
- 5
src/com/vaadin/terminal/gwt/client/ApplicationConnection.java View File

@@ -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();
}
}


Loading…
Cancel
Save