You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by mt...@apache.org on 2006/07/29 07:42:30 UTC

svn commit: r426763 - in /incubator/xap/trunk: WebContent/examples/ WebContent/examples/basic/ src/xap/bridges/basic/ src/xap/taghandling/

Author: mturyn
Date: Sat Jul 29 00:42:30 2006
New Revision: 426763

URL: http://svn.apache.org/viewvc?rev=426763&view=rev
Log:
Added an abstract class for a bridge wrappering a "black box" widget obeying a simple interface, and a subclass of that which wrappers a Dojo DatePicker object.  Added an example that uses the latter.

Added:
    incubator/xap/trunk/WebContent/examples/basic/datePicker.html
      - copied, changed from r426730, incubator/xap/trunk/WebContent/examples/basic/dom0.html
    incubator/xap/trunk/WebContent/examples/basic/datePicker.js
      - copied unchanged from r426730, incubator/xap/trunk/WebContent/examples/basic/dom0.js
    incubator/xap/trunk/WebContent/examples/basic/datePicker.xal
      - copied, changed from r426730, incubator/xap/trunk/WebContent/examples/basic/dom0.xal
    incubator/xap/trunk/WebContent/examples/basic/datePickerHandler.js
      - copied, changed from r426730, incubator/xap/trunk/WebContent/examples/basic/dom0Handler.js
    incubator/xap/trunk/src/xap/bridges/basic/AbstractBlackBoxWidgetBridge.js
    incubator/xap/trunk/src/xap/bridges/basic/DatePickerBridge.js
Modified:
    incubator/xap/trunk/WebContent/examples/index.html
    incubator/xap/trunk/src/xap/taghandling/plugin.xml

Copied: incubator/xap/trunk/WebContent/examples/basic/datePicker.html (from r426730, incubator/xap/trunk/WebContent/examples/basic/dom0.html)
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/basic/datePicker.html?p2=incubator/xap/trunk/WebContent/examples/basic/datePicker.html&p1=incubator/xap/trunk/WebContent/examples/basic/dom0.html&r1=426730&r2=426763&rev=426763&view=diff
==============================================================================
--- incubator/xap/trunk/WebContent/examples/basic/dom0.html (original)
+++ incubator/xap/trunk/WebContent/examples/basic/datePicker.html Sat Jul 29 00:42:30 2006
@@ -1,7 +1,7 @@
 <html>
 <head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-    <title>Wrapped DOM example 0</title>
+    <title>A Dojo "DatePicker" wrapped by an AbstractBlackBoxWidgetBridge subclass.</title>
 
 	<style type="text/css">
       <!--
@@ -25,20 +25,20 @@
     	// These should be in this order, as this is what their dependencies
     	// look like   	
 		Xap.addDebuggables( 
+						"xap.session.ClientSession",
 						"xap.taghandling.AbstractTagImpl",
-						"xap.bridges.dojo.DojoWidgetBridge",		
-						"xap.bridges.dojo.DojoButtonBridge",
-						"xap.bridges.basic.DomNodeBridge"
+						"xap.bridges.basic.AbstractBlackBoxWidgetBridge",
+						"xap.bridges.basic.DatePickerBridge",
+"src.dojo/src/widget.html.DatePicker"						
 							) ;
     </script>
    
     <script language="JavaScript" type="text/javascript">
     	Xap.bootstrap( "../../", true );
   	</script>
+<!--  Do this as late as possible---brings in script tags: -->
+<script language="JavaScript"> Xap._loadDebuggables();</script>
 
-    	
-
-    	
   	
   	  <!-- SECTION 2 -->
 	<script type="text/javascript">
@@ -49,35 +49,15 @@
 		dojo.require("dojo.widget.Button");  	                                          
  	</script>
 
-	<script language="JavaScript" src="dom0.js"> </script>
-	<script language="JavaScript" src="dom0Handler.js"> </script>	
-
-
- 
- <script>
-document.onAnotherEvent = function(){
-// Put something here so we can put a breakpoint on that line, if need be:
-	var foo = "bar" ;
-}
-
-
-var iii=0 ;
-
-document.attachOurEvent = function(){
-	var displayer = document.getElementById("mouseOverDisplayer") ;
-	displayer.lastCallInChain = function(){
-		displayer.innerHTML =  "Mouse-over number "+ (++iii) +"." ;
-	}
-	dojo.event.connect(document,"onAnotherEvent",displayer,"lastCallInChain") ;
-}
+	<script language="JavaScript" src="datePicker.js"> </script>
+	<script language="JavaScript" src="datePickerHandler.js"> </script>	
 
 
- </script>
  
  
  </head>
  
- <body onLoad="document.attachOurEvent();Xap.scanPage();if(xap.showStatus){xap.showStatus();};document.attachOurEvent();">
+ <body onLoad="Xap.scanPage();if(xap.showStatus){xap.showStatus();};">
 	<script type="text/javascript">
 		DBG = new AjxDebug( AjxDebug.NONE, null, false ); 
 	</script>
@@ -91,11 +71,11 @@
 		<tr><td><td/><td/></tr>
 		<tr><td id="xapStat"></td>		
 			<td><div context="../../"  id="applicationHome"
-				appName="MyApp" src="dom0.xal" toolkit="dojo">This cell is the xap ClientSession "MyApp"'s home-base.</div>
+				appName="MyApp" src="datePicker.xal" toolkit="dojo">This cell is the xap ClientSession "MyApp"'s home-base.</div>
 			</td>
 		</tr>
-		<tr><td  height="5em" id="targetNode" valign="top" align="left" onmouseover="javascript:document.onAnotherEvent()">FOObar</td><td/></tr>
-		<tr><td height="30px" bgColor="#884466"><td id="mouseOverDisplayer"/>Mouse-over number 0.<td/></tr>
+		<tr><td  height="5em" id="targetNode" valign="top" align="left"/><td></td></tr>
+		<tr><td height="30px" bgColor="#FFFFee"><strong>Try changing the year.</strong></td><td id="mouseOverDisplayer"/><td/></tr>
 	</table>
 
 
@@ -104,7 +84,6 @@
 	<button onclick="alert(MyApp.getDocumentContainer().getUiDocument().toXml());">hello</button>
 	<div id="foot">FOOTER TEXT</dev>
 
-<!--  Do this as late as possible---brings in script tags: -->
-<script> Xap._loadDebuggables();</script>
+
 </body>
 </html>

Copied: incubator/xap/trunk/WebContent/examples/basic/datePicker.xal (from r426730, incubator/xap/trunk/WebContent/examples/basic/dom0.xal)
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/basic/datePicker.xal?p2=incubator/xap/trunk/WebContent/examples/basic/datePicker.xal&p1=incubator/xap/trunk/WebContent/examples/basic/dom0.xal&r1=426730&r2=426763&rev=426763&view=diff
==============================================================================
--- incubator/xap/trunk/WebContent/examples/basic/dom0.xal (original)
+++ incubator/xap/trunk/WebContent/examples/basic/datePicker.xal Sat Jul 29 00:42:30 2006
@@ -4,20 +4,20 @@
 	<mco:mco 
 		xmlns:mco="http://www.openxal.org/mco" 
 		id="handler" 
-		src="dom0Handler"
+		src="datePickerHandler"
 	/>
 
 
 
   <xm:modifications xmlns:xm="http://www.openxal.org/xmodify">
     <xm:append select="/xal">
-		<dom xmlns="http://www.dojotoolkit.org/" 		
+		<datePicker xmlns="http://www.dojotoolkit.org/" 		
 				elementId="targetNode"
-				bgColor="#eeddFF"
-				color="#ffeeff"
-				innerHTML="Mouse over me!"
-				valign="middle"
-				align="center"
+				height="60px"
+				width="90px"
+				x="10px"
+				y="10px"
+				onCommand="javascript:alert('Year changed, event \'onIncrementYear\' triggered the code that created this box.')"
 		/>	
    	</xm:append> 	  	
 

Copied: incubator/xap/trunk/WebContent/examples/basic/datePickerHandler.js (from r426730, incubator/xap/trunk/WebContent/examples/basic/dom0Handler.js)
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/basic/datePickerHandler.js?p2=incubator/xap/trunk/WebContent/examples/basic/datePickerHandler.js&p1=incubator/xap/trunk/WebContent/examples/basic/dom0Handler.js&r1=426730&r2=426763&rev=426763&view=diff
==============================================================================
--- incubator/xap/trunk/WebContent/examples/basic/dom0Handler.js (original)
+++ incubator/xap/trunk/WebContent/examples/basic/datePickerHandler.js Sat Jul 29 00:42:30 2006
@@ -1,15 +1,15 @@
 // For MCO:
-function dom0Handler() { }
+function datePickerHandler() { }
 
-dom0Handler.prototype = new Object() ;
+datePickerHandler.prototype = new Object() ;
 
 
-dom0Handler.colours = ["<font color='#660000'>",
+datePickerHandler.colours = ["<font color='#660000'>",
 						"<font color='#aa00aa'>",
 						"<font color='#000000'>"
 						];						
 							
-dom0Handler.prototype.onClick = function (srcNode) {
+datePickerHandler.prototype.onClick = function (srcNode) {
 //xap.util.Utils.interrogate(srcNode) ;
 	var attributes = srcNode.attributes;
 	
@@ -17,17 +17,17 @@
 	var i1 = (i0+1)%3 ;
 	var i2 = (i0+2)%3 ;
 
-	var resultString = "<br/><br/>"+dom0Handler.colours[i0]
+	var resultString = "<br/><br/>"+datePickerHandler.colours[i0]
 						+"An MCO call got the attributes of the XAP button: " ;
 	if(!attributes){
 		resultString += "<br/><NONE>" ;
 	} else {
 		for (var ii = 0; ii <attributes.length; ++ii ){
 			resultString +="<br/>&nbsp;&nbsp;&nbsp;&nbsp;"
-							+ dom0Handler.colours[i1]
+							+ datePickerHandler.colours[i1]
 							+attributes[ii].nodeName
 							+"</font>" ;
-			resultString +=":"+ dom0Handler.colours[i2]
+			resultString +=":"+ datePickerHandler.colours[i2]
 								+attributes[ii].nodeValue+"</font>" ;				
 		}
 	}

Modified: incubator/xap/trunk/WebContent/examples/index.html
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/index.html?rev=426763&r1=426762&r2=426763&view=diff
==============================================================================
--- incubator/xap/trunk/WebContent/examples/index.html (original)
+++ incubator/xap/trunk/WebContent/examples/index.html Sat Jul 29 00:42:30 2006
@@ -23,6 +23,7 @@
       <li><a href="dojo/dojo1.html">Dojo example 1</a></li><br/>    
       
       <li><a href="basic/dom0.html">Wrapped dom example 0</a></li>
+      <li><a href="basic/datePicker.html">Wrapped DatePicker, treated as a black box.</a></li>      
 </ul>
   </body>
 </html>

Added: incubator/xap/trunk/src/xap/bridges/basic/AbstractBlackBoxWidgetBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/basic/AbstractBlackBoxWidgetBridge.js?rev=426763&view=auto
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/basic/AbstractBlackBoxWidgetBridge.js (added)
+++ incubator/xap/trunk/src/xap/bridges/basic/AbstractBlackBoxWidgetBridge.js Sat Jul 29 00:42:30 2006
@@ -0,0 +1,137 @@
+/*
+ * Copyright  2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *	http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+ 
+Xap.provide("xap.bridges.basic.AbstractBlackBoxWidgetBridge"); 
+Xap.require("xap.util.LogFactory") ;
+Xap.require("xap.taghandling.AbstractTagImpl") ;
+ 
+ /**
+ * @fileoverview
+ * 
+ * A superclass for the bridges controlling a widget peer obeying a limited interface; treat it
+ * as an abstract superclass (note that it doesn't implement a couple of methods it requires).
+ */
+ 
+ 
+ /**
+ * Creates a xap.bridges.basic.AbstractBlackBoxWidgetBridge.
+ * 
+ * 
+ * @class xap.bridges.basic.AbstractBlackBoxWidgetBridge is the bridge between an XML element
+ * representing a control and a subclass of AbstractBlackBoxWidget. This class 
+ * is typically not used directly but is extended by other classes 
+ * for its subclasses.
+ * 
+ * @author mturyn
+ */
+xap.bridges.basic.AbstractBlackBoxWidgetBridge =  function() {
+	xap.taghandling.AbstractTagImpl.call( this );
+}
+
+xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype = new xap.taghandling.AbstractTagImpl;
+
+xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.constructor = xap.bridges.basic.AbstractBlackBoxWidgetBridge ;
+
+xap.bridges.basic.AbstractBlackBoxWidgetBridge.s_log = xap.util.LogFactory.getLog( "xap.bridges.basic.AbstractBlackBoxWidgetBridge" );
+
+
+xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.toString = function() {
+	return "xap.bridges.basic.AbstractBlackBoxWidgetBridge";
+}
+
+/**
+ * All bridges to should go through these steps:
+ * 
+ * 1: Create or obtain the peer object
+ * 2: Handle all the initial attributes
+ * 3: Recursively parse the inititial children
+ * 
+**/ 
+xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.init = function() {
+	// Take basic layout-rectangle properties, if any, from the .xal file:
+	var mapper = new Object() ;
+	mapper.height = "height" ;
+	mapper.width = "width";	
+	mapper.x = "left" ;	
+	mapper.y = "top" ;	
+
+	this._creationProperties = new Object() ;
+
+	for (var prop in mapper){
+		var xalProp = this.getElement().getAttribute(prop) ;
+		if ( xalProp  &&  ("" + xalProp).length > 0 ){
+			this._creationProperties[ mapper[prop] ] = xalProp ;
+		}
+	}	
+
+
+	this.createPeer();
+	this.parseInitialAttributes( this.getElement() );
+	this.parseInitialChildren( this.getElement() );
+	xap.taghandling.AbstractTagImpl.prototype.init.call( this );
+	this.getPeer().show();
+}
+
+xap.bridges.basic.AbstractBlackBoxWidgetBridge.FUNCTION="function" ; 
+xap.bridges.basic.AbstractBlackBoxWidgetBridge.interfaceMethods = 
+	{attributeSet:null,getEventSource:null,getEventTrigger:null} ;
+	
+xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.createPeer = function() {
+	var parent = this.getElement().getParent();
+	var handler = this.getUiContentHandler().getHandlerForElement( parent );
+	var parentPeer = handler.getPeer();
+	 
+	// Hmmm...is there a better, generic, way
+	// of describing an element that contains
+	// a widget?
+	if ( parentPeer.nodeName=="DIV" 
+			|| parentPeer.nodeName=="BODY"
+				|| parentPeer.nodeName=="TD"
+			) {			   
+  
+		// The candy in the middle of the wrapper:
+		//xap.util.Utils.interrogate(propertyMap) ;
+		// is this subclass instance "this" an appropriate bridge---does it fit our "interface"?:
+
+		if(!this._peer){
+			throw new xap.util.Exception("Can't get a source object to manage.") ;
+		}
+
+		for( var meth in xap.bridges.basic.AbstractBlackBoxWidgetBridge.interfaceMethods){
+			if(!this[meth] ){
+				throw new xap.util.Exception("Source object does not have member \""+ meth+"\".") ;
+			}
+			if( typeof this[meth] !=xap.bridges.basic.AbstractBlackBoxWidgetBridge.FUNCTION){
+				throw new xap.util.Exception("Source object member \""+ meth+"\" is not a function.") ;
+			}
+		}
+		
+		// O.K., this is an object we can use as a  bridge---go on:		
+		//var peer = this._peer ;  //We've got one already.
+		dojo.event.connect(this.getEventSource(),this.getEventTrigger(), this,"_onCommandEvent");				
+	} else {
+		xap.bridges.basic.AbstractBlackBoxWidgetBridge.s_log.error("Bogus parent peer:" + parentPeer );
+	}
+}
+
+
+xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype._onCommandEvent = function( event ) {
+	this.fireEvent("onCommand");
+}
+
+
+

Added: incubator/xap/trunk/src/xap/bridges/basic/DatePickerBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/basic/DatePickerBridge.js?rev=426763&view=auto
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/basic/DatePickerBridge.js (added)
+++ incubator/xap/trunk/src/xap/bridges/basic/DatePickerBridge.js Sat Jul 29 00:42:30 2006
@@ -0,0 +1,78 @@
+
+/*
+ * Copyright  2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *	http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+Xap.provide("xap.bridges.basic.DatePickerBridge");
+Xap.require("xap.util.LogFactory");
+Xap.require("xap.bridges.basic.AbstractBlackBoxWidgetBridge");
+Xap.require("dojo.widget.DatePicker");
+
+/**
+ * @fileoverview
+ * 
+ * A wrapper for a Dojo DatePicker, treated as a black box.
+ */
+/**
+ * Creates a xap.bridges.basic.DatePickerBridge.
+ * 
+ * 
+ * @class xap.bridges.basic.DatePickerBridge is the bridge between an XML element
+ * representing a control and a subclass of DatePicker. This class 
+ * is typically not used directly but is extended by other classes 
+ * for its subclasses.
+ * 
+ * @author mturyn
+ */
+xap.bridges.basic.DatePickerBridge = function () {
+	xap.bridges.basic.AbstractBlackBoxWidgetBridge.call(this);
+};
+
+
+xap.bridges.basic.DatePickerBridge.prototype = new xap.bridges.basic.AbstractBlackBoxWidgetBridge;
+xap.bridges.basic.DatePickerBridge.prototype.constructor = xap.bridges.basic.DatePickerBridge;
+xap.bridges.basic.DatePickerBridge.s_log = xap.util.LogFactory.getLog("xap.bridges.basic.DatePickerBridge");
+xap.bridges.basic.DatePickerBridge.prototype.toString = function () {
+	return "xap.bridges.basic.DatePickerBridge";
+};
+
+
+xap.bridges.basic.DatePickerBridge.prototype._peer = null ;
+
+
+xap.bridges.basic.DatePickerBridge.prototype.createPeer = function () {
+	this._creationProperties.widgetId =   this.getElement().getAttribute("id");
+
+	var elementId = this.getElement().getAttribute("elementId");
+	var originalDiv = document.getElementById(elementId);
+	
+	this._creationProperties.widgetContainerId = elementId ;
+	
+	this._peer = dojo.widget.createWidget("DatePicker", this._creationProperties,originalDiv);
+	xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.createPeer.call(this);
+};
+
+
+
+xap.bridges.basic.DatePickerBridge.prototype.attributeSet = function () {
+	//TO_DO anything useful here?  format-string?
+};
+xap.bridges.basic.DatePickerBridge.prototype.getEventSource = function () {
+	return this._peer;
+};
+xap.bridges.basic.DatePickerBridge.prototype.getEventTrigger = function () {
+	return "onIncrementYear";
+};
+

Modified: incubator/xap/trunk/src/xap/taghandling/plugin.xml
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/taghandling/plugin.xml?rev=426763&r1=426762&r2=426763&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/taghandling/plugin.xml (original)
+++ incubator/xap/trunk/src/xap/taghandling/plugin.xml Sat Jul 29 00:42:30 2006
@@ -29,6 +29,7 @@
 		
 		
 		<mapping class="xap.bridges.basic.DomNodeBridge" name="dom"/>
+		<mapping class="xap.bridges.basic.DatePickerBridge" name="datePicker"/>
 										
 	</tag-mappings>