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/06/29 04:03:20 UTC
svn commit: r417934 - in /incubator/xap/trunk/src/xap/bridges/dojo: ./
DojoButtonBridge.js DojoContentPaneBridge.js DojoWidgetBridge.js
Author: mturyn
Date: Wed Jun 28 21:03:19 2006
New Revision: 417934
URL: http://svn.apache.org/viewvc?rev=417934&view=rev
Log:
Initial code for these bridges; still need to integrate them into the newer code.
Added:
incubator/xap/trunk/src/xap/bridges/dojo/
incubator/xap/trunk/src/xap/bridges/dojo/DojoButtonBridge.js
incubator/xap/trunk/src/xap/bridges/dojo/DojoContentPaneBridge.js
incubator/xap/trunk/src/xap/bridges/dojo/DojoWidgetBridge.js
Added: 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=417934&view=auto
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/dojo/DojoButtonBridge.js (added)
+++ incubator/xap/trunk/src/xap/bridges/dojo/DojoButtonBridge.js Wed Jun 28 21:03:19 2006
@@ -0,0 +1,140 @@
+/*
+ * 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.
+ *
+ */
+
+ /**
+ * @fileoverview
+ *
+ * A bridge class that controls a dojo Button peer.
+ */
+
+/**
+ * Creates a DojoButtonBridge.
+ *
+ *
+ * @class DojoButtonBridge is the bridge between an XML element
+ * representing a button and the Dojo Button class.
+ *
+ * @author jmargaris
+ * @author mturyn
+ */
+
+ Xap.require("xap.bridges.dojo.DojoWidgetBridge");
+
+ /**
+ * @fileoverview
+ *
+ * A bridge class with dojo toolkit button peer.
+ */
+
+DojoButtonBridge= function() {
+ DojoWidgetBridge.call(this);
+}
+
+DojoButtonBridge.prototype = new DojoWidgetBridge;
+
+
+DojoButtonBridge.prototype.constructor=DojoButtonBridge ;
+
+DojoButtonBridge.s_log = LogFactory.getLog( "DojoButtonBridge" );
+
+DojoButtonBridge.prototype.toString = function() {
+ return "DojoButtonBridge";
+}
+
+
+
+DojoButtonBridge.prototype.getPeerString = function(){
+ return "Button" ;
+}
+
+
+
+
+/**
+ * The callback for the selection listener on DojoButton.
+ * When this is called we fire an "onCommand" event.
+ */
+DojoButtonBridge.prototype._onSelectEvent = function( event ) {
+ this.fireEvent("onCommand");
+}
+
+
+/**
+ * This method is called whenever an attribute
+ * on the XML element that maps to this bridge class
+ * is changed.
+ * <ul>
+ * <li>text - the HTML text of the label</li>
+ * </ul>
+ *
+ * Attributes not handled here are are passed to the
+ * superclass attributeSet method.
+ */
+DojoButtonBridge.prototype.attributeSet = function( event ) {
+ var name = event.getName();
+ var value = event.getNewValue();
+ var peer = this.getPeer();
+
+ if (name=="text"){
+ DojoButtonBridge.changeCaption(peer,value) ;
+ }
+ else if(name=="fontColor"){
+ peer.setTextForeground(value);
+ }
+ else if(name=="image"){
+ //peer.setImage(value);
+ peer.activeImg=value ;
+ }
+ else if (name=="onClick"){
+ dojo.event.connect(peer, 'onClick', value)
+ }
+ else if (name=="onCommand"){
+ dojo.event.connect(peer, 'onCommand', value)
+ }
+ else{
+ DojoWidgetBridge.prototype.attributeSet.call( this, event );
+ }
+ peer.onResized() ;
+}
+
+
+
+
+DojoButtonBridge.changeCaption = function(aButton,newCaption){
+ var currentCaption = aButton.caption ;
+ if ( newCaption == aButton.caption ){
+ return ;
+ }
+
+ var possibleHolders = aButton.containerNode.childNodes ;
+
+ if (possibleHolders.length==0){
+ // Need to have a child node to hold the caption,
+ // won't have one first time out:
+ aButton.caption = newCaption ;
+ aButton.fillInTemplate() ;
+ return ;
+ }
+
+ for(var ii=0; ii < possibleHolders.length ; ++ii){
+ if (possibleHolders[ii].nodeValue == currentCaption){
+ possibleHolders[ii].nodeValue = newCaption ;
+ aButton.caption = newCaption ;
+ break ;
+ }
+ }
+}
Added: incubator/xap/trunk/src/xap/bridges/dojo/DojoContentPaneBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/dojo/DojoContentPaneBridge.js?rev=417934&view=auto
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/dojo/DojoContentPaneBridge.js (added)
+++ incubator/xap/trunk/src/xap/bridges/dojo/DojoContentPaneBridge.js Wed Jun 28 21:03:19 2006
@@ -0,0 +1,102 @@
+/*
+ * 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.
+ *
+ */
+
+ /**
+ * @fileoverview
+ *
+ * A bridge class that controls a dojo ContentPane peer. So far,
+ * doesn't seem to load anything successfully, which might just be a matter
+ * of setting permissions....
+ */
+
+/**
+ * Creates a DojoContentPaneBridge.
+ *
+ *
+ * @class DojoContentPaneBridge is the bridge between an XML element
+ * representing a button and the DojoContentPane Zimbra class.
+ *
+ * @author jmargaris
+ * @author mturyn
+ */
+
+Xap.require("xap.bridges.dojo.DojoWidgetBridge");
+
+ /**
+ * @fileoverview
+ *
+ * A bridge class with dojo contentPane peer.
+ */
+
+DojoContentPaneBridge = function() {
+ DojoWidgetBridge.call(this);
+}
+
+DojoContentPaneBridge.prototype = new DojoWidgetBridge;
+
+
+DojoContentPaneBridge.prototype.constructor=DojoContentPaneBridge ;
+
+DojoContentPaneBridge.s_log = LogFactory.getLog( "DojoContentPaneBridge" );
+
+DojoContentPaneBridge.prototype.toString = function() {
+ return "DojoContentPaneBridge";
+}
+
+/**
+ * Provides the name used to create the peer component
+ * that this bridge controls.
+ */
+DojoContentPaneBridge.prototype.getPeerString = function(){
+ return "ContentPane" ;
+}
+
+
+
+
+/**
+ * This method is called whenever an attribute
+ * on the XML element that maps to this bridge class
+ * is changed.
+ * <ul>
+ * <li>text - the HTML text of the label</li>
+ * </ul>
+ *
+ * Attributes not handled here are are passed to the
+ * superclass attributeSet method.
+ */
+DojoContentPaneBridge.prototype.attributeSet = function( event ) {
+ var name = event.getName();
+ var value = event.getNewValue();
+ var peer = this.getPeer();
+
+ if (name=="src"){
+ //peer.setImage(value);
+ try {
+ peer.setUrl(value) ;
+ } catch (ex){
+ alert("Pane can't load '"+value+"':\n"+ex) ;
+ }
+ }
+ else{
+ DojoWidgetBridge.prototype.attributeSet.call( this, event );
+ }
+
+}
+
+
+
Added: 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=417934&view=auto
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/dojo/DojoWidgetBridge.js (added)
+++ incubator/xap/trunk/src/xap/bridges/dojo/DojoWidgetBridge.js Wed Jun 28 21:03:19 2006
@@ -0,0 +1,225 @@
+/*
+ * 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.dojo.DojoWidgetBridge");
+
+ /**
+ * @fileoverview
+ *
+ * A bridge class that controls a generic dojo widget's peer; here
+ * for now as an abstract superclass.
+ */
+
+
+ /**
+ * Creates a DojoWidgetBridge.
+ *
+ *
+ * @class DojoWidgetBridge is the bridge between an XML element
+ * representing a control and a subclass of DojoWidget. This class
+ * is typically not used directly but is extended by other classes
+ * for its subclasses.
+ *
+ * @author jmargaris
+ * @author mturyn
+ */
+DojoWidgetBridge = function() {
+ AbstractTagImpl.call( this );
+}
+
+DojoWidgetBridge.prototype = new AbstractTagImpl;
+
+DojoWidgetBridge.prototype.constructor = DojoWidgetBridge ;
+
+DojoWidgetBridge.s_log = LogFactory.getLog( "DojoWidgetBridge" );
+
+
+DojoWidgetBridge.prototype.toString = function() {
+ return "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
+ *
+**/
+DojoWidgetBridge.prototype.init = function() {
+ this.createPeer();
+ this.parseInitialAttributes( this.getElement() );
+ this.parseInitialChildren( this.getElement() );
+ AbstractTagImpl.prototype.init.call( this );
+ this.getPeer().show();
+}
+/**
+ *
+ * Since the <code>dojo.widget.createWidget()</code>
+ * is good at creating a widget into the place in a DOM previously
+ * occupied by an HTML element, we first create a vanilla
+ * <DIV/> to be swapped-out with the widget's containing DIV.
+ */
+DojoWidgetBridge.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 Dojo widget?
+ if ( parentPeer.localName=="DIV"
+ || parentPeer.localName=="BODY"
+ || parentPeer.localName=="TD"
+ ) {
+ var tmp = document.createElement("DIV") ;
+ parentPeer.appendChild(tmp) ;
+ var widgetId = this.getElement().getAttribute("id") ;
+ var dojoType = this.getPeerString() ;
+ var peer = dojo.widget.createWidget(dojoType, {widgetId:widgetId,position:"absolute"},tmp);
+
+ this.setPeer( peer );
+ //peer.addSelectionListener(new AjxListener(this, this._onSelectEvent));
+ } else {
+ DojoWidgetBridge.s_log.error("Bogus parent peer:" + parentPeer );
+ }
+}
+
+
+
+
+/**
+ * This method is called whenever an attribute
+ * on the XML element that maps to this bridge class
+ * is changed. DojoWidgetBridge handles the following attributes:
+ * <ul>
+ * <li>x - the x location</li>
+ * <li>y - the y location</li>
+ * <li>width - the width</li>
+ * <li>height - the height</li>
+ * <li>cursor - a CSS cursor name</li>
+ * <li>enabled - true/false</li>
+ * <li>tooltipText - html text for toolip</li>
+ * <li>backgroundColor - equivalent of CSS background-color</li>
+ * <li>borderWidth - equivalent of CSS border-width</li>
+ * <li>borderStyle- equivalent of CSS border-style</li>
+ * <li>borderColor - equivalent of CSS border-color</li>
+ * <li>color - equivalent of CSS color</li>
+ * <li>fontFamily - equivalent of CSS font-family</li>
+ * <li>fontSize - equivalent of CSS font-size</li>
+ * <li>fontStyle - equivalent of CSS font-style</li>
+ * <li>fontWeight- equivalent of CSS font-weight</li>
+ * <li>fontVariant- equivalent of CSS font-variant</li>
+ * <li>textDecoration- equivalent of CSS text-decoration</li>
+ * <li>margin - equivalent of CSS margin</li>
+ * <li>padding - equivalent of CSS padding</li>
+ * <li>textAlign - equivalent of CSS ext-align</li>
+ * </ul>
+ *
+ * Attributes not handled here are are passed to the
+ * superclass attributeSet method.
+ */
+DojoWidgetBridge.prototype.attributeSet = function( event ) {
+ var name = event.getName();
+ var value = event.getNewValue();
+ var peer = this.getPeer();
+ var shouldResize=false ;
+ if ( name=="x" ) {
+ // peer.setLocation( value, null );
+ peer.domNode.style.left = value ;
+ shouldResize = true ; ;
+ }
+ else if (name=="y") {
+ //peer.setLocation( null, value );
+ peer.domNode.style.top = value ;
+ shouldResize = true ; ;
+ }
+ else if (name=="width") {
+ //peer.setSize( value, null );
+ //peer.setWidth(value) ;
+ peer.containerNode.style.width=value ;
+ shouldResize = true ; ;
+ }
+ else if ( name=="height"){
+ //peer.setSize( null, value );
+ //peer.setHeight(value) ;
+ peer.containerNode.style.height=value ;
+ shouldResize = true ; ;
+ }
+ else if (name=="cursor"){
+ peer.setCursor(value);
+ }
+ else if (name=="enabled"){
+ peer.setEnabled(value=="false"?false:true, true);
+ }
+ else if (name=="tooltipText"){
+ peer.setToolTipContent(value);
+ }
+ //all of these map to CSS styles of the same name
+ else if ( name=="backgroundColor" ){
+ peer.domNode.style.backgroundColor=value;
+ }
+ else if ( name=="borderWidth" ){
+ peer.domNode.style.borderWidth=value;
+ }
+ else if ( name=="borderStyle" ){
+ peer.domNode.style.borderStyle=value;
+ }
+ else if ( name=="borderColor" ){
+ peer.domNode.style.borderColor=value;
+ }
+ else if ( name=="color" ){
+ peer.domNode.style.color=value;
+ }
+ else if ( name=="fontFamily" ){
+ peer.domNode.style.fontFamily=value;
+ }
+ else if ( name=="fontSize" ){
+ peer.domNode.style.fontSize=value;
+ }
+ else if ( name=="fontStyle" ){
+ peer.domNode.style.fontStyle=value;
+ }
+ else if (name=="fontWeight"){
+ peer.domNode.style.fontWeight=value;
+ }
+ else if ( name=="margin" ){
+ peer.domNode.style.margin=value;
+ }
+ else if ( name=="textDecoration" ){
+ peer.domNode.style.textDecoration=value;
+ }
+ else if ( name=="padding" ){
+ peer.domNode.style.padding=value;
+ }
+ else if ( name=="position" ){
+ peer.domNode.style.position=value;
+ peer.conatainerNode.style.position=value;
+ }
+ else if ( name=="textAlign" ){
+ peer.domNode.style.textAlign=value;
+ }
+ else{
+ AbstractTagImpl.prototype.attributeSet.call( this, event );
+ return ;
+ }
+
+ if( shouldResize ){
+ peer.onResized() ;
+ }
+
+}