incubator-xap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmarga...@apache.org
Subject svn commit: r555798 - in /incubator/xap/trunk/codebase/src/xap: bridges/dojo/ColumnBridge.js widgets/dojo/TreeTable.js
Date Thu, 12 Jul 2007 22:26:03 GMT
Author: jmargaris
Date: Thu Jul 12 15:26:02 2007
New Revision: 555798

URL: http://svn.apache.org/viewvc?view=rev&rev=555798
Log:
For Michael Mikhaylov: https://issues.apache.org/jira/browse/XAP-489

Modified:
    incubator/xap/trunk/codebase/src/xap/bridges/dojo/ColumnBridge.js
    incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js

Modified: incubator/xap/trunk/codebase/src/xap/bridges/dojo/ColumnBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/bridges/dojo/ColumnBridge.js?view=diff&rev=555798&r1=555797&r2=555798
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/bridges/dojo/ColumnBridge.js (original)
+++ incubator/xap/trunk/codebase/src/xap/bridges/dojo/ColumnBridge.js Thu Jul 12 15:26:02
2007
@@ -36,7 +36,7 @@
  * A bridge class with dojo toolkit box panel peer.
  */
  
-xap.bridges.dojo.ColumnBridge= function() {
+xap.bridges.dojo.ColumnBridge = function() {
 	xap.bridges.dojo.DojoWidgetBridge.call(this);
 }
 
@@ -47,22 +47,192 @@
 );
 
 
+// define xap (non-CSS) attributes
+xap.bridges.dojo.ColumnBridge.prototype._xapAttributes = [
+	'dataType', 'horizontalAlignment', 'backgroundImage'
+];
+
+
+// define CSS style attributes
+xap.bridges.dojo.ColumnBridge.prototype._cssAttributes = [
+	'color','fontFamily','fontSize','fontStyle','fontWeight','textAlign','textDecoration',
+	'backgroundColor','cursor'
+];
+
+// return all attributes
+xap.bridges.dojo.ColumnBridge.prototype.getNewAllowedAttributes = function() {
+	return this._xapAttributes.concat(this._cssAttributes);
+}
+
+
+/**
+ 	This function creates attribute setter and remover functions.
+ 	For setters we use setXxxAttribute(value) pattern.
+ 	For removers we use attributeRemovers.xxx() pattern.
+**/
+xap.bridges.dojo.ColumnBridge.prototype._createAttributeMethods = function() {
+
+	// lets make sure that we have an attributeRemovers property ready
+	if(this.attributeRemovers === undefined) {
+		this.attributeRemovers = {};
+	}
+	
+	// create setters and removers
+	for(var n = 0; n < this._cssAttributes.length; n++) {
+		
+		var attributePropertyName = this._cssAttributes[n];
+		var attributeSetterName = 
+			'set' + attributePropertyName.substring(0,1).toUpperCase() + 
+			attributePropertyName.substring(1) + 'Attribute';
+		
+		// create a setter instance
+		this[attributeSetterName] = function(value) {
+				var name = arguments.callee.attributePropertyName;
+				this['_' + name] = value;
+				if(this._localRule !== undefined) {
+					this._localRule.style[name] = value;
+				}
+			};
+		// save attribute name
+		this[attributeSetterName].attributePropertyName = attributePropertyName;
+
+		// create a remover instance
+		this.attributeRemovers[attributePropertyName] = function() {
+			var name = arguments.callee.attributePropertyName;
+			delete this['_' + name];
+			if(this._localRule !== undefined) {
+				this._localRule.style[name] = '';
+			}
+		};
+		// save attribute name
+		this.attributeRemovers[attributePropertyName].attributePropertyName = attributePropertyName;
+		
+	}// end for()
+	
+};
+
+// call _createAttributeMethods right away to create setters
+// and removers in prototype object
+xap.bridges.dojo.ColumnBridge.prototype._createAttributeMethods();
+
 
 xap.bridges.dojo.ColumnBridge.prototype.getPeerString = function(){
     return "TableColumn" ;
 }
 
- 
-xap.bridges.dojo.ColumnBridge.prototype.getNewAllowedAttributes = function(){
-	return ['dataType'];
-}	
 
-xap.bridges.dojo.ColumnBridge.prototype.setDataTypeAttribute = function( value ){
+// set _dataType
+xap.bridges.dojo.ColumnBridge.prototype.setDataTypeAttribute = function( value ) {
 	this.getPeer()._dataType = value;
+}
+
+// remove _dataType
+xap.bridges.dojo.ColumnBridge.prototype.attributeRemovers.dataTypeAttribute = function( value
) {
+	delete this._dataType;
+	this.getPeer()._dataType = null;
+}
+
+// set _horizontalAlignment
+// Note: it sets text-align on TD/tableColumn, not on SPAN/xapCell
+xap.bridges.dojo.ColumnBridge.prototype.setHorizontalAlignmentAttribute = function( value
) {
+	this._horizontalAlignment = value;
+	this.setTextAlignAttribute(value);
 }	
 
+// remove _horizontalAlignment
+xap.bridges.dojo.ColumnBridge.prototype.attributeRemovers.horizontalAlignment = function()
{
+	delete this._horizontalAlignment;
+	this.attributeRemovers.textAlign.call(this);
+}	
+
+
+// set _backgroundImage
+xap.bridges.dojo.ColumnBridge.prototype.setBackgroundImageAttribute = function( value ) {
+	this._backgroundImage = value;
+	if(this._localRule !== undefined) {
+		this._localRule.style.backgroundImage = 'url(' + value + ')';
+	}
+}	
+
+// remove _horizontalAlignment
+xap.bridges.dojo.ColumnBridge.prototype.attributeRemovers.backgroundImage = function() {
+	delete this._backgroundImage;
+	if(this._localRule !== undefined) {
+		this._localRule.style.backgroundImage = 'url(none)';
+	}
+}	
+
+
+/**
+ *		Add child
+ */
 xap.bridges.dojo.ColumnBridge.prototype.addChild = function(childHandler, index){
 	this.getPeer().setHeader(childHandler.getPeer());
 }
+
+
+/**
+ *	This seems the best place at which to cache the 
+ *  XAL-derived width, if any:
+**/ 
+xap.bridges.dojo.ColumnBridge.prototype.init = function(){
+
+	xap.bridges.dojo.ColumnBridge.superclass.init.call(this) ;
+	
+	/*
+	 *	Create custom CSS class for this column
+	 */
+	var elementId = this.getElement().getAttribute('id');
+	var localCSSClassName = null;
+	
+	if(elementId.indexOf('xap:') != -1) {
+		localCSSClassName = elementId.replace('xap:','tableColumn');
+	} else {
+		localCSSClassName = 'tableColumn' + elementId;
+	}
+	
+	// only for TDs
+	var selector = 'td.' + localCSSClassName;
+	
+	// insert an empty rule
+	dojo.html.insertCssRule(selector, ' ');
+	this._localRule = xap.util.CssUtils.getCSSRule(selector);
+	this.getPeer()._localCSSClassName = localCSSClassName;
+
+	/**
+	 *	Attribute setters are called before init(),
+	 *	so we need to assign all attributes here
+	**/
+	for(var n = 0; n < this._cssAttributes.length; n++) {
+		var attributePropertyName = this._cssAttributes[n];
+		var value = this['_' + attributePropertyName];
+		if( value !== undefined ) {
+			this._localRule.style[attributePropertyName] = value;
+		}
+	}
+	
+	// backgroundImage too because it uses url()
+	if(this._backgroundImage !== undefined) {
+		this._localRule.style.backgroundImage = 'url(' + this._backgroundImage + ')';
+	}
+	
+};
+
+
+xap.bridges.dojo.ColumnBridge.prototype.unload = function(){
+	
+	// attempt to destroy global rule instance
+	var styleSheet = this._localRule.parentStyleSheet;
+	for(var n = 0; n < styleSheet.length; n++) {
+		if(styleSheet[n] == this._localRule) {
+			styleSheet.deleteRule(n);
+			delete this._localRule;
+			break;
+		}
+	}
+	
+	xap.bridges.dojo.ColumnBridge.superclass.unload.call(this) ;
+};
+
 
 

Modified: incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js?view=diff&rev=555798&r1=555797&r2=555798
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js (original)
+++ incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js Thu Jul 12 15:26:02 2007
@@ -729,7 +729,15 @@
 		this._table = table;
 	},
 
+	getTable: function() {
+		return ( this._table );
+	},
+
 	onClickCallback : function(){
+	    sort();
+	},
+	
+	sort : function(){
 		if (this._table){
 			this._table.sortColumn(this);
 		}
@@ -782,8 +790,15 @@
 	//thing, it should probably have something like:
 	//getText() function, domNode, getSortValue() function, etc,
 	//right now we don't have a good way of knowing what the text is
+	// @param cell DOM node from CellBridge instance
+	// @param cellInfo object from CellBridge instance
+	// @param cellCount number of cells added to the Row so far
 	addCell : function( cell , cellInfo){
 		this._cellInfo.push(cellInfo);
+		
+		// get current <td> count before we insert another one
+		var tdCount = this.domNode.childNodes.length;
+		
 		var td = document.createElement("td");
 		this.domNode.appendChild(td);
 		td.style.whiteSpace = "nowrap";
@@ -798,10 +813,17 @@
 			td.align = cell.style.textAlign;
 		}
 		
-		if (this._table && this._table._tableCellClass){
-			dojo.html.addClass(td,this._table._tableCellClass);
+		// Add column CSS class
+		// Use tdCount variable to locate column
+		if (this._table && this._table._columns) {
+			dojo.html.addClass(td, this._table._columns[tdCount]._localCSSClassName);
 		}
-		
+
+		// Add regular cell CSS class
+		if (this._table && this._table._tableCellClass) {
+			dojo.html.addClass(td, this._table._tableCellClass);
+		}
+						
 		//TODO should we use style.textAlign instead of this
 		//everywhere???
 		if (!this._indentSpan){



Mime
View raw message