package com.itmill.toolkit.terminal.gwt.client;
import java.util.ArrayList;
+import java.util.Iterator;
import com.google.gwt.core.client.JavaScriptObject;
private String appUri;
private JavaScriptObject versionInfo;
+ private static ArrayList unstartedApplications = new ArrayList();
+
public String getRootPanelId() {
return id;
}
}-*/;
- public native static void loadAppIdListFromDOM(ArrayList list)
+ /**
+ * Inits the ApplicationConfiguration by reading the DOM and instantiating
+ * ApplicationConenctions accordingly. Call {@link #startNextApplication()}
+ * to actually start the applications.
+ *
+ * @param widgetset
+ * the widgetset that is running the apps
+ */
+ public static void initConfigurations(WidgetSet widgetset) {
+ ArrayList appIds = new ArrayList();
+ loadAppIdListFromDOM(appIds);
+
+ for (Iterator it = appIds.iterator(); it.hasNext();) {
+ String appId = (String) it.next();
+ ApplicationConfiguration appConf = getConfigFromDOM(appId);
+ ApplicationConnection a = new ApplicationConnection(widgetset,
+ appConf);
+ unstartedApplications.add(a);
+ }
+ }
+
+ /**
+ * 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() {
+ if (unstartedApplications.size() > 0) {
+ ApplicationConnection a = (ApplicationConnection) unstartedApplications
+ .remove(0);
+ a.start();
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private native static void loadAppIdListFromDOM(ArrayList list)
/*-{
var j;
view = new IView(cnf.getRootPanelId());
showLoadingIndicator();
+ }
+
+ /**
+ * Starts this application. Don't call this method directly - it's called by
+ * {@link ApplicationConfiguration#startNextApplication()}, which should be
+ * called once this application has started (first response received) or
+ * failed to start. This ensures that the applications are started in order,
+ * to avoid session-id problems.
+ */
+ void start() {
makeUidlRequest("", true, false);
}
// TODO Better reporting to user
console.error("Got error");
endRequest();
+ if (!applicationRunning) {
+ // start failed, let's try to start the next app
+ configuration.startNextApplication();
+ }
}
public void onResponseReceived(Request request,
} else {
applicationRunning = true;
handleWhenCSSLoaded(response);
+ configuration.startNextApplication();
}
}
}
if (html.length() != 0) {
- INotification n = new INotification(1000 * 60 * 45); // 45min
+ INotification n = new INotification(1000 * 60 * 45); //45min
n.addEventListener(new NotificationRedirect(url));
n.show(html, INotification.CENTERED_TOP,
INotification.STYLE_SYSTEM);
* @param container
*/
public void runDescendentsLayout(HasWidgets container) {
-// getConsole().log(
-// "runDescendentsLayout("
-// + container.getClass().getName().replaceAll(
-// "[^\\.]*\\.", "") + "/" + container.hashCode()
-// + ")");
+ // getConsole().log(
+ // "runDescendentsLayout("
+ // + container.getClass().getName().replaceAll(
+ // "[^\\.]*\\.", "") + "/" + container.hashCode()
+ // + ")");
final Iterator childWidgets = container.iterator();
while (childWidgets.hasNext()) {
final Widget child = (Widget) childWidgets.next();
width *= relativeSize.getWidth() / 100.0;
if (width >= 0) {
-// getConsole().log(
-// "Widget " + widget.getClass().getName() + "/"
-// + widget.hashCode() + " relative width "
-// + relativeSize.getWidth() + "%: " + width
-// + "px");
+ // getConsole().log(
+ // "Widget " + widget.getClass().getName() + "/"
+ // + widget.hashCode() + " relative width "
+ // + relativeSize.getWidth() + "%: " + width
+ // + "px");
widget.setWidth(width + "px");
}
} else {
height *= relativeSize.getHeight() / 100.0;
if (height >= 0) {
-// getConsole().log(
-// "Widget " + widget.getClass().getName() + "/"
-// + widget.hashCode() + " relative height "
-// + relativeSize.getHeight() + "%: " + height
-// + "px");
+ // getConsole().log(
+ // "Widget " + widget.getClass().getName() + "/"
+ // + widget.hashCode() + " relative height "
+ // + relativeSize.getHeight() + "%: " + height
+ // + "px");
widget.setHeight(height + "px");
}
} else {
package com.itmill.toolkit.terminal.gwt.client;
-import java.util.ArrayList;
-import java.util.Iterator;
-
import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.terminal.gwt.client.ui.IAccordion;
import com.itmill.toolkit.terminal.gwt.client.ui.IButton;
public class DefaultWidgetSet implements WidgetSet {
/**
- * This is the entry point method.
+ * This is the entry point method. It will start the first
*/
public void onModuleLoad() {
- ArrayList appIds = new ArrayList();
- ApplicationConfiguration.loadAppIdListFromDOM(appIds);
- for (Iterator iterator = appIds.iterator(); iterator.hasNext();) {
- String appId = (String) iterator.next();
- ApplicationConfiguration appConf = ApplicationConfiguration
- .getConfigFromDOM(appId);
- new ApplicationConnection(this, appConf);
- }
+ ApplicationConfiguration.initConfigurations(this);
+ ApplicationConfiguration.startNextApplication(); // start first app
}
public Paintable createWidget(UIDL uidl) {