incubator-xap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mtu...@apache.org
Subject svn commit: r426265 - in /incubator/xap/trunk: WebContent/examples/ WebContent/examples/basic/ src/xap/bridges/basic/ src/xap/taghandling/
Date Thu, 27 Jul 2006 22:01:05 GMT
Author: mturyn
Date: Thu Jul 27 15:01:05 2006
New Revision: 426265

URL: http://svn.apache.org/viewvc?rev=426265&view=rev
Log:
Added the basics for a simple bridge wrapping an HtmlElement, destined to be a superclass
for the preponderance of widgets that come wrapped in DIVs.

A crude example fashioned for it.

Added:
    incubator/xap/trunk/WebContent/examples/basic/
    incubator/xap/trunk/WebContent/examples/basic/dom0.html   (with props)
    incubator/xap/trunk/WebContent/examples/basic/dom0.js   (with props)
    incubator/xap/trunk/WebContent/examples/basic/dom0.xal   (with props)
    incubator/xap/trunk/WebContent/examples/basic/dom0Handler.js   (with props)
    incubator/xap/trunk/src/xap/bridges/basic/DomNodeBridge.js   (with props)
Modified:
    incubator/xap/trunk/WebContent/examples/index.html
    incubator/xap/trunk/src/xap/taghandling/plugin.xml

Added: incubator/xap/trunk/WebContent/examples/basic/dom0.html
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/basic/dom0.html?rev=426265&view=auto
==============================================================================
--- incubator/xap/trunk/WebContent/examples/basic/dom0.html (added)
+++ incubator/xap/trunk/WebContent/examples/basic/dom0.html Thu Jul 27 15:01:05 2006
@@ -0,0 +1,110 @@
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+    <title>Wrapped DOM example 0</title>
+
+	<style type="text/css">
+      <!--
+          @import url(../../css/xapDefault.css);
+      -->
+    </style>
+    
+	<!-- Keep dojo from trying to scan this whole page for dojoType'd tags: -->
+	<script type="text/javascript">
+		djConfig = {
+			parseWidgets: false
+		};
+	</script>    
+	
+    <script language="JavaScript" type="text/javascript" src="../../src/dojo/dojo.js"></script>
+    <script language="JavaScript" type="text/javascript" src="../../src/xap/util/Utils.js"></script>
+    <script language="JavaScript" type="text/javascript" src="../../src/xap/Xap.js"></script>
+    
+
+    <script language="JavaScript" type="text/javascript"> 
+    	// These should be in this order, as this is what their dependencies
+    	// look like   	
+		Xap.addDebuggables( 
+						"xap.taghandling.AbstractTagImpl",
+						"xap.bridges.dojo.DojoWidgetBridge",		
+						"xap.bridges.dojo.DojoButtonBridge",
+						"xap.bridges.basic.DomNodeBridge"
+							) ;
+    </script>
+   
+    <script language="JavaScript" type="text/javascript">
+    	Xap.bootstrap( "../../", true );
+  	</script>
+
+    	
+
+    	
+  	
+  	  <!-- SECTION 2 -->
+	<script type="text/javascript">
+		// Load Dojo's code concerned with a Button or Button2 widget,
+		// including the object dojo.widget needed to create one
+		dojo.require("dojo.widget.*");   
+		dojo.require("dojo.event.*");            
+		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>
+ 
+ 
+ </head>
+ 
+ <body onLoad="document.attachOurEvent();Xap.scanPage();if(xap.showStatus){xap.showStatus();};document.attachOurEvent();">
+	<script type="text/javascript">
+		DBG = new AjxDebug( AjxDebug.NONE, null, false ); 
+	</script>
+	<h1>Wrapped DIV managed by a xaplet embedded in another table cell:</h1>
+	
+	<table id="bigtable" border="4px" borderColor="#8866AA" width="80%" height="80%"
+		style="left:10%;top:10%"
+		cellpadding="20em" cellspacing="2px"
+		>
+		<tr><th width="30%">0.</th><th>1.</th></tr>
+		<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>
+			</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>
+	</table>
+
+
+	<!-- MyApp as the app name is a top-level alias for session
+	as this event handler illustrates -->	
+	<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>

Propchange: incubator/xap/trunk/WebContent/examples/basic/dom0.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/xap/trunk/WebContent/examples/basic/dom0.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/basic/dom0.js?rev=426265&view=auto
==============================================================================
--- incubator/xap/trunk/WebContent/examples/basic/dom0.js (added)
+++ incubator/xap/trunk/WebContent/examples/basic/dom0.js Thu Jul 27 15:01:05 2006
@@ -0,0 +1,41 @@
+xap.showStatus = function(){
+	var session = window["MyApp"] ;
+
+	var node = session.domContainer ;
+	var front = "" ;
+	var path = "";
+	while( node.parentNode ){
+		var siblings = node.parentNode.childNodes ;
+		if (path.length>0){
+			path = "<strong>/</strong>" + path  ;
+		}
+		var idx = -1 ;
+		var nodeLikeThisOneName= node.nodeName ;
+		var nodeLikeThisOneNameIndex = -1 ;
+		// Which node is this (e.g., which TR child of a TBODY?)
+		while( ++idx < siblings.length ){
+			if( nodeLikeThisOneName == siblings[idx].nodeName ){
+			// This is {<last count>+1} node like this under
+			// the parent (e.g., the 3rd <td> under a <tr>)
+				++nodeLikeThisOneNameIndex ;
+			}
+			if( siblings[idx] == node ){
+				path = "<strong>" +node.nodeName +"</strong>" +"<font color='#4444FF'>["+nodeLikeThisOneNameIndex+"]</font>"
 + path ;
+				break ;
+			}
+		}	
+		node = node.parentNode ;				
+	}
+	document.getElementById("xapStat").innerHTML =
+					"Found xap tag with <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; appName:"

+						+ session.appName
+						+ ", <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; and source " 
+						+ session.src 
+						+ "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; under element: "
+						+ "<code>"+path +"</code>"
+							;
+}	
+
+
+
+		

Propchange: incubator/xap/trunk/WebContent/examples/basic/dom0.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/xap/trunk/WebContent/examples/basic/dom0.xal
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/basic/dom0.xal?rev=426265&view=auto
==============================================================================
--- incubator/xap/trunk/WebContent/examples/basic/dom0.xal (added)
+++ incubator/xap/trunk/WebContent/examples/basic/dom0.xal Thu Jul 27 15:01:05 2006
@@ -0,0 +1,35 @@
+<xal xmlns="http://www.openxal.org/xal"> 
+
+
+	<mco:mco 
+		xmlns:mco="http://www.openxal.org/mco" 
+		id="handler" 
+		src="dom0Handler"
+	/>
+
+
+
+  <xm:modifications xmlns:xm="http://www.openxal.org/xmodify">
+    <xm:append select="/xal">
+		<dom xmlns="http://www.dojotoolkit.org/" 		
+				elementId="targetNode"
+				bgColor="#eeddFF"
+				color="#ffeeff"
+				innerHTML="Mouse over me!"
+				valign="middle"
+				align="center"
+		/>	
+   	</xm:append> 	  	
+
+	<xm:append select="/xal">
+		<button xmlns="http://www.dojotoolkit.org/" 
+			text="Button in middle of the application." 	
+			color="#aa0000"
+			id="button0"
+			backgroundColor="#00aaaa"
+			onCommand="mco:handler.onClick(this)"
+		/> 
+   	</xm:append> 	  
+   	
+  </xm:modifications>
+</xal>
\ No newline at end of file

Propchange: incubator/xap/trunk/WebContent/examples/basic/dom0.xal
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/xap/trunk/WebContent/examples/basic/dom0Handler.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/basic/dom0Handler.js?rev=426265&view=auto
==============================================================================
--- incubator/xap/trunk/WebContent/examples/basic/dom0Handler.js (added)
+++ incubator/xap/trunk/WebContent/examples/basic/dom0Handler.js Thu Jul 27 15:01:05 2006
@@ -0,0 +1,38 @@
+// For MCO:
+function dom0Handler() { }
+
+dom0Handler.prototype = new Object() ;
+
+
+dom0Handler.colours = ["<font color='#660000'>",
+						"<font color='#aa00aa'>",
+						"<font color='#000000'>"
+						];						
+							
+dom0Handler.prototype.onClick = function (srcNode) {
+//xap.util.Utils.interrogate(srcNode) ;
+	var attributes = srcNode.attributes;
+	
+	var i0 = Math.floor(3*Math.random() );
+	var i1 = (i0+1)%3 ;
+	var i2 = (i0+2)%3 ;
+
+	var resultString = "<br/><br/>"+dom0Handler.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]
+							+attributes[ii].nodeName
+							+"</font>" ;
+			resultString +=":"+ dom0Handler.colours[i2]
+								+attributes[ii].nodeValue+"</font>" ;				
+		}
+	}
+	xap.showStatus() ;
+	var ticker = document.getElementById("xapStat") ;
+	ticker.innerHTML = ticker.innerHTML + resultString ;
+	
+}
\ No newline at end of file

Propchange: incubator/xap/trunk/WebContent/examples/basic/dom0Handler.js
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/xap/trunk/WebContent/examples/index.html
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/index.html?rev=426265&r1=426264&r2=426265&view=diff
==============================================================================
--- incubator/xap/trunk/WebContent/examples/index.html (original)
+++ incubator/xap/trunk/WebContent/examples/index.html Thu Jul 27 15:01:05 2006
@@ -20,7 +20,9 @@
       <li><a href="html-xmodify/index.html">Macro and xModify running against
the HTML DOM</a></li><br>
 
       <li><a href="dojo/dojoExample_0.html">Dojo example 0</a></li>
-      <li><a href="dojo/dojo1.html">Dojo example 1</a></li>     

+      <li><a href="dojo/dojo1.html">Dojo example 1</a></li><br/>
   
+      
+      <li><a href="basic/dom0.html">Wrapped dom example 0</a></li>
 </ul>
   </body>
 </html>

Added: 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=426265&view=auto
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/basic/DomNodeBridge.js (added)
+++ incubator/xap/trunk/src/xap/bridges/basic/DomNodeBridge.js Thu Jul 27 15:01:05 2006
@@ -0,0 +1,119 @@
+/*
+ * 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.DomNodeBridge"); 
+/**
+ * @fileoverview
+ * 
+ * A bridge class that controls a blob of html.
+ */
+
+/**
+ * Creates a xap.bridges.basic.DomNodeBridge.
+ * 
+ * 
+ * @class xap.bridges.basic.DomNodeBridge is the bridge between an XML element
+ * representing a blob of html.
+ * 
+ * @constructor
+ * 
+ * @author mturyn
+ */
+xap.bridges.basic.DomNodeBridge = function() {
+	xap.taghandling.AbstractTagImpl.call( this );
+}
+
+xap.bridges.basic.DomNodeBridge.prototype = new xap.taghandling.AbstractTagImpl;
+
+xap.bridges.basic.DomNodeBridge.s_log = xap.util.LogFactory.getLog( "xap.bridges.basic.DomNodeBridge"
);
+
+xap.bridges.basic.DomNodeBridge.prototype.toString = function() {
+	return "xap.bridges.basic.DomNodeBridge";
+}
+
+/**
+ * All bridges to DwtControls should go through these steps:
+ * 
+ * 1: Create the peer object
+ * 2: Handle all the initial attributes
+ * 3: Recursively parse the inititial children
+ * 
+ * It's not clear if we need zShow everwhere. (probably not)
+ * Also the workflow here is a bit strange in that when you create
+ * DwtControls you create them with a parent. Typically with most component
+ * frameworks the parent is responsible for adding the child control
+ * when the parent gets the onChildAdded() event. But with the Zimbra
+ * hierarchy the child adds itself to the parent in it's createPeer(),
+ * before onChildAdded() is ever called.
+ * 
+ * One effect of this is that instead of hooking up the hierarchy 
+ * from tail to head we do it from head to tail.
+ */
+xap.bridges.basic.DomNodeBridge.prototype.init = function() {
+	this.createPeer();
+	this.parseInitialAttributes( this.getElement() );
+	this.parseInitialChildren( this.getElement() );
+	xap.taghandling.AbstractTagImpl.prototype.init.call( this );
+}
+
+/**
+ * Creates the peer component that this bridge controls.
+ */
+xap.bridges.basic.DomNodeBridge.prototype.createPeer = function() {
+	var parent = this.getElement().getParent();
+	var handler = this.getUiContentHandler().getHandlerForElement( parent );
+	var parentPeer = handler.getPeer();
+	
+	var elementId = this.getElement().getAttribute("elementId")  ;
+	
+	if ( true  ) {
+    	try {
+    	    var peer = document.getElementById(elementId) ;
+    		this.setPeer(peer) ;
+        } catch ( e ) {
+        	alert(e);
+    	}
+	} else {
+		//xap.bridges.zimbra.DwtButtonBridge.s_log.error("Bogus parent peer:" + parentPeer );
+	}
+}
+
+/**
+  * Attributes not handled here are so far ignored.
+* */
+xap.bridges.basic.DomNodeBridge.prototype.attributeSet = function( event ) {
+		var name = event.getName();
+		var value = event.getNewValue();
+		var peer = this.getPeer() ;
+		
+		if(name=="innerHTML"){
+			peer.innerHTML = value ;
+		}
+		
+	// Prefer setters to direct field settings, node attributes last?:
+		var setterName = "set" + name.substring(0,1).toUpperCase() +name.substring(1) ;
+		if( peer[setterName]){
+			peer[setterName].call( peer, value) ;
+		} else if( peer.style[setterName]){
+			(peer.style[setterName]).call( peer.style, value) ;
+		} else {
+			peer.setAttribute(name,value) ;
+		}
+}
+	
+
+

Propchange: incubator/xap/trunk/src/xap/bridges/basic/DomNodeBridge.js
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/xap/trunk/src/xap/taghandling/plugin.xml
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/taghandling/plugin.xml?rev=426265&r1=426264&r2=426265&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/taghandling/plugin.xml (original)
+++ incubator/xap/trunk/src/xap/taghandling/plugin.xml Thu Jul 27 15:01:05 2006
@@ -16,6 +16,7 @@
 		<mapping class="xap.bridges.zimbra.DwtVerticalLayoutPanelBridge" name="verticalLayoutPanel"/>
 		<mapping class="xap.bridges.zimbra.DwtHorizontalLayoutPanelBridge" name="horizontalLayoutPanel"/>
 		
+		
 		<mapping class="xap.bridges.basic.TextViewBridge" name="textView"/>
 	</tag-mappings>
 	
@@ -24,7 +25,11 @@
 		<mapping class="xap.bridges.dojo.DojoContentPaneBridge" name="contentPane"/>	
 		<mapping class="xap.bridges.dojo.DojoFloatingPaneBridge" name="floatingPane"/>	
 		<mapping class="xap.bridges.dojo.DojoGenericWidgetBridge" name="generic"/>
-		<mapping class="xap.bridges.dojo.DojoLayoutPaneBridge" name="layoutPane"/>						
		
+		<mapping class="xap.bridges.dojo.DojoLayoutPaneBridge" name="layoutPane"/>	
+		
+		
+		<mapping class="xap.bridges.basic.DomNodeBridge" name="dom"/>
+										
 	</tag-mappings>	
 	
 	



Mime
View raw message