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/10 17:39:30 UTC

svn commit: r430453 - in /incubator/xap/trunk/src/xap: bridges/basic/AbstractBlackBoxWidgetBridge.js bridges/basic/DomNodeBridge.js session/ClientSession.js

Author: mturyn
Date: Thu Aug 10 10:39:29 2006
New Revision: 430453

URL: http://svn.apache.org/viewvc?rev=430453&view=rev
Log:
Altered AbstractBlackBoxWidget.createPeer() so that it no longer directly looks at the parent bridge's peer.  
Altered ClientSession so that it wrappers the top-level HTML Dom node adequately, so that the altered createPeer() will have something to deal-with.  
Altered DomNodeBridge so that it's easy to create a new one given an HTMLElement.

Modified:
    incubator/xap/trunk/src/xap/bridges/basic/AbstractBlackBoxWidgetBridge.js
    incubator/xap/trunk/src/xap/bridges/basic/DomNodeBridge.js
    incubator/xap/trunk/src/xap/session/ClientSession.js

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=430453&r1=430452&r2=430453&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/basic/AbstractBlackBoxWidgetBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/basic/AbstractBlackBoxWidgetBridge.js Thu Aug 10 10:39:29 2006
@@ -104,7 +104,7 @@
 
 
 xap.bridges.basic.AbstractBlackBoxWidgetBridge.interfaceMethods = 
-	{attributeSet:null,getEventTriggers:null,getDisplayDomNode:null,getRootDomNode:null} ;
+	{obtainPeer:null,attributeSet:null,getEventTriggers:null,getDisplayDomNode:null,getRootDomNode:null} ;
 	
 xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.createPeer = function() {
 	// Implemented by subclasses---here, we don't care how they get it:  with a simple
@@ -113,23 +113,40 @@
 	this.obtainPeer() ;
 
 	var parent = this.getElement().getParent();
-	var handler = this.getUiContentHandler().getHandlerForElement( parent );
-	var parentPeer = handler.getPeer();
+	var parentHandler = this.getUiContentHandler().getHandlerForElement( parent );
+	var parentPeer = parentHandler.getPeer();
+
+	var parentPeerDomNode = null ;
+
+	if ( parentHandler.getDisplayDomNode ){
+	// The parent is another bridge
+	// Get the display node associated with the bridge's parent, since this represents the 
+	// place in the HTML DOM	
+		 parentPeerDomNode = parentHandler.getDisplayDomNode() ;
+	}  else if (parentPeer.innerHTML){
+		// This is already an HTML element or equivalent:
+		// (Is there a better way of telling an HTML element?)
+		// TO_DO:  make sure that we can remove this option---bridges
+		// should see only other bridges' components only through methods.
+		parentPeerDomNode = parentPeer ;
+	} else {
+		throw new xap.util.Exception("Parent must either be a XapElement or a bridge.") ;
+	}
 	 
-	// Hmmm...is there a better, generic, way
+	// TO_DO: is there a better, generic, way
 	// of describing an element that contains
-	// a widget?
-	if ( parentPeer.nodeName=="DIV" 
-			|| parentPeer.nodeName=="BODY"
-				|| parentPeer.nodeName=="TD"
-			) {			   
+	// a widget---maybe anything that can call appendChild?
+	if ( ! parentPeerDomNode.tagName.match(/(DIV|BODY|TD)/)
+			){
+		xap.bridges.basic.AbstractBlackBoxWidgetBridge.s_log.error("Bogus parent peer:" + parentPeer );
+	} else  {			   
   
 		// 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.") ;
+			throw new xap.util.Exception("Haven't obtained a source object to manage.") ;
 		}
 
 		for( var meth in xap.bridges.basic.AbstractBlackBoxWidgetBridge.interfaceMethods){
@@ -153,13 +170,11 @@
 			var trigger  = triggerPieces[triggerPieces.length - 1] ;
 			dojo.event.connect(source,trigger, this,trigger);				
 		}
-		dojo.event.connect(this._peer,this.getPeerOnCommandEvent(),this,"_onCommandEvent") ;
-		if(parent.getDisplayDomNode){
-			parent.getDisplayDomNode().appendChild(this.getDisplayDomNode()) ;
-		}
-	} else {
-		xap.bridges.basic.AbstractBlackBoxWidgetBridge.s_log.error("Bogus parent peer:" + parentPeer );
-	}
+		dojo.event.connect(this.getPeer(),this.getPeerOnCommandEvent(),this,"_onCommandEvent") ;
+
+		parentPeerDomNode.appendChild(this.getDisplayDomNode()) ;
+
+	} 
 }
 
  //Default behaviour:
@@ -237,6 +252,15 @@
 	// What will the id of the node to which we'll attach this widget be?
 	var elementId = this.getElement().getAttribute("elementId");
 	return document.getElementById(elementId);
+}
+
+
+/**
+ *	@return true, as this class and those prototyping with it are bridges:
+ *
+**/ 
+xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.isBridge = function(){
+	return true ;
 }
 
 

Modified: incubator/xap/trunk/src/xap/bridges/basic/DomNodeBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/basic/DomNodeBridge.js?rev=430453&r1=430452&r2=430453&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/basic/DomNodeBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/basic/DomNodeBridge.js Thu Aug 10 10:39:29 2006
@@ -42,6 +42,9 @@
  */
 xap.bridges.basic.DomNodeBridge = function() {
 	xap.taghandling.AbstractTagImpl.call( this );
+	if(arguments[0]){
+		this._peer = arguments[0] ;
+	}
 }
 
 Xap.setupClassAsSubclassOf(
@@ -58,11 +61,13 @@
 	var handler = this.getUiContentHandler().getHandlerForElement( parent );
 	var parentPeer = handler.getPeer();
 	
-	var elementId = this.getElement().getAttribute("elementId")  ;
-	
-	if ( true  ) {
+	// If we don't have a peer, try to find one:
+	if ( !this._peer ) {
     	try {
-    	    var peer = document.getElementById(elementId) ;
+		var elementId = this.getElement().getAttribute("elementId")  ;    	
+		var peer = document.getElementById(elementId) ;
+		// This method does more than just set the _peer member; it
+		// can also set up handlers.....
     		this.setPeer(peer) ;
         } catch ( e ) {
         	alert(e);

Modified: incubator/xap/trunk/src/xap/session/ClientSession.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/session/ClientSession.js?rev=430453&r1=430452&r2=430453&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/session/ClientSession.js (original)
+++ incubator/xap/trunk/src/xap/session/ClientSession.js Thu Aug 10 10:39:29 2006
@@ -292,15 +292,27 @@
 }
 
 xap.session.ClientSession.prototype._createInitialDocument = function(toolkitType, parentElement) {
-	var shell = null ;
+	var parentElementWrapper = null ;
+
+	//create a zimbra parentElementWrapper object
+	//create an abstractTagImpl
+	var handler = new xap.taghandling.AbstractTagImpl();
+
+
+// If the handler handles a dojo widget, its relevant dom node will be the parentElement;
+// if zimbroid, it will have to be found some other way Zimbra will handle:
 	if( toolkitType && toolkitType=="dojo"){
-		shell = parentElement!=null? parentElement : document.body ;
+		parentElementWrapper = parentElement!=null? parentElement : document.body ;
+		handler.getDisplayDomNode = function(){
+			return parentElement ;
+		}
 	} else {
-		shell = new DwtShell( "MainShell", false, null, null, true );
+		parentElementWrapper = new DwtShell( "MainShell", false, null, null, true );
+		handler.getDisplayDomNode = function(){
+			return  parentElementWrapper ;
+		}		
 	}
-	//create a zimbra shell object
-	//create an abstractTagImpl
-	var handler = new xap.taghandling.AbstractTagImpl();
+
 	
 	var uiDocument =  this.getDocumentContainer().getUiDocument();
 	handler.setElement( uiDocument.getRootElement() );
@@ -310,7 +322,7 @@
 											 handler.getElement(), handler );
 	handler.init();
 	
-	//have the shell be the peer of the xap.taghandling.AbstractTagImpl
-	handler.setPeer( shell );
+	//have the parentElementWrapper be the peer of the xap.taghandling.AbstractTagImpl
+	handler.setPeer( parentElementWrapper );
 }