From seam-commits at lists.jboss.org Mon Jun 15 23:45:13 2009 Content-Type: multipart/mixed; boundary="===============7349262106975427495==" MIME-Version: 1.0 From: seam-commits at lists.jboss.org To: seam-commits at lists.jboss.org Subject: [seam-commits] Seam SVN: r11161 - in sandbox/trunk/modules/xwidgets: src/main/javascript and 1 other directory. Date: Mon, 15 Jun 2009 23:33:21 -0400 Message-ID: --===============7349262106975427495== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: shane.bryzak(a)jboss.com Date: 2009-06-15 23:33:21 -0400 (Mon, 15 Jun 2009) New Revision: 11161 Added: sandbox/trunk/modules/xwidgets/examples/helloworld/xw.Label.js sandbox/trunk/modules/xwidgets/examples/helloworld/xw.Panel.js Modified: sandbox/trunk/modules/xwidgets/examples/helloworld/index.html sandbox/trunk/modules/xwidgets/examples/helloworld/test.xw sandbox/trunk/modules/xwidgets/src/main/javascript/xw.Panel.js sandbox/trunk/modules/xwidgets/src/main/javascript/xw.js Log: support for magical asynchronous, dynamic loading of components = Modified: sandbox/trunk/modules/xwidgets/examples/helloworld/index.html =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sandbox/trunk/modules/xwidgets/examples/helloworld/index.html 2009-06-1= 5 23:54:27 UTC (rev 11160) +++ sandbox/trunk/modules/xwidgets/examples/helloworld/index.html 2009-06-1= 6 03:33:21 UTC (rev 11161) @@ -5,10 +5,12 @@
= - - = - Modified: sandbox/trunk/modules/xwidgets/examples/helloworld/test.xw =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sandbox/trunk/modules/xwidgets/examples/helloworld/test.xw 2009-06-15 2= 3:54:27 UTC (rev 11160) +++ sandbox/trunk/modules/xwidgets/examples/helloworld/test.xw 2009-06-16 0= 3:33:21 UTC (rev 11161) @@ -2,7 +2,5 @@ \ No newline at end of file Added: sandbox/trunk/modules/xwidgets/examples/helloworld/xw.Label.js =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sandbox/trunk/modules/xwidgets/examples/helloworld/xw.Label.js = (rev 0) +++ sandbox/trunk/modules/xwidgets/examples/helloworld/xw.Label.js 2009-06-= 16 03:33:21 UTC (rev 11161) @@ -0,0 +1,23 @@ +Package("xw.controls"); + +xw.controls.Label =3D function() +{ + this.value =3D ""; + this.parent =3D null; + this.control =3D null; + = + xw.controls.Label.prototype.setParent =3D function(parent) + { + this.parent =3D parent; + } + = + xw.controls.Label.prototype.paint =3D function() + { + if (this.control =3D=3D null) + { + this.control =3D document.createTextNode(this.value); + this.control.widget =3D this; + this.parent.control.appendChild(this.control); + } = + } +} Added: sandbox/trunk/modules/xwidgets/examples/helloworld/xw.Panel.js =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sandbox/trunk/modules/xwidgets/examples/helloworld/xw.Panel.js = (rev 0) +++ sandbox/trunk/modules/xwidgets/examples/helloworld/xw.Panel.js 2009-06-= 16 03:33:21 UTC (rev 11161) @@ -0,0 +1,29 @@ +Package("xw.controls"); + +xw.controls.Panel =3D function() +{ + this.width =3D 200; + this.height =3D 100; = + this.parent =3D null; + this.control =3D null; + = + xw.controls.Panel.prototype.setParent =3D function(parent) + { + this.parent =3D parent; + } + = + xw.controls.Panel.prototype.paint =3D function() + { + if (this.control =3D=3D null) + { + this.control =3D document.createElement("div"); + this.control.widget =3D this; + this.parent.control.appendChild(this.control); + = + this.control.style.width =3D "400"; + this.control.style.height =3D "200"; + = + this.control.style.border =3D "1px solid black"; + } = + } +} Modified: sandbox/trunk/modules/xwidgets/src/main/javascript/xw.Panel.js =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sandbox/trunk/modules/xwidgets/src/main/javascript/xw.Panel.js 2009-06-= 15 23:54:27 UTC (rev 11160) +++ sandbox/trunk/modules/xwidgets/src/main/javascript/xw.Panel.js 2009-06-= 16 03:33:21 UTC (rev 11161) @@ -20,8 +20,8 @@ this.control.widget =3D this; this.parent.control.appendChild(this.control); = - this.control.style.width =3D "100%"; - this.control.style.height =3D "100%"; + this.control.style.width =3D "400"; + this.control.style.height =3D "200"; = this.control.style.border =3D "1px solid black"; } = Modified: sandbox/trunk/modules/xwidgets/src/main/javascript/xw.js =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sandbox/trunk/modules/xwidgets/src/main/javascript/xw.js 2009-06-15 23:= 54:27 UTC (rev 11160) +++ sandbox/trunk/modules/xwidgets/src/main/javascript/xw.js 2009-06-16 03:= 33:21 UTC (rev 11161) @@ -28,41 +28,157 @@ return false; = } = +xw.Sys.createHttpRequest =3D function(mimeType) +{ = + if (window.XMLHttpRequest) + { + var req =3D new XMLHttpRequest(); + if (mimeType !=3D null && req.overrideMimeType) req.overrideMimeType(m= imeType); + return req; + } + else + { + return new ActiveXObject("Microsoft.XMLHTTP"); + } +} = + /** - * View Loader - loads view definitions from a URL + * Asynchronously loads the javascript source from the specified url */ -xw.ViewLoader =3D {}; -xw.ViewLoader.load =3D function(viewName, callback) +xw.Sys.loadSource =3D function(url, callback) { - if (window.XMLHttpRequest) + var req =3D xw.Sys.createHttpRequest("text/plain"); + req.onreadystatechange =3D function() { + if (req.readyState =3D=3D 4) + { + if (req.status =3D=3D 200 || req.status =3D=3D 0) + { + var e =3D document.createElement("script"); + e.language =3D "javascript"; + e.text =3D req.responseText; + e.type =3D "text/javascript"; + document.getElementsByTagName("head")[0].appendChild(e); = + if (callback) callback(); + } + } + else + { + //alert("There was an error processing your request. Error code: " = + req.status); + } + }; + = + req.open("GET", url, true); + req.send(null); +} + +xw.Sys.isUndefined =3D function(value) = +{ = + return value =3D=3D null && value !=3D=3D null; = +} + +xw.Sys.arrayContains =3D function(arrayVal, value) +{ + for (var i =3D 0; i < arrayVal.length; i++) { - asyncReq =3D new XMLHttpRequest(); - if (asyncReq.overrideMimeType) - asyncReq.overrideMimeType("text/xml"); + if (arrayVal[i] =3D=3D value) return true; = + } = + return false; +} + +xw.Sys.capitalize =3D function(value) +{ + return value.substring(0, 1).toUpperCase() + value.substring(1, value.le= ngth); = +} + +/** + * Control manager = + */ +xw.ControlManager =3D {}; +xw.ControlManager.controls =3D new Array(); +xw.ControlManager.pendingControls =3D new Array(); +xw.ControlManager.initControl =3D function(controlName) +{ = + if (xw.Sys.isUndefined(xw.controls) || + xw.Sys.isUndefined(eval("xw.controls." + controlName))) + { + var url =3D xw.getResourceBase() + "xw." + xw.Sys.capitalize(controlNa= me) + ".js"; + var callback =3D function() { xw.ControlManager.processPendingControls= (); }; + xw.Sys.loadSource(url, callback); + } = +} + +xw.ControlManager.processPendingControls =3D function() +{ + if (xw.ControlManager.pendingControls.length > 0) + { + var controlName =3D xw.ControlManager.pendingControls.shift(); + xw.ControlManager.initControl(controlName); } else { - asyncReq =3D new ActiveXObject("Microsoft.XMLHTTP"); + xw.ViewManager.signalControlsLoaded(); + } = +} + +xw.ControlManager.loadControls =3D function(controls) +{ + for (var i =3D 0; i < controls.length; i++) + { + if (!xw.ControlManager.isControlLoaded(controls[i])) + { + xw.ControlManager.pendingControls.push(controls[i]); = + } = } + = + xw.ControlManager.processPendingControls(); +} +xw.ControlManager.isControlLoaded =3D function(controlName) +{ + for (var i =3D 0; i < xw.ControlManager.controls.length; i++) + { + if (xw.ControlManager.controls[i] =3D=3D controlName) return true; + } = + return false; +} = - asyncReq.onreadystatechange =3D function() { callback(asyncReq) }; - asyncReq.open("GET", viewName, true); - asyncReq.send(null); - return asyncReq; = +/** + * View Loader - loads view definitions from a URL + */ +xw.ViewLoader =3D {}; +xw.ViewLoader.load =3D function(viewName, callback) +{ + var req =3D xw.Sys.createHttpRequest("text/xml"); + req.onreadystatechange =3D function() { callback(req) }; + req.open("GET", viewName, true); + req.send(null); + return req; = } = /** * View manager - responsible for caching views */ xw.ViewManager =3D {}; -xw.ViewManager.views =3D {}; +xw.ViewManager.pendingViews =3D new Array(); xw.ViewManager.loadViewCallback =3D function(req, container) { = if (req.readyState =3D=3D 4) { if (req.status =3D=3D 200 || req.status =3D=3D 0) { - xw.renderView(req.responseXML.documentElement, container); + var viewRoot =3D req.responseXML.documentElement; + if (viewRoot.tagName =3D=3D "view") + { + // create the view and push it into the pendingViews array + var view =3D new xw.View(viewRoot, container); + xw.ViewManager.pendingViews.push(view); + // next we want to load all of the controls + var controls =3D view.getDependencies(); + xw.ControlManager.loadControls(controls); + } + else + { + alert("Invalid view definition - document root is not 'view' eleme= nt"); + } = } else { @@ -71,6 +187,16 @@ } = } = +xw.ViewManager.signalControlsLoaded =3D function() +{ + if (xw.ViewManager.pendingViews.length > 0) + { + var view =3D xw.ViewManager.pendingViews.shift(); + view.render(); = + } = + = +} + xw.ViewManager.openView =3D function(viewName, container) { var callback =3D function(req) { = @@ -102,9 +228,35 @@ = xw.View.prototype.render =3D function() { - this.element =3D = this.renderChildren(this.viewRoot.childNodes, this); = } + = + xw.View.prototype.getDependencies =3D function() + { + var controls =3D new Array(); + this.parseControls(this.viewRoot.childNodes, controls); + return controls; = + } + = + xw.View.prototype.parseControls =3D function(elements, controls) + { + for (var i =3D 0; i < elements.length; i++) = + { + var element =3D elements.item(i); + if (element instanceof Element) + { + if (!xw.Sys.arrayContains(controls, element.tagName)) + { + controls[controls.length] =3D element.tagName; = + } + var children =3D element.childNodes; + if (children.length > 0) + { + this.parseControls(children, controls); = + } = + } = + } + } = xw.View.prototype.renderChildren =3D function(children, parentControl) { @@ -123,6 +275,7 @@ var controlName =3D tag.substring(0,1).toUpperCase() + = tag.substring(1, tag.length); = + // TODO fix var control =3D eval("new xw.controls." + controlName + "()"); = control.setParent(parent); @@ -149,22 +302,23 @@ } = /** - * General methods + ******* General methods ******* */ + = +/** + * Opens a view in the specified container - this call is asynchronous + */ = xw.openView =3D function(viewName, container) { xw.ViewManager.openView(viewName, container); } = -xw.renderView =3D function(viewRoot, container) -{ = - if (viewRoot.tagName =3D=3D "view") - { - var view =3D new xw.View(viewRoot, container); - view.render(); - } - else - { - alert("Invalid view definition - document root is not 'view' element"); - } = +xw.setResourceBase =3D function(resourceBase) +{ + xw.resourceBase =3D resourceBase; +} + +xw.getResourceBase =3D function() +{ + return xw.Sys.isUndefined(xw.resourceBase) ? "" : xw.resourceBase + "/"; } \ No newline at end of file --===============7349262106975427495==--