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 jm...@apache.org on 2007/10/23 01:36:13 UTC
svn commit: r587355 -
/incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js
Author: jmargaris
Date: Mon Oct 22 18:36:13 2007
New Revision: 587355
URL: http://svn.apache.org/viewvc?rev=587355&view=rev
Log:
changes from michael M
Modified:
incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js
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?rev=587355&r1=587354&r2=587355&view=diff
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js (original)
+++ incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js Mon Oct 22 18:36:13 2007
@@ -125,6 +125,7 @@
* the widths of columns and headers match up.
*/
_resizeTable: function(){
+
// In some multi-threaded scenarios, _resizeTable can fire when the peer columns/headers
// are out of synch with the available Xap columns, in this instance, we should call
// rebuild to synchronize the columns in this condition
@@ -169,14 +170,14 @@
//In IE get/set of column width dynamically doesn't seem to work
//too well so use first row instead
if (dojo.render.html.ie){
- headerWidth = this.headerRow.childNodes[i].offsetWidth;
+ headerWidth = this.headerRow.childNodes[i].clientWidth;
if (firstRow && firstRow.childNodes[i]) {
- contentWidth = firstRow.childNodes[i].offsetWidth;
+ contentWidth = firstRow.childNodes[i].clientWidth;
}
}
else {
- headerWidth = this.headerTable.childNodes[i].offsetWidth;
- contentWidth = this.table.childNodes[i].offsetWidth;
+ headerWidth = this.headerTable.childNodes[i].clientWidth;
+ contentWidth = this.table.childNodes[i].clientWidth;
}
finalWidth = Math.max(headerWidth, contentWidth);
@@ -383,9 +384,6 @@
this._rebuildHead();
this._rebuildBody();
- window.clearTimeout(this._rebuildTableTask);
- this._rebuildTableTask = null;
- this._resizeTable();
},
_rebuildRow: function( row, depth, alternateRow ){
@@ -396,38 +394,54 @@
}
},
- //note this is kind of crappy as we recolor the entire table
- //even if we expanded only the very last row. If we add/remove/expand/contract
+ //If we add/remove/expand/contract
//a row we only really need to start recoloring at that node
- //TODO efficiency
- _recolorAlternateRows: function(){ //debug::this.loggit('_recolorAlternateRows') ;
+ _recolorAlternateRows: function(row){
+
if (this._alternateRowClass === undefined) { return; }
+
var isAlternateRow = false;
- for (var i = 0; i < this._rows.length; i++){
- isAlternateRow = this._recolorRow(this._rows[i], isAlternateRow);
+
+ // recolor only subsequent rows
+ var i = (row === undefined) ? 0 : xap.util.ArrayHelper.indexOf(this._rows, row) + 1;
+ while (i < this._rows.length){
+ var current = this._rows[i++];
+ isAlternateRow = this._recolorRow(current, isAlternateRow);
}
},
- _recolorRow: function( row, isAlternateRow ){
+ _recolorRow: function(row, isAlternateRow ) {
+
+
+ // do nothing if invisible
var style = row.domNode.style;
if(style.visibility == "hidden" && style.display == "none") {
return isAlternateRow;
}
-
- if (isAlternateRow){
- xap.util.CssUtils.addClass(row.domNode,this._alternateRowClass);
- }
- else{
- xap.util.CssUtils.removeClass(row.domNode,this._alternateRowClass);
- }
+
+ // only update style when needed
+ if(row._alternateRow != isAlternateRow) {
- isAlternateRow = ! isAlternateRow;
+ // save new value
+ row._alternateRow = isAlternateRow;
- if (!row._expanded) return isAlternateRow;
+ if (isAlternateRow) {
+ xap.util.CssUtils.setClass(row.domNode, this._alternateRowClass);
+ } else {
+ xap.util.CssUtils.setClass(row.domNode, ' ');
+ }
- for (var i = 0; i<row._rows.length; i++){
- isAlternateRow = this._recolorRow(row._rows[i], isAlternateRow);
+ // flip row
+ isAlternateRow = ! isAlternateRow;
+
+ // recolor children
+ if (row._expanded) {
+ for (var i = 0; i<row._rows.length; i++){
+ isAlternateRow = this._recolorRow(row._rows[i], isAlternateRow);
+ }
+ }
}
+
return isAlternateRow;
},
@@ -644,8 +658,7 @@
*/
onExpandRow : function(row, expanded){
- this._recolorAlternateRows();
- //event hook
+ this._recolorAlternateRows( row );
},
onScrollCallback : function(event){
@@ -812,9 +825,6 @@
// initiates table resize
setStatedWidth: function(val){
this._sStatedWidth = val ;
- if(this._table) {
- this._table._resizeTableLater();
- }
},
// turns visibility on and off
@@ -896,7 +906,7 @@
var tdCount = this.domNode.childNodes.length;
var td = document.createElement("td");
-
+ this.domNode.appendChild(td);
td.style.whiteSpace = "nowrap";
td.align="left";
td.valign = "top";
@@ -907,17 +917,29 @@
}
if ( cell.style.textAlign ) {
td.align = cell.style.textAlign;
- } // Add column CSS class
- //TODO concatenate class names and use setClass instead of addClass
+ }
- // Use tdCount variable to locate column
- if (this._table && this._table._columns && this._table._columns.length > 0 ) {
- xap.util.CssUtils.addClass(td, this._table._columns[tdCount]._localCSSClassName);
- }
+ // Add CSS
+ if(this._table) {
+
+ var cssClassNames = '';
+
+ // Add column CSS class
+ // Use tdCount variable to locate column
+ if (this._table._columns && this._table._columns[tdCount]) {
+ cssClassNames = this._table._columns[tdCount]._localCSSClassName;
+ }
- // Add regular cell CSS class
- if (this._table && this._table._tableCellClass) {
- xap.util.CssUtils.addClass(td, this._table._tableCellClass);
+ // Add regular cell CSS class
+ if (this._table._tableCellClass) {
+ cssClassNames = cssClassNames + ' ' + this._table._tableCellClass;
+ }
+
+ // update class
+ if(cssClassNames) {
+ xap.util.CssUtils.setClass(td, cssClassNames);
+ }
+
}
//TODO should we use style.textAlign instead of this
@@ -930,7 +952,7 @@
this._adjustImage();
}
td.appendChild(cell);
- this.domNode.appendChild(td);
+ cell._td = td;
},
//adjust the class for the image for this row
@@ -977,9 +999,12 @@
setExpanded : function (expanded){
this._expanded = expanded;
for (var i = 0; i<this._rows.length; i++){
- this._rows[i].setVisible(this._expanded);
+ this._rows[i].setVisible(this._expanded, false);
}
this._adjustImage();
+ if(this._table) {
+ this._table._resizeTableLater();
+ }
},
setSelected : function (selected){
@@ -1004,23 +1029,20 @@
//if we set to invis, set all children to invis as well
//if we set it back, set children back ONLY if we are expanded!
- setVisible : function (visible){
+ setVisible : function (visible, refreshTable){
var visibility = visible === true ? "visible" : "hidden";
var display = visible === true ? "" : "none";
this.domNode.style.visibility = visibility;
this.domNode.style.display = display;
for (var i = 0; i<this._rows.length; i++){
if (!visible || this._expanded){
- this._rows[i].setVisible(visible);
+ this._rows[i].setVisible(visible, refreshTable);
}
}
-
- //TODO set visible is called on EVERY child row when you expand/collapse!!!
- //need to do this only ONCE!!!
- // if(this._table) {
- // this._table._recolorAlternateRows();
- // this._table._resizeTableLater();
- // }
+ if(this._table && refreshTable !== false) {
+ this._table._recolorAlternateRows();
+ this._table._resizeTableLater();
+ }
},
removeCell : function( cell ){