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/08/15 17:18:07 UTC

svn commit: r431643 - in /incubator/xap/trunk: WebContent/examples/basic/ WebContent/examples/dojo/ src/xap/ src/xap/bridges/basic/ src/xap/bridges/dojo/

Author: mturyn
Date: Tue Aug 15 10:18:06 2006
New Revision: 431643

URL: http://svn.apache.org/viewvc?rev=431643&view=rev
Log:
Tweaked bridge.attributeSet, other changes made in examples along the way.

Modified:
    incubator/xap/trunk/WebContent/examples/basic/dom0.html
    incubator/xap/trunk/WebContent/examples/dojo/dojo1.html
    incubator/xap/trunk/WebContent/examples/dojo/dojoExample_0.xal
    incubator/xap/trunk/WebContent/examples/dojo/portletHandler.js
    incubator/xap/trunk/src/xap/Xap.js
    incubator/xap/trunk/src/xap/bridges/basic/AbstractBlackBoxWidgetBridge.js
    incubator/xap/trunk/src/xap/bridges/dojo/DojoButtonBridge.js
    incubator/xap/trunk/src/xap/bridges/dojo/DojoColorPaletteBridge.js
    incubator/xap/trunk/src/xap/bridges/dojo/DojoFloatingPaneBridge.js
    incubator/xap/trunk/src/xap/bridges/dojo/DojoWidgetBridge.js

Modified: incubator/xap/trunk/WebContent/examples/basic/dom0.html
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/basic/dom0.html?rev=431643&r1=431642&r2=431643&view=diff
==============================================================================
--- incubator/xap/trunk/WebContent/examples/basic/dom0.html (original)
+++ incubator/xap/trunk/WebContent/examples/basic/dom0.html Tue Aug 15 10:18:06 2006
@@ -94,8 +94,7 @@
 				xapId="MyApp" xapSrc="dom0.xal" xapToolkit="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()"> </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" onmouseover="javascript:document.onAnotherEvent()"> </td><td id="mouseOverDisplayer"/>Mouse-over number 0.<td/></tr>
 	</table>
 
 

Modified: incubator/xap/trunk/WebContent/examples/dojo/dojo1.html
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/dojo/dojo1.html?rev=431643&r1=431642&r2=431643&view=diff
==============================================================================
--- incubator/xap/trunk/WebContent/examples/dojo/dojo1.html (original)
+++ incubator/xap/trunk/WebContent/examples/dojo/dojo1.html Tue Aug 15 10:18:06 2006
@@ -26,7 +26,7 @@
     	// look like   	
 		Xap.addDebuggables( 
 						"xap.taghandling.AbstractTagImpl",
-						"xap.taghandling.AbstractBlackBoxWidgetBridge",						
+						"xap.bridges.basic.AbstractBlackBoxWidgetBridge",						
 						"xap.bridges.dojo.DojoWidgetBridge",		
 						"xap.bridges.dojo.DojoButtonBridge"
 							) ;

Modified: incubator/xap/trunk/WebContent/examples/dojo/dojoExample_0.xal
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/dojo/dojoExample_0.xal?rev=431643&r1=431642&r2=431643&view=diff
==============================================================================
--- incubator/xap/trunk/WebContent/examples/dojo/dojoExample_0.xal (original)
+++ incubator/xap/trunk/WebContent/examples/dojo/dojoExample_0.xal Tue Aug 15 10:18:06 2006
@@ -1,7 +1,8 @@
 <xal xmlns="http://www.openxal.org/xal"> 
   <xm:modifications xmlns:xm="http://www.openxal.org/xmodify">
     <xm:append select="/xal">
-		<button xmlns="http://www.dojotoolkit.org/" text="First" 
+		<button xmlns="http://www.dojotoolkit.org/" 
+			text="FIRST" 
 			onClick="javascript:huh_0"			
 			height="24px"
 			width="40px"
@@ -11,7 +12,7 @@
 			backgroundColor="#00aaaa"
 		/> 
 		<floatingPane 
-			x="50px" y="20px" 
+			x="250px" y="250px" 
 			width="400px" height="400px" 
 			xmlns="http://www.dojotoolkit.org/" 
 			backgroundColor="#FFAAFF"
@@ -21,25 +22,25 @@
 			resizable="false"			
 	    >
 
-		<button xmlns="http://www.dojotoolkit.org/"
-			src="replaceButton.xm"
-			text="Do-"	
-			onClick="javascript:huh_1"			
-			width="60px"
-			height="32px"	
-			color="#00aa00"												
-		/>
+			<button xmlns="http://www.dojotoolkit.org/"
+				src="replaceButton.xm"
+				text="Do-"	
+				onClick="javascript:huh_1"			
+				width="60px"
+				height="32px"	
+				color="#00aa00"												
+			/>
 		
-		<floatingPane 
-			x="60px" y="20px" 
-			width="300px" height="250px" 
-			xmlns="http://www.dojotoolkit.org/" 
-			backgroundColor="#FFAAFF"
-			layoutAlign="horizontal"
-			color="#FFAAFF"
-			title="a resizable floating pane, horizontal alignment"
-			resizable="true"
-	    >			
+			<floatingPane 
+				x="60px" y="20px" 
+				width="300px" height="550px" 
+				xmlns="http://www.dojotoolkit.org/" 
+				backgroundColor="#FFAAFF"
+				layoutAlign="horizontal"
+				color="#FFAAFF"
+				title="a resizable floating pane, horizontal alignment"
+				resizable="true"
+		    >			
 			
 			
 			<button xmlns="http://www.dojotoolkit.org/"

Modified: incubator/xap/trunk/WebContent/examples/dojo/portletHandler.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/dojo/portletHandler.js?rev=431643&r1=431642&r2=431643&view=diff
==============================================================================
--- incubator/xap/trunk/WebContent/examples/dojo/portletHandler.js (original)
+++ incubator/xap/trunk/WebContent/examples/dojo/portletHandler.js Tue Aug 15 10:18:06 2006
@@ -28,8 +28,10 @@
 	
 	var bridge = clientEvent.session.getUiDocumentHandler().getHandlerForElement( cpEl );	
 
-	var palette = bridge.getPeer() ;
-	var colour = palette._color.replace(/\s/g,"") ;	
+//	var palette = bridge.getPeer() ;
+//	var colour = palette._color.replace(/\s/g,"") ;	
+
+	var colour = bridge.getAttribute( "color" ).replace(/\s/g,"") ;	
 
 	var elementId = clientEvent.source.getAttribute("displayerId") ;
 	var element = document.getElementById(portletHandler.getPairedCorner(elementId) );

Modified: incubator/xap/trunk/src/xap/Xap.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/Xap.js?rev=431643&r1=431642&r2=431643&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/Xap.js (original)
+++ incubator/xap/trunk/src/xap/Xap.js Tue Aug 15 10:18:06 2006
@@ -561,9 +561,10 @@
 	var subclassConstructor = Xap.resolveConstructor( subclassName ) ;
 	var superclassConstructor = Xap.resolveConstructor( superclassName ) ;	
 
-
 	subclassConstructor.prototype = new superclassConstructor();
 	subclassConstructor.prototype.superclass = 	superclassConstructor.prototype ;
+
+	subclassConstructor.prototype.constructor = subclassConstructor;
 
 	// This can by default the same for all objects; can overwrite this definition in
 	// the source file, if desired...

Modified: 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=431643&r1=431642&r2=431643&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/basic/AbstractBlackBoxWidgetBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/basic/AbstractBlackBoxWidgetBridge.js Tue Aug 15 10:18:06 2006
@@ -48,16 +48,12 @@
 	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.setupClassAsSubclassOf("xap.bridges.basic.AbstractBlackBoxWidgetBridge","xap.taghandling.AbstractTagImpl");
+
 
-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:
@@ -244,7 +240,7 @@
 				}
 			}
 		}
-		this.eventTriggers  = triggerMap ;
+		this.eventTriggers  = triggerMap ; 
 	}	
 	return  this.eventTriggers ;
 };
@@ -276,5 +272,81 @@
 xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.isBridge = function(){
 	return true ;
 }
+
+
+/**
+ * This is a default behaviour---subclasses should short-circuit this being called if they want to
+ * do anything interesting (e.g. aButton.getText--> peer.getCaption) .
+ * @param attributeName{string}
+ * @return object or primitive from the getter
+**/
+xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.getAttribute = function(name){
+	// Prefer to use accessors over fields:
+	var getterName = "get" + name.substring(0,1).toUpperCase() +name.substring(1)  ;	
+	var result = null ;
+	if (this.getPeer()[getterName]){
+		result =  this.getPeer()[getterName].call() ;
+	} else {
+		result = this.getPeer()[name] ;
+	}
+	return result ;
+}
+ 
+ /**
+  *   Memoiser to avoid the same string operation's repetition:
+  **/
+ xap.bridges.basic.AbstractBlackBoxWidgetBridge._nameToSetterMap = new Object() ;
+ 
+ /**
+ * This is a default behaviour---subclasses should short-circuit this being called if they want to
+ * do anything interesting (e.g. aBridge.attributeSet("foo") ---> aPeer.setBar(a) instead of ...setFoo(a).)
+ * @param event{AttributeChangeEvent}
+**/
+xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.attributeSet = function( event ) { 
+	var name = event.getName(); 
+	var value = event.getNewValue(); 
+	var peer = this.getPeer() ; 
+	
+	if( name=="xmlns"){
+		this._namespace = value ;
+		return ;
+	}
+	
+	if( name=="onCommand"){
+	// This is an event we've already mapped-to; if the attribute
+	// value has changed, that will only matter the next time it's
+	// triggered, at which point the new value will be found (since
+	// fireEvent() doesn't cache it in any event) and used:
+		return ;
+	}	
+	
+	if( this.eventTriggers[name]){
+		// This is one of our widget-specific mapped events;
+		// see "onCommand" super.
+		return ;
+	}
+	
+	
+	var setter = xap.bridges.basic.AbstractBlackBoxWidgetBridge._nameToSetterMap[name] ;
+	// May seem needless, but string operations are generally much slower than 
+	// look-ups---we could even fill this table at startup.....
+	if (!setter){
+		setter = "set" + name.substring(0,1).toUpperCase() +name.substring(1) ; 
+		xap.bridges.basic.AbstractBlackBoxWidgetBridge._nameToSetterMap[name] = setter ;
+	}
+	
+	// First try to use this setter on the peer:
+	if( peer[setter]){
+		peer[setter].call( peer, value) ;
+	// Next, try direct field-setting
+	} else if (peer[name]){
+		peer[name] = value ;
+	} else {
+		this.superclass.attributeSet.call( this, event );    
+	} 
+}
+
+
+
 
 

Modified: incubator/xap/trunk/src/xap/bridges/dojo/DojoButtonBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/dojo/DojoButtonBridge.js?rev=431643&r1=431642&r2=431643&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/dojo/DojoButtonBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/dojo/DojoButtonBridge.js Tue Aug 15 10:18:06 2006
@@ -58,28 +58,26 @@
 				"xap.bridges.dojo.DojoWidgetBridge"						
 );
 
-/*
-     ==
 
-xap.bridges.dojo.DojoButtonBridge.prototype = new xap.bridges.dojo.DojoWidgetBridge;
 
-
-xap.bridges.dojo.DojoButtonBridge.prototype.constructor=xap.bridges.dojo.DojoButtonBridge ;
-xap.bridges.dojo.DojoButtonBridge.prototype.superclass = xap.bridges.dojo.DojoWidgetBridge.prototype ;
-
-xap.bridges.dojo.DojoButtonBridge.s_log = xap.util.LogFactory.getLog( "DojoButtonBridge" );
-
-xap.bridges.dojo.DojoButtonBridge.prototype.toString = function() {
-	return "xap.bridges.dojo.DojoButtonBridge";
+xap.bridges.dojo.DojoButtonBridge.prototype.getPeerString = function(){
+    return "Button" ;
 }
 
-*/
-
 
+/**
+ *  Sets the widget as our peer, upgrades it with new methods to adapt it to our use:
+**/
+xap.bridges.dojo.DojoButtonBridge.prototype.setPeer = function(aButton){
+	this.superclass.setPeer.call(this,aButton) ;
+	aButton.setText = function(aString){
+		xap.bridges.dojo.DojoButtonBridge.changeCaption(aButton,aString) ; 
+	}
+	aButton.getText = function(){
+		aButton.getCaption()  ; 
+	}	
+}	
 
-xap.bridges.dojo.DojoButtonBridge.prototype.getPeerString = function(){
-    return "Button" ;
-}
 
 
 
@@ -108,28 +106,20 @@
     var name = event.getName();
     var value = event.getNewValue();
     var peer = this.getPeer();
-    
-    if (name=="text"){
-        xap.bridges.dojo.DojoButtonBridge.changeCaption(peer,value) ;    
-    }
-    else if(name=="fontColor"){
+    var shouldResize = false ;
+      
+    if(name=="fontColor"){
         peer.setTextForeground(value);
     }
     else if(name=="image"){
-        //peer.setImage(value);
           peer.activeImg=value ;
+          shouldResize=true ;
+    } else{
+        this.superclass.attributeSet.call( this, event );
     }
-    else if (name=="onClick"){
-        dojo.event.connect(peer, 'onClick', value) ;
-    }
-//    else if (name=="onCommand"){
-//        //dojo.event.connect(peer.domNode, 'onCommand', value) ;
-//		document.addEventListener("onclick", this._onSelectEvent, this);        
-//    }    
-    else{
-        xap.bridges.dojo.DojoWidgetBridge.prototype.attributeSet.call( this, event );
+    if(shouldResize){
+    	peer.onResized() ;
     }
-    peer.onResized() ;
 }
 
 

Modified: incubator/xap/trunk/src/xap/bridges/dojo/DojoColorPaletteBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/dojo/DojoColorPaletteBridge.js?rev=431643&r1=431642&r2=431643&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/dojo/DojoColorPaletteBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/dojo/DojoColorPaletteBridge.js Tue Aug 15 10:18:06 2006
@@ -71,6 +71,9 @@
 	aWidget.onColorSelect = function(aColor){
 		aWidget._color =  aColor ;
 	}
+	aWidget.getColor = function(){
+		return aWidget._color ;
+	}	
 }
 
 

Modified: incubator/xap/trunk/src/xap/bridges/dojo/DojoFloatingPaneBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/dojo/DojoFloatingPaneBridge.js?rev=431643&r1=431642&r2=431643&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/dojo/DojoFloatingPaneBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/dojo/DojoFloatingPaneBridge.js Tue Aug 15 10:18:06 2006
@@ -52,10 +52,6 @@
 
 Xap.setupClassAsSubclassOf( "xap.bridges.dojo.DojoFloatingPaneBridge", "xap.bridges.dojo.DojoWidgetBridge") ;
 
-
-
-
-
 xap.bridges.dojo.DojoFloatingPaneBridge.prototype.getPeerString = function(){
     return "FloatingPane" ;
 }
@@ -109,25 +105,44 @@
     var name = event.getName();
     var value = event.getNewValue();
     var peer = this.getPeer();
+    var shouldResize = false ;
     
-    if (name=="layoutAlign"){
-    	peer.layoutAlign = value ;
-    } 
-    else if (name=="title"){
-    	peer.title = value ;
-    	// Mozilla:
-    	if (peer.titleBar.textContent){
-	    	peer.titleBar.textContent = value ;
-	    	peer.titleBar.title = value ;    	
-    	}  // IE
-    	else if (peer.titleBar.innerText){
-	  	
-    	} 
+    if ( name=="x" ) {
+		// peer.setLocation( value, null );
+		peer.domNode.style.left = value ;
+		peer.containerNode.style.left = value ;			
+		shouldResize = true ; 	
+	} else if (name=="y") {
+		peer.domNode.style.top = value ;
+		peer.containerNode.style.top = value ;		
+		shouldResize = true ; 
+	} else if (name=="width") {
+		peer.containerNode.style.width=value ;
+		peer.domNode.style.width=value ;					
+		shouldResize = true ; ;
+	} else if ( name=="height"){
+		peer.containerNode.style.height=value ;	
+		peer.domNode.style.height=value ;				
+		shouldResize = true ; ;
+	} else if (name=="layoutAlign"){
+    		peer.layoutAlign = value ;
+    } else if (name=="title"){
+		peer.title = value ;
+		// Mozilla:
+		if (peer.titleBar.textContent){
+			peer.titleBar.textContent = value ;
+			peer.titleBar.title = value ;    	
+		}  else if (peer.titleBar.innerText){
+		// IE	  	
+		}
 
-    } else {
-        xap.bridges.dojo.DojoWidgetBridge.prototype.attributeSet.call( this, event );
+	} else {
+//		xap.bridges.dojo.DojoWidgetBridge.prototype.attributeSet.call( this, event );
+    }
+    
+    if( shouldResize){
+    	//peer.onResized() ;
     }
-    peer.onResized() ;
 }
 
 xap.bridges.dojo.DojoFloatingPaneBridge.prototype.getRootDomNode = function(){

Modified: incubator/xap/trunk/src/xap/bridges/dojo/DojoWidgetBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/dojo/DojoWidgetBridge.js?rev=431643&r1=431642&r2=431643&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/dojo/DojoWidgetBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/dojo/DojoWidgetBridge.js Tue Aug 15 10:18:06 2006
@@ -148,7 +148,7 @@
    		}
    
    		// The candy in the middle of the wrapper:
-        var peer = dojo.widget.createWidget(dojoType,propertyMap,tmp); 
+        	var peer = dojo.widget.createWidget(dojoType,propertyMap,tmp); 
 		this.setPeer(peer ) ;
 }
 
@@ -190,7 +190,8 @@
 	var name = event.getName();
 	var value = event.getNewValue();
 	var peer = this.getPeer();
-    var shouldResize=false ;
+      var shouldResize=false ;
+      
     
 	if ( name=="debugName" ) {
 		peer.debugName = value ;	
@@ -199,11 +200,11 @@
 	else if ( name=="x" ) {
 		// peer.setLocation( value, null );
 		peer.domNode.style.left = value ;	
-		shouldResize = true ; ;		
+		shouldResize = true ; 	
 	}
 	else if (name=="y") {
 		peer.domNode.style.top = value ;
-		shouldResize = true ; ;
+		shouldResize = true ; 
 	}
 	else if (name=="width") {
 		peer.domNode.style.width=value ;			
@@ -260,12 +261,14 @@
 		peer.domNode.style.padding=value;
 	}
     else if ( name=="position" ){
-        peer.domNode.style.position=value;
-        peer.containerNode.style.position=value;
+	peer.domNode.style.position=value;
+	peer.containerNode.style.position=value;
     }
     else if ( name=="textAlign" ){
-        peer.domNode.style.textAlign=value;
-    }    
+		peer.domNode.style.textAlign=value;
+    }  else {  
+		xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.attributeSet.call( this, event );    
+    }
 
     
     if( shouldResize ){