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/10 22:30:50 UTC
svn commit: r583635 -
/incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js
Author: jmargaris
Date: Wed Oct 10 15:30:48 2007
New Revision: 583635
URL: http://svn.apache.org/viewvc?rev=583635&view=rev
Log:
more efficiency changes including begin/end children stuff
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=583635&r1=583634&r2=583635&view=diff
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js (original)
+++ incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js Wed Oct 10 15:30:48 2007
@@ -87,32 +87,14 @@
* Rebuild just the rows of the table, typically called after sorting.
*/
_rebuildRowsLater : function(){
-
- //if a full rebuild is pending don't bother
- if (!this._rebuildTableTask && !this._rebuildRowsTask){
- this._rebuildRowsTask = dojo.lang.setTimeout(this, this._rebuildRows, 0);
- }
+ this._rebuildRows();
},
/**
* Rebuilds the entire table from scratch, should be a very rare occurence.
*/
_rebuildTableLater: function(){
-
- //cancel any partial rebuild tasks
- if (this._rebuildRowsTask){
- window.clearTimeout(this._rebuildRowsTask);
- this._rebuildRowsTask = null;
- }
- if (this._resizeTableTask ){
- window.clearTimeout(this._resizeTableTask);
- this._resizeTableTask = null;
- }
-
- //if not already scheduled then schedule it
- if (!this._rebuildTableTask){
- this._rebuildTableTask = dojo.lang.setTimeout(this, this._rebuildTable, 0);
- }
+ this._rebuildTable();
},
/**
@@ -120,9 +102,7 @@
* and make sure headers and column widths agree
*/
_resizeTableLater: function(){
- if (!this._resizeTableTask){
- this._resizeTableTask = dojo.lang.setTimeout(this, this._resizeTable, 0);
- }
+ this._resizeTable();
},
_getSizeFromString: function(val){
@@ -255,17 +235,18 @@
// sets column width to "width" (note: ends with "px")
for (var i=0; i<this._columns.length;i++) {
- //this._fixColumnWidth(this._columns[i], i, firstRow);
// get new width
var width = this._columns[i]._calculatedWidth;
var boxObject = {width: parseInt(width)};
// set new width
- dojo.html.setMarginBox( this.headerRow.childNodes[i], boxObject) ;
+ if (this.headerRow && this.headerRow.childNodes[i]){
+ dojo.html.setMarginBox( this.headerRow.childNodes[i], boxObject) ;
+ }
if (firstRow && firstRow.childNodes[i]){
dojo.html.setMarginBox( firstRow.childNodes[i], boxObject ) ;
}
// update header width to fill all available space
- if (this.headerRow.childNodes[i].childNodes[0]) {
+ if (this.headerRow && this.headerRow.childNodes[i] && this.headerRow.childNodes[i].childNodes[0]) {
this.headerRow.childNodes[i].childNodes[0].style.width = "100%";
}
}
@@ -326,8 +307,6 @@
for (var i =0; i<this._rows.length; i++){
this._rebuildRow(this._rows[i], 0);
}
- window.clearTimeout(this._rebuildRowsTask);
- this._rebuildRowsTask = null;
this.table.appendChild(this.tbody);
// resize columns in the case of new rows added
@@ -393,7 +372,10 @@
/**
* Rebuilds the entire table from scratch
*/
- _rebuildTable: function(){
+ _rebuildTable: function(){
+
+ if(!this.domNode) { return; }
+
var wh = dojo.html.getMarginBox(this.domNode);
//if we have no width wait for onResized()
@@ -489,7 +471,7 @@
this.scrollDiv.style.height = contentHt;
// reset scroll position
- dojo.lang.setTimeout(this, this._resetScrollPosition, 0);
+ this._resetScrollPosition();
}
},
/**
@@ -537,6 +519,31 @@
this._rowRemoved(row);
},
+ // we call this from iterator to indicate that
+ // we are starting bulk add
+ beginChildrenChanges: function() {
+ if(this._bulkChanges > 0) {
+ this._bulkChanges++;
+ } else {
+ this._bulkChanges = 1;
+ }
+ },
+
+ // we call this from iterator to indicate that
+ // we are done with bulk add
+ // @param rebuild -- pass false to suppress rebuild call
+ endChildrenChanges: function(rebuild) {
+ if(this._bulkChanges > 1) {
+ this._bulkChanges --;
+ } else {
+ this._bulkChanges = 0;
+ if(rebuild === undefined || rebuild) {
+ this._rebuildRows();
+ }
+ }
+ },
+
+
_rowAdded: function(row){
row.setTable(this);
@@ -551,11 +558,15 @@
this._rowAdded(row._rows[i]);
}
- //TODO we should be able to insert the row into the table
- //at the right spot. Gets kind of tricky for nested rows and such,
- //in that case you need to insert relative to a sibling
+ // TODO we should be able to insert the row into the table
+ // at the right spot. Gets kind of tricky for nested rows and such,
+ // in that case you need to insert relative to a sibling
// TODO: maybe resize the columns when stuff is added
- this._rebuildRowsLater();
+
+ // rebuild rows now or wait for bulk changes to finish?
+ if(!this._bulkChanges) {
+ this._rebuildRows();
+ }
},
_rowRemoved: function(row){
@@ -572,7 +583,11 @@
//TODO we should be able to insert the row into the table
//at the right spot. Gets kind of tricky for nested rows and such,
//in that case you need to insert relative to a sibling
- this._rebuildRowsLater();
+
+ // rebuild rows now or wait for bulk changes to finish?
+ if(!this._bulkChanges) {
+ this._rebuildRows();
+ }
},
/**
@@ -932,25 +947,26 @@
//setLeafImage(...), setOpenImage(...) etc? If so we need more than
//a class we need to dynamically set the image
_adjustImage : function(){
+
if (!this._indentSpan){
return;
}
var newClass = "";
- if (this._imageClass){
- xap.util.CssUtils.removeClass(this._indentSpan, this._imageClass);
- }
- if (this._rows.length==0){
- newClass = ""; // eventually add a class here to fix the indenting
+
+ if(this._rows.length > 0) {
+ newClass = this._expanded ? "ImgNodeExpanded" : "ImgNodeCollapsed";
}
- else if (this._expanded){
- newClass = "ImgNodeExpanded";
+
+ if (this._imageClass !== undefined && this._imageClass != newClass) {
+ xap.util.CssUtils.removeClass(this._indentSpan, this._imageClass);
}
- else{
- newClass = "ImgNodeCollapsed";
+
+ if (this._imageClass === undefined || this._imageClass != newClass) {
+ xap.util.CssUtils.addClass(this._indentSpan, newClass);
+ this._imageClass = newClass;
}
- xap.util.CssUtils.addClass(this._indentSpan, newClass);
- this._imageClass= newClass;
+
},
setDepth : function( depth ){
@@ -1017,6 +1033,15 @@
this.domNode.removeChild(cell._td);
},
+ // rows can have other rows as children
+ // so we forward begin/end calls to the table
+ beginChildrenChanges : function () {
+ if(this._table) { this._table.beginChildrenChanges(); }
+ },
+ endChildrenChanges : function () {
+ if(this._table) { this._table.endChildrenChanges(); }
+ },
+
insertRow: function(row, index){
// Don't show the kid if we are not expanded!
row.setVisible(this._expanded);