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/02 19:49:58 UTC
svn commit: r428116 - in /incubator/xap/trunk: WebContent/examples/dojo/
src/xap/ src/xap/bridges/basic/ src/xap/bridges/dojo/
Author: mturyn
Date: Wed Aug 2 12:49:58 2006
New Revision: 428116
URL: http://svn.apache.org/viewvc?rev=428116&view=rev
Log:
Refactored s.t. DojoWidgetBridge is now a subclass of AbstractBlackBoxWidgetBridge, so a lot of changes on that class. Added a generic setup method to Xap to handle standard toString() method, inheritance setup, our logging---basically dojo.inherits() plus Xap-specific add-ons.
Modified:
incubator/xap/trunk/WebContent/examples/dojo/dojo1.html
incubator/xap/trunk/WebContent/examples/dojo/dojo1.xal
incubator/xap/trunk/WebContent/examples/dojo/dojo1Handler.js
incubator/xap/trunk/src/xap/Xap.js
incubator/xap/trunk/src/xap/bridges/basic/AbstractBlackBoxWidgetBridge.js
incubator/xap/trunk/src/xap/bridges/basic/DatePickerBridge.js
incubator/xap/trunk/src/xap/bridges/dojo/DojoButtonBridge.js
incubator/xap/trunk/src/xap/bridges/dojo/DojoWidgetBridge.js
Modified: incubator/xap/trunk/WebContent/examples/dojo/dojo1.html
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/dojo/dojo1.html?rev=428116&r1=428115&r2=428116&view=diff
==============================================================================
--- incubator/xap/trunk/WebContent/examples/dojo/dojo1.html (original)
+++ incubator/xap/trunk/WebContent/examples/dojo/dojo1.html Wed Aug 2 12:49:58 2006
@@ -26,6 +26,7 @@
// look like
Xap.addDebuggables(
"xap.taghandling.AbstractTagImpl",
+ "xap.taghandling.AbstractBlackBoxWidgetBridge",
"xap.bridges.dojo.DojoWidgetBridge",
"xap.bridges.dojo.DojoButtonBridge"
) ;
Modified: incubator/xap/trunk/WebContent/examples/dojo/dojo1.xal
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/dojo/dojo1.xal?rev=428116&r1=428115&r2=428116&view=diff
==============================================================================
--- incubator/xap/trunk/WebContent/examples/dojo/dojo1.xal (original)
+++ incubator/xap/trunk/WebContent/examples/dojo/dojo1.xal Wed Aug 2 12:49:58 2006
@@ -16,7 +16,8 @@
color="#aa0000"
id="button0"
backgroundColor="#00aaaa"
- onCommand="mco:handler.onClick(this)"
+ onCommand="mco:handler.examineObject(this)"
+ onMouseOver="mco:handler.addPeriods(this)"
/>
</xm:append>
Modified: incubator/xap/trunk/WebContent/examples/dojo/dojo1Handler.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/dojo/dojo1Handler.js?rev=428116&r1=428115&r2=428116&view=diff
==============================================================================
--- incubator/xap/trunk/WebContent/examples/dojo/dojo1Handler.js (original)
+++ incubator/xap/trunk/WebContent/examples/dojo/dojo1Handler.js Wed Aug 2 12:49:58 2006
@@ -4,12 +4,12 @@
dojo1Handler.prototype = new Object() ;
-dojo1Handler.colours = ["<font color='#660000'>",
- "<font color='#0000aa'>",
- "<font color='#000000'>"
+dojo1Handler.colours = ["<font color='#aa0000'>",
+ "<font color='#0000cc'>",
+ "<font color='#00aa00'>"
];
-dojo1Handler.prototype.onClick = function (srcNode) {
+dojo1Handler.prototype.examineObject = function (srcNode) {
//xap.util.Utils.interrogate(srcNode) ;
var attributes = srcNode.attributes;
@@ -35,4 +35,11 @@
var ticker = document.getElementById("xapStat") ;
ticker.innerHTML = ticker.innerHTML + resultString ;
+}
+
+dojo1Handler.prototype.addPeriods = function (srcNode) {
+ var ticker = document.getElementById("xapStat") ;
+ ticker.innerHTML = ticker.innerHTML
+ + dojo1Handler.colours[Math.floor(3*Math.random() )]
+ + " ... </font>" ;
}
Modified: incubator/xap/trunk/src/xap/Xap.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/Xap.js?rev=428116&r1=428115&r2=428116&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/Xap.js (original)
+++ incubator/xap/trunk/src/xap/Xap.js Wed Aug 2 12:49:58 2006
@@ -595,6 +595,37 @@
}
}
+Xap.resolveConstructor = function(aString){
+ var scoper = dj_global ;
+ var arr = aString.split(".") ;
+ for( var kk=0; kk< arr.length - 1; ++kk ){
+ scoper = scoper[arr[kk]] ;
+ }
+ return scoper[arr[arr.length-1]] ;
+}
+
+
+
+/**
+ * Handles common class set-up routines, assumes constructors for subclass and superclass already exist:
+**/
+Xap.setupClassAsSubclassOf = function(subclassName,superclassName,sub,sup){
+ var subclassConstructor = Xap.resolveConstructor( subclassName ) ;
+ var superclassConstructor = Xap.resolveConstructor( superclassName ) ;
+
+ if(superclassName){
+ Xap.require(superclassName) ;
+ }
+ dojo.inherits(subclassConstructor, superclassConstructor) ;
+ subclassConstructor.prototype.toString = function(){
+ return subclassName ;
+ }
+ subclassConstructor.prototype.superclass = superclassConstructor.prototype ;
+ subclassConstructor.s_log = xap.util.LogFactory.getLog( subclassName ) ;
+}
+
+
+
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=428116&r1=428115&r2=428116&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/basic/AbstractBlackBoxWidgetBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/basic/AbstractBlackBoxWidgetBridge.js Wed Aug 2 12:49:58 2006
@@ -101,6 +101,11 @@
{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
+ // constructor, via a database call, using a JSON-encoded object over the fibre,
+ // or stolen from a fruit-cart:
+ this.obtainPeer() ;
+
var parent = this.getElement().getParent();
var handler = this.getUiContentHandler().getHandlerForElement( parent );
var parentPeer = handler.getPeer();
@@ -136,12 +141,16 @@
// We now have a hash table containing a set of strings (triggers) pointing to
// objects, like "[Foobar.]onBaz"--->aFoobarInstance
for(var aKey in triggers){
- var source = triggers[aKey] ;
- var triggerPieces = aKey.split(".") ;
+ var source = triggers[aKey].src ;
+ var triggerPieces = triggers[aKey].methodName.split(".") ;
// handles both "foo" and "Me.foo"
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 );
}
@@ -159,7 +168,13 @@
}
-// Closure to create a default function---is there still a problem
+xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.getPeerOnCommandEvent = function(){
+ return "onClick" ;
+}
+
+
+
+// Closure to create a default event-handling function---is there still a problem
// (memory leak) with this in IE?
xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.getOnXFunction = function(str){
return function(){
@@ -176,29 +191,46 @@
var triggerMap = new Object() ;
// Let's transfer all the "onXXX" methods over to the bridge---first find
// them, then use a closure to create the new function:
- for(var keyy in this._peer){
- var member = this._peer[keyy] ;
+ for(var methodName in this._peer){
+ var member = this._peer[methodName] ;
if( !xap.bridges.basic.AbstractBlackBoxWidgetBridge.s_IsFunction(member) ){
continue ;
}
- if( keyy.substring(0,2)==xap.bridges.basic.AbstractBlackBoxWidgetBridge.ON){
- triggerMap[keyy] = this._peer ;
- // Create the callback for this "on..." method, if we don't have it:
- if( !this[keyy]){
+ if( methodName.substring(0,2)==xap.bridges.basic.AbstractBlackBoxWidgetBridge.ON){
+ // By default, "<bridge>.onFoo" maps to "<peer>.onFoo", but this could
+ // change, so allow for that:
+ triggerMap[methodName] = { src: this._peer, methodName: methodName } ;
+ // Create the callback for this "on..." method, if we don't explicitly have it:
+ if( !this[methodName]){
// This is the only way I could think of (that worked) to
// get the name of the event into the callback definition, so
// "onBlur" --> this.fireEvent("onBlur")
- this[keyy] = this.getOnXFunction(keyy) ;//this.eval( this.getStringForFireEventMethodString(keyy) ) ;
-
+ this[methodName] = this.getOnXFunction(methodName) ;
}
}
}
this.eventTriggers = triggerMap ;
- }
+ }
return this.eventTriggers ;
};
+/**
+ * Default behavior in this abstract superclass: the display dom node is the root dom node.
+**/
+xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.getDisplayDomNode = function(){
+ return this.getRootDomNode() ;
+}
-
+/**
+ * @return An HTML object (e.g., a DIV or a TD or...) which this widget can replace---this
+ * both works with Dojo's way of doing things, and (more generally) allows a designer to
+ * lay out the location for a component.
+ *
+**/
+xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.getOriginalDomNode = function(){
+ // 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);
+}
Modified: 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=428116&r1=428115&r2=428116&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/basic/DatePickerBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/basic/DatePickerBridge.js Wed Aug 2 12:49:58 2006
@@ -52,19 +52,20 @@
xap.bridges.basic.DatePickerBridge.prototype._peer = null ;
-xap.bridges.basic.DatePickerBridge.prototype.createPeer = function () {
+xap.bridges.basic.DatePickerBridge.prototype.obtainPeer = function () {
this._creationProperties.widgetId = this.getElement().getAttribute("id");
- // What will the id of the node to which we'll attach this widget be?
- var elementId = this.getElement().getAttribute("elementId");
- var originalDiv = document.getElementById(elementId);
-
- this._creationProperties.widgetContainerId = elementId ;
-
- this._peer = dojo.widget.createWidget("DatePicker", this._creationProperties,originalDiv);
+// The superclass method is fine for this, almost as if it were originally here and had
+// been moved up there when refactoring.
+ originalDiv = this.getOriginalDomNode() ;
- xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.createPeer.call(this);
+ this._creationProperties.widgetContainerId =this._creationProperties.widgetId ;
+ var peer = dojo.widget.createWidget("DatePicker", this._creationProperties,originalDiv);
+
+ this.setPeer(peer) ;
+
+
};
@@ -78,13 +79,9 @@
return this._peer.domNode ;
}
-//Default behaviour:
-xap.bridges.basic.AbstractBlackBoxWidgetBridge.getDisplayDomNode = function(){
- return this.getRootDomNode() ;
-}
-
-
+// Just testing that the superclass event-mapper doesn't destroy any explicitly-defined
+// events:
xap.bridges.basic.AbstractBlackBoxWidgetBridge.prototype.onIncrementYear = function(){
this.fireEvent("onIncrementYear") ;
var bkpt = true ;
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=428116&r1=428115&r2=428116&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/dojo/DojoButtonBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/dojo/DojoButtonBridge.js Wed Aug 2 12:49:58 2006
@@ -45,6 +45,14 @@
xap.bridges.dojo.DojoWidgetBridge.call(this);
}
+
+Xap.setupClassAsSubclassOf(
+ "xap.bridges.dojo.DojoButtonBridge",
+ "xap.bridges.dojo.DojoWidgetBridge"
+);
+
+/*
+
xap.bridges.dojo.DojoButtonBridge.prototype = new xap.bridges.dojo.DojoWidgetBridge;
@@ -57,6 +65,8 @@
return "xap.bridges.dojo.DojoButtonBridge";
}
+*/
+
xap.bridges.dojo.DojoButtonBridge.prototype.getPeerString = function(){
@@ -70,8 +80,8 @@
* The callback for the selection listener on DojoButton.
* When this is called we fire an "onCommand" event.
*/
-xap.bridges.dojo.DojoButtonBridge.prototype._onSelectEvent = function( event ) {
- this.fireEvent("onCommand");
+xap.bridges.dojo.DojoButtonBridge.prototype.getPeerOnCommandEvent= function(){
+ return "onClick" ;
}
@@ -169,16 +179,7 @@
return map ;
}
-
-
-/**
- * With what event will we associate our top-level "fireEvent" which
- * will turn into a direct Javascript eval, and MCO, a Macro, and http: request.... ?
-**/
-xap.bridges.dojo.DojoButtonBridge.prototype.getEventAttachString = function(){
- return "onclick" ;
-}
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=428116&r1=428115&r2=428116&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/dojo/DojoWidgetBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/dojo/DojoWidgetBridge.js Wed Aug 2 12:49:58 2006
@@ -15,6 +15,7 @@
*
*/
+ Xap.require("xap.bridges.basic.AbstractBlackBoxWidgetBridge");
Xap.provide("xap.bridges.dojo.DojoWidgetBridge");
/**
@@ -38,10 +39,10 @@
* @author mturyn
*/
xap.bridges.dojo.DojoWidgetBridge = function() {
- xap.taghandling.AbstractTagImpl.call( this );
+ xap.bridges.basic.AbstractBlackBoxWidgetBridge.call( this );
}
-xap.bridges.dojo.DojoWidgetBridge.prototype = new xap.taghandling.AbstractTagImpl;
+xap.bridges.dojo.DojoWidgetBridge.prototype = new xap.bridges.basic.AbstractBlackBoxWidgetBridge;
xap.bridges.dojo.DojoWidgetBridge.prototype.constructor = xap.bridges.dojo.DojoWidgetBridge ;
@@ -52,21 +53,6 @@
return "xap.bridges.dojo.DojoWidgetBridge";
}
-/**
- * All bridges to Dojo widgets should go through these steps:
- *
- * 1: Create the peer object
- * 2: Handle all the initial attributes
- * 3: Recursively parse the inititial children
- *
-**/
-xap.bridges.dojo.DojoWidgetBridge.prototype.init = function() {
- this.createPeer();
- this.parseInitialAttributes( this.getElement() );
- this.parseInitialChildren( this.getElement() );
- xap.taghandling.AbstractTagImpl.prototype.init.call( this );
- this.getPeer().show();
-}
/**
*
@@ -104,52 +90,24 @@
* occupied by an HTML element, we first create a vanilla
* <DIV/> to be swapped-out with the widget's containing DIV.
*/
-xap.bridges.dojo.DojoWidgetBridge.prototype.createPeer = function() {
- var parent = this.getElement().getParent();
- var handler = this.getUiContentHandler().getHandlerForElement( parent );
- var parentPeer = handler.getPeer();
-
-
-
- // This is necessary if a Dojo widget is the parentPeer:
- // This is probably a kludge, but I don't want to
- // muck around with handler.getPeer() at the moment:
- if( parentPeer.containerNode ){
- parentPeer = parentPeer.containerNode ;
- }
-
-
- // Hmmm...is there a better, generic, way
- // of describing an element that contains
- // a Dojo widget?
- if ( parentPeer.nodeName=="DIV"
- || parentPeer.nodeName=="BODY"
- || parentPeer.nodeName=="TD"
- ) {
- var tmp = document.createElement("DIV") ;
- parentPeer.appendChild(tmp) ;
-
- tmp.parent = parentPeer ;
+xap.bridges.dojo.DojoWidgetBridge.prototype.obtainPeer = function() {
// These properties of the map might be overwritten by a passed-in map:
// (by default, widget i.d. === xap i.d.)
- // This method should be spun off into an overridden
- // getPropertyMap that can be widget-specific:
var propertyMap = {} ;
-
-
-
+
// map xal attributes to widget attributes, where possible;
// when last parameter is extant and "true", remove the
// attributes we're going to handle here from the xal attributes
- // that will be applied to the object after its creation:
+ // that will be applied to the object after its creation (so we
+ // don't set them on creation and then afterward again).
this.mapAllowedInitialPropertiesFromXalToDojo(propertyMap,
this.getElement(),
true
) ;
-
- //alert(propertyMap.title) ;
- // Forbid changing the dojoType if we're in a subclass and "already got one":
+ // Forbid changing the dojoType if we're in a subclass that already has one,
+ // as given by getPeerString()---this is usually the case, but the GenericDojoWidget
+ // will accept a "dojoType" attribute that we'll actually _need_:
var dojoType = null ;
if ( this.getPeerString ){
dojoType = this.getPeerString() ;
@@ -158,19 +116,30 @@
}
delete propertyMap.dojoType ;
+ var parentDomNode = this.getOriginalDomNode() ;
+ var parent = this.getElement().getParent();
+ var handler = this.getUiContentHandler().getHandlerForElement( parent );
+ var parentPeer = handler.getPeer();
+
+
+ // This is necessary if a Dojo widget is the parentPeer:
+ // This is probably a kludge, but I don't want to
+ // muck around with handler.getPeer() at the moment:
+ if( parentPeer.containerNode ){
+ parentPeer = parentPeer.containerNode ;
+ }
+
+ var tmp = document.createElement('div');
+ tmp.parent = parentPeer ;
+ parentPeer.appendChild(tmp) ;
+
if (dojoType == null ){
- // Make this a xap.util.XapException once we're stable:
throw new xap.util.Exception("No dojo type specified by class or passed-in map.") ;
}
// The candy in the middle of the wrapper:
- //xap.util.Utils.interrogate(propertyMap) ;
var peer = dojo.widget.createWidget(dojoType,propertyMap,tmp);
- this.setPeer( peer );
- dojo.event.connect(peer.domNode,this.getEventAttachString(), this,"_onSelectEvent");
- } else {
- xap.bridges.dojo.DojoWidgetBridge.s_log.error("Bogus parent peer:" + parentPeer );
- }
+ this.setPeer(peer ) ;
}
@@ -203,8 +172,9 @@
* <li>textAlign - equivalent of CSS ext-align</li>
* </ul>
*
- * Attributes not handled here are are passed to the
- * superclass attributeSet method.
+ * Attributes not handled here are not passed to the
+ * superclass attributeSet method, since this has an abstract superclass and its parent
+ *
*/
xap.bridges.dojo.DojoWidgetBridge.prototype.attributeSet = function( event ) {
var name = event.getName();
@@ -286,10 +256,7 @@
else if ( name=="textAlign" ){
peer.domNode.style.textAlign=value;
}
- else{
- xap.taghandling.AbstractTagImpl.prototype.attributeSet.call( this, event );
- return ;
- }
+
if( shouldResize ){
peer.onResized() ;
@@ -349,4 +316,13 @@
attrHolder.attributes = postInitAttributes ;
}
}
+
+
+xap.bridges.dojo.DojoWidgetBridge.prototype.getOriginalDomNode = function(){
+ return document.createElement("div") ;
+}
+
+xap.bridges.dojo.DojoWidgetBridge.prototype.getRootDomNode = function(){
+ return this._peer.domNode;
+}