]> source.dussan.org Git - vaadin-framework.git/commitdiff
preliminary support for multiple widgetset on a same host page
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 27 Apr 2011 14:20:21 +0000 (14:20 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 27 Apr 2011 14:20:21 +0000 (14:20 +0000)
svn changeset:18507/svn branch:6.6

WebContent/multiwidgetset.html [new file with mode: 0644]
src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java

diff --git a/WebContent/multiwidgetset.html b/WebContent/multiwidgetset.html
new file mode 100644 (file)
index 0000000..1fee38f
--- /dev/null
@@ -0,0 +1,68 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+       style="width:100%;height:100%;border:0;margin:0;">
+<head>
+<title>Multiple embedded applications</title>
+<script type="text/javascript">
+       var vaadin = {
+               debug: true,
+               vaadinConfigurations : {
+                       'fb' : {
+                               appUri : '/sampler',
+                               // sampler only works with sampler widgetset
+                               widgetset : 'com.vaadin.demo.sampler.gwt.SamplerWidgetSet',
+                               themeUri : '/VAADIN/themes/sampler-reindeer',
+                               versionInfo : {
+                                       vaadinVersion : "6.0.0-INTERNAL-NONVERSIONED-DEBUG-BUILD",
+                                       applicationVersion : "NONVERSIONED"
+                               }
+                       },
+                       'calc' : {
+                               appUri : '/Calc',
+                               // no widgetset defined means don't care. Most widgetset have button and gridlayout. 
+                               // First injected widgetset will start this app.
+                               themeUri : '/VAADIN/themes/sampler-reindeer',
+                               versionInfo : {
+                                       vaadinVersion : "6-INTERNAL-NONVERSIONED-DEBUG-BUILD",
+                                       applicationVersion : "NONVERSIONED"
+                               }
+                       },
+                       'colorpicker' : {
+                               appUri : '/colorpicker',
+                               widgetset : 'com.vaadin.demo.colorpicker.gwt.ColorPickerWidgetSet',
+                               themeUri : '/VAADIN/themes/sampler-reindeer',
+                               versionInfo : {
+                                       vaadinVersion : "6.0.0-INTERNAL-NONVERSIONED-DEBUG-BUILD",
+                                       applicationVersion : "NONVERSIONED"
+                               }
+                       }
+               }
+       };
+</script>
+
+<script language='javascript'
+       src='/VAADIN/widgetsets/com.vaadin.terminal.gwt.DefaultWidgetSet/com.vaadin.terminal.gwt.DefaultWidgetSet.nocache.js'></script>
+<script language='javascript'
+       src='/VAADIN/widgetsets/com.vaadin.demo.colorpicker.gwt.ColorPickerWidgetSet/com.vaadin.demo.colorpicker.gwt.ColorPickerWidgetSet.nocache.js'></script>
+<script language='javascript'
+       src='/VAADIN/widgetsets/com.vaadin.demo.sampler.gwt.SamplerWidgetSet/com.vaadin.demo.sampler.gwt.SamplerWidgetSet.nocache.js'></script>
+<link rel="stylesheet" type="text/css"
+       href="/VAADIN/themes/sampler-reindeer/styles.css" />
+</head>
+<body>
+       <iframe id="__gwt_historyFrame"
+               style="width: 0; height: 0; border: 0; overflow: hidden"
+               src="javascript:false"></iframe>
+
+       <p>Experimental test page for multiple apps and multiple widgetsets
+               on the same page. Try with ?debug to see three VConsoles! Test well
+               before using this kind of setup in production. E.g. theme conflicts
+               and other unknown issues may arise. E.g. Glass can get broken in your
+               screen, even in LCD:s. Seriously, to save bandwidth and client side load,
+               it is highly recommended to use the classic shared widgetset approach.</p>
+
+       <div id="fb" style="height: 400px; border: 2px solid red; margin: 0"></div>
+       <div id="calc" style="border: 2px solid green; margin: 0"></div>
+       <div id="colorpicker" style="border: 2px solid blue; margin: 0"></div>
+</body>
+</html>
index 72e8afe8b393325f20cf59d94063f5c973780889..4b6194b79bcf30998c050a69616d2b65fac20a9a 100644 (file)
@@ -48,6 +48,7 @@ public class ApplicationConfiguration implements EntryPoint {
     private String authorizationErrorCaption;
     private String authorizationErrorMessage;
     private String authorizationErrorUrl;
+    private String requiredWidgetset;
     private boolean useDebugIdInDom = true;
     private boolean usePortletURLs = false;
     private String portletUidlURLBase;
@@ -140,6 +141,10 @@ public class ApplicationConfiguration implements EntryPoint {
         return authorizationErrorUrl;
     }
 
+    public String getRequiredWidgetset() {
+        return requiredWidgetset;
+    }
+
     private native void loadFromDOM()
     /*-{
 
@@ -180,6 +185,9 @@ public class ApplicationConfiguration implements EntryPoint {
             if (jsobj.standalone) {
                 this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::standalone = true;
             }
+            if (jsobj.widgetset) {
+                this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::requiredWidgetset = jsobj.widgetset;
+            }
         } else {
             $wnd.alert("Vaadin app failed to initialize: " + this.id);
         }
@@ -202,14 +210,38 @@ public class ApplicationConfiguration implements EntryPoint {
         for (Iterator<String> it = appIds.iterator(); it.hasNext();) {
             String appId = it.next();
             ApplicationConfiguration appConf = getConfigFromDOM(appId);
-            ApplicationConnection a = GWT.create(ApplicationConnection.class);
-            a.init(widgetSet, appConf);
-            unstartedApplications.add(a);
+            if (canStartApplication(appConf)) {
+                ApplicationConnection a = GWT
+                        .create(ApplicationConnection.class);
+                a.init(widgetSet, appConf);
+                unstartedApplications.add(a);
+                consumeApplication(appId);
+            } else {
+                VConsole.log("Application "
+                        + appId
+                        + " was not started. Provided widgetset did not match with this module.");
+            }
         }
 
         deferredWidgetLoadLoop.scheduleRepeating(100);
     }
 
+    /**
+     * Marks an applicatin with given id to be initialized. Suggesting other
+     * modules should not try to start this application anymore.
+     * 
+     * @param appId
+     */
+    private native static void consumeApplication(String appId)
+    /*-{
+         $wnd.vaadin.vaadinConfigurations[appId].initialized = true;
+    }-*/;
+
+    private static boolean canStartApplication(ApplicationConfiguration appConf) {
+        return appConf.getRequiredWidgetset() == null
+                || appConf.getRequiredWidgetset().equals(GWT.getModuleName());
+    }
+
     /**
      * Starts the next unstarted application. The WidgetSet should call this
      * once to start the first application; after that, each application should
@@ -237,7 +269,9 @@ public class ApplicationConfiguration implements EntryPoint {
     /*-{
          var j;
          for(j in $wnd.vaadin.vaadinConfigurations) {
-             list.@java.util.Collection::add(Ljava/lang/Object;)(j);
+             if(!$wnd.vaadin.vaadinConfigurations[j].initialized) {
+                 list.@java.util.Collection::add(Ljava/lang/Object;)(j);
+             }
          }
      }-*/;