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 2007/06/05 16:33:06 UTC
svn commit: r544548 - in /incubator/xap/trunk/codebase/src/xap:
bridges/dojo/TableBridge.js widgets/dojo/TreeTable.js
Author: mturyn
Date: Tue Jun 5 09:33:05 2007
New Revision: 544548
URL: http://svn.apache.org/viewvc?view=rev&rev=544548
Log:
Bringing up to a post-release version of things that seems to both have the newer features and not screw up loading.
Modified:
incubator/xap/trunk/codebase/src/xap/bridges/dojo/TableBridge.js
incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js
Modified: incubator/xap/trunk/codebase/src/xap/bridges/dojo/TableBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/bridges/dojo/TableBridge.js?view=diff&rev=544548&r1=544547&r2=544548
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/bridges/dojo/TableBridge.js (original)
+++ incubator/xap/trunk/codebase/src/xap/bridges/dojo/TableBridge.js Tue Jun 5 09:33:05 2007
@@ -27,7 +27,8 @@
Xap.require("xap.bridges.dojo.DojoWidgetBridge");
Xap.require("xap.widgets.dojo.TreeTable");
-
+Xap.require("dojo.html");
+Xap.require("xap.util.CssUtils");
/**
@@ -38,13 +39,10 @@
xap.bridges.dojo.TableBridge= function() {
xap.bridges.dojo.DojoWidgetBridge.call(this);
-}
+};
-Xap.setupClassAsSubclassOf(
- "xap.bridges.dojo.TableBridge",
- "xap.bridges.dojo.DojoWidgetBridge"
-);
+Xap.setupClassAsSubclassOf("xap.bridges.dojo.TableBridge", "xap.bridges.dojo.DojoWidgetBridge");
@@ -53,18 +51,41 @@
dojo.event.connect(this.getPeer(), "onActivateRow",this,"onActivateRow");
dojo.event.connect(this.getPeer(), "onSelectRow",this,"onSelectRow");
dojo.event.connect(this.getPeer(), "onDeselectRow",this,"onDeselectRow");
- dojo.event.connect(this.getPeer(), "onExpandRow",this,"onExpandRow");
-}
+ dojo.event.connect(this.getPeer(), "onExpandRow",this,"onExpandRow");
+
+};
+
xap.bridges.dojo.TableBridge.prototype.getPeerString = function(){
return "TreeTable" ;
-}
+};
+
+
+xap.bridges.dojo.TableBridge.prototype.obtainPeer = function(){
+ xap.bridges.dojo.TableBridge.superclass.obtainPeer.call(this) ;
+ var peer = this.getPeer() ;
+ if( !peer._tableLayoutModel){
+ peer._tableLayoutModel = {} ;
+ }
+ var h = this.getElement().getAttribute("height") ;
+ if( h ){
+ peer._tableLayoutModel.initialHeight = h ;
+ }
+ var w = this.getElement().getAttribute("width") ;
+ if( w ){
+ peer._tableLayoutModel.initialWidth = w ;
+ }
+};
+
+
+
xap.bridges.dojo.TableBridge.prototype.onActivateRow = function( a ){
var clientEvent = new xap.session.ClientEvent(this.getElement(), this.getSession());
clientEvent.rowId = this.getSelectedRowIds();
this.fireEvent("onSelect", null, null, clientEvent);
-}
+};
+
xap.bridges.dojo.TableBridge.prototype.onExpandRow = function( row, expanded ){
var handler = this.getUiContentHandler().getHandlerForPeer(row);
@@ -72,13 +93,14 @@
var clientEvent = new xap.session.ClientEvent(this.getElement(), this.getSession());
clientEvent.rowId = handler.getElement().getAttribute("id");
this.fireEvent(expanded?"onExpand":"onCollapse", null, null, clientEvent);
-}
+};
xap.bridges.dojo.TableBridge.prototype.onDeselectRow = function( row ){
var handler = this.getUiContentHandler().getHandlerForPeer(row);
handler.writeBackRemoveAttribute("selected");
-}
+};
+
xap.bridges.dojo.TableBridge.prototype.onSelectRow = function( row ){
var handler = this.getUiContentHandler().getHandlerForPeer(row);
@@ -86,7 +108,8 @@
var clientEvent = new xap.session.ClientEvent(this.getElement(), this.getSession());
clientEvent.rowId = this.getSelectedRowIds();
this.fireEvent("onStateChange", null, null, clientEvent);
-}
+};
+
xap.bridges.dojo.TableBridge.prototype.getSelectedRowIds = function(){
var s = "";
@@ -94,15 +117,15 @@
for (var i=0; i<selectedItems.length; i++){
var row = selectedItems[i];
var handler = this.getUiContentHandler().getHandlerForPeer(row);
- if (handler!=null){
- if (s.length!=0){
- s+=(',');
+ if (handler){
+ if (s.length !== 0){
+ s += (',');
}
- s+= handler.getElement().getAttribute("id");
+ s += handler.getElement().getAttribute("id");
}
}
return s;
-}
+};
/**
*
@@ -115,16 +138,31 @@
/**
* Dynamic attributes
*/
-xap.bridges.dojo.TableBridge.prototype.getNewAllowedAttributes = function(){
- return [];
-}
+xap.bridges.dojo.TableBridge.prototype.getNewAllowedAttributes = function() {
+ return [
+ "altColor",
+ "altBackgroundColor",
+ "highlightColor",
+ "highlightBackgroundColor",
+ "horizontalLineColor",
+ "verticalLineColor",
+ "collapsedImage",
+ "expandedImage"];
+};
+
+
xap.bridges.dojo.TableBridge.prototype.setHeightAttribute = function(value){
this.getPeer().setHeight (value);
-}
-
+};
+
+xap.bridges.dojo.TableBridge.prototype.setWidthAttribute = function(aWidth){
+ this.getPeer().setWidth(aWidth) ;
+};
xap.bridges.dojo.TableBridge.prototype.addChild = function(childHandler, index){
+// TODO: implement "addSelfToTable" methods on child peers
+// so that we can reduce this to four polymorphic lines:
var childPeer = childHandler.getPeer();
if (childPeer instanceof xap.widgets.dojo.TableColumn){
//TODO interpret index correctly
@@ -133,7 +171,8 @@
else if (childPeer instanceof xap.widgets.dojo.TableRow){
this.getPeer().insertRow(childPeer,-1);
}
-}
+};
+
// handler for removing children
xap.bridges.dojo.TableBridge.prototype.removeChild = function( childHandler ){
@@ -145,4 +184,228 @@
else if (childPeer instanceof xap.widgets.dojo.TableRow){
this.getPeer().removeRow(childPeer);
}
-}
+};
+
+
+//=============================== ATTRIBUTE HELPERS
+
+
+/**
+ * Returns global CSS rule "." and CSS class name
+ *
+ * @return CSS rule object
+ */
+xap.bridges.dojo.TableBridge.prototype.getGlobalRule = function(cssClassName) {
+ var globalRule = xap.util.CssUtils.getCSSRule('.' + cssClassName);
+ return globalRule;
+};
+
+
+/**
+ * Returns local CSS rule by combining element id and CSS class name
+ *
+ * @return CSS rule object
+ */
+xap.bridges.dojo.TableBridge.prototype.getLocalRule = function(cssClassName, bCreate) {
+ var id = this.getRootDomNode().getAttribute('id');
+ var selector = 'div#' + id + ' .' + cssClassName;
+ var localRule = xap.util.CssUtils.getCSSRule(selector);
+ if(!localRule && bCreate ) {
+ // create local rule
+ var globalRule = this.getGlobalRule(cssClassName);
+ if( globalRule ){
+ dojo.html.insertCssRule(selector, globalRule.style.cssText);
+ localRule = xap.util.CssUtils.getCSSRule(selector);
+ } else {
+ xap.log.Logger.getRootLogger().error('Missing CSS rule ' + cssClassName);
+ }
+ }
+ return localRule;
+};
+
+
+//=============================== ATTRIBUTE SETTERS
+
+
+/** XML attribute set method for "altColor" */
+xap.bridges.dojo.TableBridge.prototype.setAltColorAttribute = function(value) {
+ var cssClassName = this.getPeer()._alternateRowClass;
+ // "true" == "create one if there isn't one extant"
+ var localRule = this.getLocalRule(cssClassName, true);
+ if( localRule && localRule.style ){
+ localRule.style.color = value ;
+ } else {
+ xap.log.Logger.getRootLogger().error('Unable to create local rule ' + cssClassName);
+ }
+ // create local selected row class to prevent override
+ this.getLocalRule(this.getPeer()._selectedRowClass, true);
+};
+
+/** XML attribute remove method for "altColor" */
+xap.bridges.dojo.TableBridge.prototype.attributeRemovers.altColor = function() {
+ var cssClassName = this.getPeer()._alternateRowClass;
+ var localRule = this.getLocalRule(cssClassName);
+ if(localRule) { localRule.style.color = ''; }
+};
+
+//==
+
+/** XML attribute set method for "altBackgroundColor" */
+xap.bridges.dojo.TableBridge.prototype.setAltBackgroundColorAttribute = function(value) {
+ var cssClassName = this.getPeer()._alternateRowClass;
+ var localRule = this.getLocalRule(cssClassName);
+ // "true" == "create one if there isn't one extant"
+ var localRule = this.getLocalRule(cssClassName, true);
+ if( localRule && localRule.style ){
+ localRule.style.backgroundColor = value;
+ } else {
+ xap.log.Logger.getRootLogger().error('Unable to create local rule ' + cssClassName);
+ }
+ // create local selected row class to prevent override
+ this.getLocalRule(this.getPeer()._selectedRowClass, true);
+};
+
+/** XML attribute remove method for "altBackgroundColor" */
+xap.bridges.dojo.TableBridge.prototype.attributeRemovers.altBackgroundColor = function() {
+ var cssClassName = this.getPeer()._alternateRowClass;
+ var localRule = this.getLocalRule(cssClassName);
+ if(localRule) { localRule.style.backgroundColor = ''; }
+};
+
+
+//==
+
+/** XML attribute set method for "highlightColor" */
+xap.bridges.dojo.TableBridge.prototype.setHighlightColorAttribute = function(value) {
+ var cssClassName = this.getPeer()._selectedRowClass;
+ // "true" == "create one if there isn't one extant"
+ var localRule = this.getLocalRule(cssClassName, true);
+ if( localRule && localRule.style ){
+ localRule.style.color = value ;
+ } else {
+ xap.log.Logger.getRootLogger().error('Unable to create local rule ' + cssClassName);
+ }
+};
+
+/** XML attribute remove method for "highlightColor" */
+xap.bridges.dojo.TableBridge.prototype.attributeRemovers.highlightColor = function() {
+ var cssClassName = this.getPeer()._selectedRowClass;
+ var localRule = this.getLocalRule(cssClassName);
+ if(localRule) { localRule.style.color = ''; }
+};
+
+
+//==
+
+
+/** XML attribute set method for "highlightBackgroundColor" */
+xap.bridges.dojo.TableBridge.prototype.setHighlightBackgroundColorAttribute = function(value) {
+ var cssClassName = this.getPeer()._selectedRowClass;
+ // "true" == "create one if there isn't one extant"
+ var localRule = this.getLocalRule(cssClassName, true);
+ if( localRule && localRule.style ){
+ localRule.style.backgroundColor = value;
+ } else {
+ xap.log.Logger.getRootLogger().error('Unable to create local rule ' + cssClassName);
+ }
+};
+
+/** XML attribute remove method for "highlightBackgroundColor" */
+xap.bridges.dojo.TableBridge.prototype.attributeRemovers.highlightBackgroundColor = function() {
+ var cssClassName = this.getPeer()._selectedRowClass;
+ var localRule = this.getLocalRule(cssClassName);
+ if(localRule) { localRule.style.backgroundColor = ''; }
+};
+
+
+//==
+
+
+/** XML attribute set method for "horizontalLineColor" */
+xap.bridges.dojo.TableBridge.prototype.setHorizontalLineColorAttribute = function(value) {
+ var cssClassName = this.getPeer()._tableCellClass;
+ // "true" == "create one if there isn't one extant"
+ var localRule = this.getLocalRule(cssClassName, true);
+ if( localRule && localRule.style ){
+ localRule.style.borderBottomColor = value;
+ } else {
+ xap.log.Logger.getRootLogger().error('Unable to create local rule ' + cssClassName);
+ }
+};
+
+/** XML attribute remove method for "horizontalLineColor" */
+xap.bridges.dojo.TableBridge.prototype.attributeRemovers.horizontalLineColor = function() {
+ var cssClassName = this.getPeer()._tableCellClass;
+ var localRule = this.getLocalRule(cssClassName);
+ if(localRule) { localRule.style.borderBottomColor = ''; }
+};
+
+
+//==
+
+
+/** XML attribute set method for "verticalLineColor" */
+xap.bridges.dojo.TableBridge.prototype.setVerticalLineColorAttribute = function(value) {
+ var cssClassName = this.getPeer()._tableCellClass;
+ // "true" == "create one if there isn't one extant"
+ var localRule = this.getLocalRule(cssClassName, true);
+ if( localRule && localRule.style ){
+ localRule.style.borderRightColor = value;
+ } else {
+ xap.log.Logger.getRootLogger().error('Unable to create local rule ' + cssClassName);
+ }
+};
+
+/** XML attribute remove method for "verticalLineColor" */
+xap.bridges.dojo.TableBridge.prototype.attributeRemovers.verticalLineColor = function() {
+ var cssClassName = this.getPeer()._tableCellClass;
+ var localRule = this.getLocalRule(cssClassName);
+ if(localRule) { localRule.style.borderRightColor = ''; }
+};
+
+
+//==
+
+
+/** XML attribute set method for "collapsedImage" */
+xap.bridges.dojo.TableBridge.prototype.setCollapsedImageAttribute = function(value) {
+ var cssClassName = 'ImgNodeCollapsed';
+ // "true" == "create one if there isn't one extant"
+ var localRule = this.getLocalRule(cssClassName, true);
+ if( localRule && localRule.style ){
+ localRule.style.backgroundImage = 'url(' + value + ')';
+ } else {
+ xap.log.Logger.getRootLogger().error('Unable to create local rule ' + cssClassName);
+ }
+};
+
+/** XML attribute remove method for "collapsedImage" */
+xap.bridges.dojo.TableBridge.prototype.attributeRemovers.collapsedImage = function() {
+ var cssClassName = 'ImgNodeCollapsed';
+ var localRule = this.getLocalRule(cssClassName);
+ if(localRule) { localRule.style.backgroundImage = ''; }
+};
+
+
+//==
+
+
+/** XML attribute set method for "expandedImage" */
+xap.bridges.dojo.TableBridge.prototype.setExpandedImageAttribute = function(value) {
+ var cssClassName = 'ImgNodeExpanded';
+ // "true" == "create one if there isn't one extant"
+ var localRule = this.getLocalRule(cssClassName, true);
+ if( localRule && localRule.style ){
+ localRule.style.backgroundImage = 'url(' + value + ')';
+ } else {
+ xap.log.Logger.getRootLogger().error('Unable to create local rule ' + cssClassName);
+ }
+};
+
+/** XML attribute remove method for "expandedImage" */
+xap.bridges.dojo.TableBridge.prototype.attributeRemovers.expandedImage = function() {
+ var cssClassName = 'ImgNodeExpanded';
+ var localRule = this.getLocalRule(cssClassName);
+ if(localRule) { localRule.style.backgroundImage = ''; }
+};
+
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=544548&r1=544547&r2=544548
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js (original)
+++ incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js Tue Jun 5 09:33:05 2007
@@ -17,8 +17,6 @@
*
*/
-
-
Xap.provide("xap.widgets.dojo.TreeTable");
Xap.provide("xap.widgets.dojo.TableColumn");
Xap.provide("xap.widgets.dojo.TableRow");
@@ -31,6 +29,9 @@
Xap.require("dojo.style");
Xap.require("dojo.event");
Xap.require("xap.util.ArrayHelper");
+Xap.require("xap.widgets.dojo.DivWrapper");
+
+
//IMPORTANT move this to some shared area
dojo.widget.manager.registerWidgetPackage("xap.widgets.dojo");
@@ -53,11 +54,18 @@
dojo.widget.HtmlWidget.call(this);
this._rebuildTableLater();
+
+ this._selectedRowClass = "selectedRow";
this._alternateRowClass = "alternateRow";
this._tableCellClass = "tableCell";
+
this._headerVisibility = "visible";
this._initialResizePending = true;
-}
+
+ // width of each column sizer, in pixels:
+ this._sizerWidth = 2;
+
+};
dojo.inherits(xap.widgets.dojo.TreeTable,dojo.widget.HtmlWidget);
@@ -65,16 +73,70 @@
//TODO calc padding after laying out headers?
//this is a bad strategy in general, the problem is we want the inner table
//to be sized at 100%
- templateString: '<div style="padding:0px 0px 0px 0px; overflow:hidden;position:relative;text-align:left">' +
- '<div dojoAttachPoint="headerDiv"><table dojoAttachPoint="headerTable" style="position:relative;width:100%;table-layout:fixed;">' +
- '<tbody dojoAttachPoint="headerTbody"><tr dojoAttachPoint="headerRow"></tr></tbody></table></div>'+
- '<div dojoAttachPoint="scrollDiv" style="overflow:auto;width:100%;height:100%;">' +
- '<table dojoAttachPoint="table" style="height:100%;"><tbody></tbody></table></div></div>',
+ templateString:
+'<div style="padding:0px 0px 0px 0px; overflow:hidden;position:relative;text-align:left">'
+ + '<div dojoAttachPoint="splitterContainer"></div>'
+ + '<div dojoAttachPoint="headerDiv">'
+ + '<table dojoAttachPoint="headerTable" border="1" style="position:relative;table-layout:fixed;">'
+ + '<tbody dojoAttachPoint="headerTbody">'
+ + '<tr dojoAttachPoint="headerRow"></tr>'
+ + '</tbody>'
+ + '</table>'
+ + '</div>'
+ + '<div dojoAttachPoint="scrollDiv" style="overflow:auto;width:100%;height:100%;">'
+ + '<table dojoAttachPoint="table" style="height:100%;">'
+ + '<thead dojoAttachPoint="spacerRow"></thead>'
+ + '<tbody></tbody>'
+ + '</table>'
+ + '</div>'
++ '</div>',
+
+
templateCssPath: null ,
widgetType: "TreeTable",
isContainer: false,
defaultCellInfo: {_text:""},
+ // Delay between setting height or width and
+ // resetting scrollDiv overflow back to "auto"
+ // (previously set to "hidden" at the start
+ // of setHeight() or setWidth()):
+ _resetScrollDivDelayMs: (dojo.render.html.moz)?20:20,
+
+
+// Debugging
+// _ctr:-1 ,
+// loggit: function(aString){
+// Xap.logString+="^"+(++this._ctr)
+// +"\t"+aString
+// +"\t" +(new Date()).getTime()
+// +"\t";
+// if(this.table){
+// Xap.logString
+// +=this.table.clientWidth +"\t"+this.domNode.clientWidth ;
+// }
+// },
+
+ postCreate: function(){ //debug::this.loggit('postCreate') ;
+ xap.widgets.dojo.TreeTable.superclass.postCreate.apply(this,arguments) ;
+ this._created = true ;
+ if( !this._tableLayoutModel ){
+ this._tableLayoutModel = {} ;
+ }
+
+
+ // Handle percentage widths/heights well on resize:
+// Doing nothing so far:
+// if( this.domNode.parentNode ){
+// dojo.event.connect(this.domNode.parentNode, "onresize", this,"onResized") ;
+// }
+
+// debugging:
+// window.foo = this ;
+ },
+
+
+
/**
*
*
@@ -86,18 +148,19 @@
/**
* Rebuild just the rows of the table, typically called after sorting.
*/
- _rebuildRowsLater : function(){
+ _rebuildRowsLater : function(delay){ //debug::this.loggit('_rebuildRowsLater ') ;
//if a full rebuild is pending don't bother
if (!this._rebuildTableTask && !this._rebuildRowsTask){
- this._rebuildRowsTask = dojo.lang.setTimeout(this, this._rebuildRows, 0);
+ var theDelay = delay || 0 ;
+ this._rebuildRowsTask = dojo.lang.setTimeout(this, this._rebuildRows, delay);
}
},
/**
* Rebuilds the entire table from scratch, should be a very rare occurence.
*/
- _rebuildTableLater: function(){
+ _rebuildTableLater: function(delay){ //debug::this.loggit('_rebuildTableLater') ;
//cancel any partial rebuild tasks
if (this._rebuildRowsTask){
@@ -110,8 +173,9 @@
}
//if not already scheduled then schedule it
+ var theDelay = delay || 0 ;
if (!this._rebuildTableTask){
- this._rebuildTableTask = dojo.lang.setTimeout(this, this._rebuildTable, 0);
+ this._rebuildTableTask = dojo.lang.setTimeout(this, this._rebuildTable, theDelay);
}
},
@@ -119,13 +183,13 @@
* Once the table is built/sized run through
* and make sure headers and column widths agree
*/
- _resizeTableLater: function(){
+ _resizeTableLater: function(){ //debug::this.loggit('_resizeTableLater') ;
if (!this._resizeTableTask){
this._resizeTableTask = dojo.lang.setTimeout(this, this._resizeTable, 0);
}
},
- _getSizeFromString: function(val){
+ _getSizeFromString: function(val){ //debug::this.loggit('_getSizeFromString') ;
var s = new String(val);
var i = s.search ("px");
if ( i > 0 ) return Number(s.substr(0,i));
@@ -137,15 +201,38 @@
* After a table has been built to the screen go through and make sure
* the widths of columns and headers match up.
*/
- _resizeTable: function(){
+ _resizeTable: function(){ //debug::this.loggit('_resizeTable') ;
var tableWidth = 0;
-
+
//don't user tbody.childNodes[0] here because in the case
//where we need to fix up IE we want to fixup and THEN remove
//and re-add rows in the new order.
var firstRow = this._rows.length>0?this._rows[0].domNode:null;
+ // Spacing gets screwed-up under IE if the first row isn't complete,
+ // so complete it if need be:
+ var len = -1 ;
+ if( dojo.render.html.ie
+ && firstRow
+ && this._columns
+ && (len=this._columns.length)>1
+ ){
+ while(firstRow.childNodes.length<len){
+ var filler = document.createElement("td");
+ filler.style.backgroundColor = "transparent" ;
+ firstRow.appendChild(filler) ;
+ }
+ }
+
+
var tableWidth = 0;
+ // No need to test for these each iteration:
+ var hasHeaders = this.headerRow && this.headerRow.childNodes ;
+ var hasFirstRow = firstRow && firstRow.childNodes ;
+ var hasHeaderTable = this.headerTable && this.headerTable.childNodes ;
+ var hasBodyTable = this.table && this.table.childNodes ;
+
+
for (var i=0; i<this._columns.length;i++){
var headerWidth = 0;
@@ -154,92 +241,210 @@
//In IE get/set of column width dynamically doesn't seem to work
//too well so use first row instead
+
+ var node = null ;
if (dojo.render.html.ie){
- var headerWidth = this.headerRow.childNodes[i].offsetWidth;
- if (firstRow && firstRow.childNodes[i]){
- columnWidth = firstRow.childNodes[i].offsetWidth;
+ if( hasHeaders && (node = this.headerRow.childNodes[i])){
+ headerWidth
+ // = node.offsetWidth;
+ = node.clientWidth;
+ }
+ node = null ;
+ if ( hasFirstRow && (node = firstRow.childNodes[i]) ){
+ columnWidth
+ = node.clientWidth ;
}
}
else{
- headerWidth = this.headerTable.childNodes[i].offsetWidth;
- columnWidth = this.table.childNodes[i].offsetWidth;
+ if( hasHeaderTable
+ && (node = this.headerTable.childNodes[i])
+ ){
+ headerWidth
+ = node.clientWidth ;
+ }
+ node=null;
+ if( hasBodyTable
+ && (node = this.table.childNodes[i])){
+ columnWidth
+ = node.clientWidth ;
+ }
}
- /* if the user explicitly set, we use those */
- if ( this._columns[i]._headerWidth ) {
- var val = this._getSizeFromString (this._columns[i]._headerWidth);
- if ( val ) setWidth = val;
- }
-
- // we want the greater of explicity set, calculated column or calculated cell; note that we need to look up
- // the explicity set ones in case the table is hidden when created
- var finalWidth = headerWidth>columnWidth ? headerWidth:columnWidth;
- finalWidth = setWidth>finalWidth?setWidth:finalWidth;
- this._columns[i]._calculatedWidth = finalWidth + "px";
- tableWidth += finalWidth;
+ /* if the user explicitly set the column width or
+ its header's width , we use those (preferring
+ as usual the last value parsed, that is,
+ the header's):
+ */
+
+ var setWidth = this._columns[i].getBestWidth() ;
+
+ // We want to set the column width to the explicitly-given value
+ // if it should be available from the column or its header); if
+ // a value is not available so, we'll use the greater of the
+ // extant cell or column widths. Note that we need to look
+ // up the explicitly-set ones in case the table is hidden when created
+ var preferredColumnWidth = setWidth ;
+ if( !setWidth ){
+ preferredColumnWidth = headerWidth>columnWidth ? headerWidth:columnWidth;
+ preferredColumnWidth += "px" ;
+ }
+ var preferredColumnWidthPx = parseInt(preferredColumnWidth) ;
+ this._columns[i].setStatedWidth(preferredColumnWidth) ;
+ if(this.columnsSizer
+ && this.columnsSizer.children
+ && this.columnsSizer.children[i]
+ ){
+ this.columnsSizer.children[i].sizeShare = preferredColumnWidthPx ;
+ }
+ tableWidth += preferredColumnWidthPx ;
}
-
+
//if we don't fix the width here then when we want the table
//to scroll horizontally it doesn't work very well, sizes
//too small
- this.table.style.width = tableWidth + "px";
- this.headerTable.style.width = tableWidth + "px";
+ if( tableWidth != 0 ){
+ this.table.style.width = tableWidth + "px";
+ this.headerTable.style.width = tableWidth + "px";
+ this.headerDiv.style.width
+ = "100%";
+
+ this.headerTable.style.tableLayout = "fixed";
+ this.table.style.tableLayout = "fixed";
+
+
+ if( !this._tableLayoutModel.resetWidthPx
+ && !this._tableLayoutModel.initialWidth
+ ){
+ this.domNode.style.width = tableWidth +"px" ;
+ } else {
+ if( this._tableLayoutModel.initialWidth ){
+ // We get this one directly from the XAL
+ // element, so it could easily be a percentage
+ // or in a non-pixel unit:
+ this.domNode.style.width = this._tableLayoutModel.initialWidth ;
+ } else {
+ // ...whereas _we_ set this, and know
+ // it to be a number giving the width
+ // in pixels:
+ this.domNode.style.width = this._tableLayoutModel.resetWidthPx+"px";
+ }
+ }
+
+ this._fixColumnWidths();
+ } else {
+ // Best for Tree
+ // TODO: break out {column/header}less behavious
+ // into a separate class?
+ this.table.style.width=this.domNode.clientWidth+"px" ;
+ }
+
+ dojo.lang.setTimeout(this,this._reconcileHeaderAndBodyColumns,0);
- this.headerTable.style.tableLayout = "fixed";
- this.table.style.tableLayout = "fixed";
+ if( this._resizeTableTask ){
+ window.clearTimeout(this._resizeTableTask);
+ this._resizeTableTask = null;
+ }
- this._fixColumnWidths();
-
- window.clearTimeout(this._resizeTableTask);
- this._resizeTableTask = null;
},
- _fixColumnWidths : function(){
+ _fixColumnWidths : function(){ //debug::this.loggit('_fixColumnWidths ') ;
+ if( this._columns.length==0){
+ this.table.style.width="100%" ;
+ return ;
+ }
+
+
+
var firstRow = this._rows.length>0?this._rows[0].domNode:null;
+
+
for (var i=0; i<this._columns.length;i++){
- var width = this._columns[i]._calculatedWidth; // Note: ends with "px"
-
+ // Note: ends with "px":
+ var width = this._columns[i].getBestWidth();
+ //...so use this:
+ var nWidth = parseInt(width) ;
+
+ width = (nWidth)+"px" ;
+
+ var widthObj = {width: nWidth};
+
+
if (dojo.render.html.ie){
- dojo.html.setMarginBox( this.headerRow.childNodes[i],
- {width: parseInt(width)} ) ;
-
+
+ if( this.headerRow.childNodes[i] ){
+ dojo.html.setMarginBox( this.headerRow.childNodes[i],
+ widthObj ) ;
+ }
+
+ widthObj = dojo.html.getMarginBox( this.headerRow.childNodes[i]) ;
+ delete widthObj.height ;
+ //widthObj.width += 1 ;
if (firstRow && firstRow.childNodes[i]){
dojo.html.setMarginBox( firstRow.childNodes[i],
- {width: parseInt(width)} ) ;
+ widthObj) ;
}
}
- else{
- this.headerTable.childNodes[i].style.width = width;
- this.table.childNodes[i].style.width = width;
+ else {
+ // Cols are direct children of headerTable;
+ // they're evidently sufficient under mozilla to
+ // set the columns on-screen:
+ if(this.headerTable.childNodes[i]){
+ dojo.html.setMarginBox(
+ this.headerTable.childNodes[i],
+ widthObj
+ ) ;
+ }
+ if(this.table.childNodes[i] && this.headerTable.childNodes[i] ){
+ widthObj = dojo.html.getMarginBox( this.headerTable.childNodes[i]) ;
+ delete widthObj.height ;
+ dojo.html.setMarginBox(
+ this.table.childNodes[i],
+ widthObj
+ ) ;
+ }
}
- if (this.headerRow.childNodes[i].childNodes[0])
- this.headerRow.childNodes[i].childNodes[0].style.width = "100%";
+ if (this.headerRow.childNodes[i] && this.headerRow.childNodes[i].childNodes[0]){
+ this.headerRow.childNodes[i].childNodes[0].style.width = "100%";
+ if( this.columnsSizer ){
+ this.columnsSizer.children[i].sizeShare
+ = nWidth ;
+ }
+ }
}
+
},
/**
* Rebuilds just the real table part of table, not
* the headers.
*/
- _rebuildBody: function(){
+ _rebuildBody: function(){ //debug::this.loggit('_rebuildBody') ;
+
this.domNode.removeChild(this.scrollDiv);
this.scrollDiv = document.createElement("div");
this.domNode.appendChild(this.scrollDiv);
- /* calculate the scroll pane as the body less the height of the header */
+ /*
+ calculate the scroll pane height as
+ the body height less the heights of
+ the header and a possible horizontal
+ scrollbar:
+ */
var contentHt = "100%";
- var ht = this.domNode.clientHeight - this.headerDiv.clientHeight;
+ var ht = this.domNode.clientHeight
+ - this.headerDiv.clientHeight
+ -this.getHorizontalScrollbarHeightPx() ;
//in IE the calculated height can be negative because
//clientHeight can be zero
if ( ht > 0 ) contentHt = ht + "px";
-
+
dojo.lang.mixin(this.scrollDiv.style,{
position:"relative",
width:"100%",
height: contentHt,
overflow:"auto"});
-
+
dojo.event.connect(this.scrollDiv, "onscroll", this, "onScrollCallback");
this.table = document.createElement("table");
@@ -261,7 +466,7 @@
* Rebuilds only the rows in the table, leaving the columns in place
* with the same sizes. Useful for sorting.
*/
- _rebuildRows: function(){
+ _rebuildRows: function(){ //debug::this.loggit('_rebuildRows') ;
if (this.tbody){
this.table.removeChild(this.tbody);
}
@@ -273,37 +478,60 @@
for (var i =0; i<this._rows.length; i++){
this._rebuildRow(this._rows[i], 0);
}
- window.clearTimeout(this._rebuildRowsTask);
- this._rebuildRowsTask = null;
+ if( this._rebuildRowsTask ){
+ window.clearTimeout(this._rebuildRowsTask);
+ this._rebuildRowsTask = null;
+ }
// resize columns in the case of new rows added
- this._resizeTable ();
+ // ---absolutely avoid this if we've just sorted.
+
+ if(this._justSorted ){
+ delete this._justSorted ;
+ } else {
+ this._resizeTable();
+ }
this._recolorAlternateRows();
+ this._redoSplitPanelStyling(1000) ;
+ },
+
+ getVerticalScrollbarWidthPx: function(){ //debug::this.loggit('getVerticalScrollbarWidthPx') ;
+ return this.scrollDiv.offsetWidth - this.scrollDiv.clientWidth ;
},
+ getHorizontalScrollbarHeightPx: function(){ //debug::this.loggit('getHorizontalScrollbarHeightPx') ;
+ return this.scrollDiv.offsetHeight - this.scrollDiv.clientHeight ;
+ },
+
/**
* Rebuilds just the head (column headers)
- * of the table.
+ * of the table. Skip sizers or outer dom node
+ * if we've just shifted a column sizer:
*/
- _rebuildHead: function(){
+ _rebuildHead: function(){ //debug::this.loggit('_rebuildHead') ;
this._headerVisibility = this.headerDiv.style.visibility;
- this.domNode.removeChild(this.headerDiv);
- this.headerDiv = document.createElement("div");
+ this.domNode.removeChild(this.headerDiv);
+ this.headerDiv = document.createElement("div");
this.domNode.appendChild(this.headerDiv);
-
+
//this.headerDiv.style.width="1000px";
- this.headerDiv.style.width="100%";
+ this.headerDiv.style.width
+ = "100%" ;
+ this.headerDiv.style.width = this.headerDiv.scrollWidth +"px" ;
+
+
this.headerDiv.style.position="relative";
this.headerDiv.style.textAlign="left";
dojo.html.addClass(this.headerDiv,'xapHeaderBackground');
this.headerTable = document.createElement("table");
this.headerDiv.appendChild(this.headerTable);
-
+
+
this.headerTable.cellPadding = "0px";
- this.headerTable.cellSpacing= "0px";
+ this.headerTable.cellSpacing = "0px";
//populate cols under both tables
for (var i = 0; i<this._columns.length; i++){
@@ -315,18 +543,55 @@
this.headerBody = document.createElement("tbody");
this.headerTable.appendChild(this.headerBody);
+ dojo.html.addClass(this.headerTable,"xapHeaderTable");
+
//now populate the header row
this.headerRow = document.createElement("tr");
this.headerBody.appendChild(this.headerRow);
for (var i = 0; i<this._columns.length; i++){
var cell = document.createElement("td");
dojo.html.addClass(cell,'xapHeaderWrapper');
- this.headerRow.appendChild(cell);
+
cell.style.whiteSpace = "nowrap";
- if (this._columns[i]._header && this._columns[i]._header._rootDomNode){
- cell.appendChild(this._columns[i]._header._rootDomNode);
+ // If overflow isn't hidden, then
+ // column cannot be shrunk below
+ // width of the contents:
+ cell.style.overflow="hidden" ;
+
+ var w = null ;
+ var hasColumns = this._columns && this._columns[i] ;
+ if(hasColumns){
+ if(w=this._columns[i].getBestWidth()){
+ cell.style.width = w ;
+ }
+ }
+
+
+ this.headerRow.appendChild(cell);
+
+
+ var header = null ;
+ if (header = this._columns[i]._header){
+ this._lastHeaderAdded = header ;
+ var hAlign = this._columns[i]._horizontalAlignment ;
+ if( !hAlign ){
+ // Default alignment:
+ hAlign = "left" ;
+ }
+ // This is another of our widgets, a Button
+ // instance; in this case the sorting hint image
+ // is _not_ a standard button image, since we
+ // wish to reserve that place for some other image:
+ header.setTextPlacementHorizontal(hAlign) ;
+ if(header._rootDomNode){
+ var subnode= header._rootDomNode ;
+ subnode.style.overflow = "hidden" ;
+ subnode.style.whitespace="nowrap" ;
+ cell.appendChild(subnode);
+ }
}
cell.style.visibility = this._headerVisibility;
+
}
if (this._headerVisibility=='hidden'){
@@ -334,30 +599,39 @@
this.headerDiv.style.visibility='hidden';
this.headerDiv.style.display='none';
}
+
},
/**
* Rebuilds the entire table from scratch
*/
- _rebuildTable: function(){
+ _rebuildTable: function(){ //debug::this.loggit('_rebuildTable') ;
var wh = dojo.html.getMarginBox(this.domNode);
//if we have no width wait for onResized()
if (!wh.width){
- window.clearTimeout(this._rebuildTableTask);
- this._rebuildTableTask = null;
+ if(this._rebuildTableTask){
+ window.clearTimeout(this._rebuildTableTask);
+ this._rebuildTableTask = null;
+ }
return;
}
this._initialResizePending = false;
this._rebuildHead();
this._rebuildBody();
- window.clearTimeout(this._rebuildTableTask);
- this._rebuildTableTask = null;
+
+ if( this._rebuildTableTask ){
+ window.clearTimeout(this._rebuildTableTask);
+ this._rebuildTableTask = null;
+ }
this._resizeTable();
+
+ dojo.lang.setTimeout(this,this._renewColumnSizers,10) ;
},
- _rebuildRow: function( row, depth, alternateRow ){
+
+ _rebuildRow: function( row, depth, alternateRow ){ //debug::this.loggit('_rebuildRow') ;
this.tbody.appendChild(row.domNode);
row.setDepth(depth);
for (var i = 0; i<row._rows.length; i++){
@@ -369,7 +643,7 @@
//even if we expanded only the very last row. If we add/remove/expand/contract
//a row we only really need to start recoloring at that node
//TODO efficiency
- _recolorAlternateRows: function(){
+ _recolorAlternateRows: function(){ //debug::this.loggit('_recolorAlternateRows') ;
if (!this._alternateRowClass) return;
var alternateRow = false;
for (var i =0; i<this._rows.length; i++){
@@ -378,7 +652,8 @@
},
- _recolorRow: function( row, alternateRow ){
+
+ _recolorRow: function( row, alternateRow ){ //debug::this.loggit('_recolorRow') ;
if (alternateRow){
dojo.html.addClass(row.domNode,this._alternateRowClass);
}
@@ -395,16 +670,314 @@
}
return alternateRow;
},
+
+ _isNotRoughedIn: function(){ //debug::this.loggit('_isNotRoughedIn') ;
+ return !this.isShowing()
+ || !this.domNode
+ ||!this.domNode.clientHeight
+ || !this.domNode.clientWidth
+ || !this.scrollDiv
+ ||!this.scrollDiv.clientHeight
+ || !this.scrollDiv.clientWidth
+ || !this.table
+ ||!this.table.clientHeight
+ || !this.table.clientWidth ;
+
+ },
+
+ _hasScrollbar: function(){ //debug::this.loggit('_hasScrollbar') ;
+ return this.scrollDiv.clientHeight - this.scrollDiv.offsetHeight ;
+ },
/*
* Support for dynamic sizing
*/
- setHeight:function(value){
- if (this.domNode) this.domNode.style.height = value;
- this.onResized();
+ setHeight:function(aHeight){ //debug::this.loggit('setHeight') ;
+ // If we don't have real (non-{zero-extent})
+ // domNode/scrollDiv/table, don't bother yet
+ // ---reschedule for a later time when
+ // they've arrived.
+ // TODO: Handle case where user _wants_
+ // a zero-height or -width table:
+ if ( this._isNotRoughedIn() ){
+ // Don't reschedule another one if
+ // one's there already:
+ if( !this._setHeightTask ){
+ this._setHeightTask
+ = dojo.lang.setTimeout(this,this.setHeight,100,aHeight) ;
+ }
+ return ;
+ }
+
+ if( this._setHeightTask ){
+ clearTimeout(this._setHeightTask) ;
+ this._setHeightTask = null ;
+ }
+
+ this.scrollDiv.style.height="100%" ;
+ this.scrollDiv.style.width="100%" ;
+// var scrollDivBox = dojo.html.getMarginBox(this.scrollDiv) ;
+// dojo.html.setMarginBox(this.scrollDiv,scrollDivBox) ;
+
+
+
+ // Table style might have been at "100%" in width or height;
+ // if that were so then when the scroll div were resized
+ // the table would too, and so not overflow:
+ if( this.table ){
+ var tableBox = dojo.html.getMarginBox(this.table) ;
+ dojo.html.setMarginBox(this.table,tableBox) ;
+ }
+
+ this._tableLayoutModel.lastVerticalScrollbarWidthPx =
+ this.getVerticalScrollbarWidthPx() ;
+ this.domNode.style.height = aHeight ;
+ this._tableLayoutModel.resetHeightPx= this.domNode.clientHeight ;
+
+ this._resetScrollDivLater(this._resetScrollDivDelayMs,"height")
+ },
+
+ _resetScrollDivLater: function(delay,dimensionChanged){ //debug::this.loggit('_rebuildTableLater') ;
+
+ //cancel any partial rebuild tasks
+ if (this._resetScrollDivTask){
+ window.clearTimeout(this._resetScrollDivTask);
+ this._resetScrollDivTask = null;
+ }
+
+ //if not already scheduled then schedule it
+ var theDelay = delay || 0 ;
+ if (!this._resetScrollDivTask){
+ this._resetScrollDivTask
+ = dojo.lang.setTimeout(this, this._resetScrollDiv, theDelay,dimensionChanged);
+ }
+ },
+
+ getExplicitWidth: function(){ //debug::this.loggit('getExplicitWidth') ;
+ var w = this._tableLayoutModel.resetWidthPx ;
+ if( !w ){
+ // Started with a width, haven't reset it:
+ w = this._tableLayoutModel.initialWidth ;
+ } else {
+ // resetWidthPx is in pixels...it better be:
+ w += "px" ;
+ }
+ return w ;
+ },
+ getExplicitHeight: function(){ //debug::this.loggit('getExplicitHeight') ;
+ var h = this._tableLayoutModel.resetHeightPx ;
+ if( !h ){
+ // Started with an height, haven't reset it:
+ h = this._tableLayoutModel.initialHeight ;
+ } else {
+ // resetHeightPx should only have been set in pixels:
+ h += "px" ;
+ }
+ return h ;
+ },
+
+ _resetScrollDiv: function(dimensionChanged){ //debug::this.loggit('_resetScrollDiv') ;
+
+ // When there's no argument here, assume both changed
+ var changedHeight = !dimensionChanged || (dimensionChanged=="height") ;
+ var changedWidth = !dimensionChanged ||(dimensionChanged=="width") ;
+
+ var w = this.getExplicitWidth() ;
+ var h = this.getExplicitHeight() ;
+
+ if(changedHeight ){
+ if(!w ){
+ // Width not rigid, so adjust
+ // so there's no horizontal scrollbar
+ this.scrollDiv.style.height=this.domNode.clientHeight - this.headerDiv.clientHeight +"px"
+ if( dojo.render.html.moz ){
+ this.domNode.style.width = "auto" ;
+ } else {
+ // if set to "auto" scrollbar ends up within domNode,
+ // necessitating an horizontal scrollbar
+ var newWidthPx =this.table.scrollWidth
+ + this.getVerticalScrollbarWidthPx()
+ + "px" ;
+ this.domNode.style.width = newWidthPx ;
+ }
+ } else if ( dojo.render.html.moz ){
+ // Fix mozilla so that we don't exceed the
+ // rigid width by a vertical scrollbar's worth:
+ this.domNode.style.width = w ;
+ }
+ }
+
+ if( changedWidth ){
+ if(!h ){
+ if( dojo.render.html.moz ){
+ this.domNode.style.height = "auto" ;
+ } else {
+ // if domNode height set to "auto" scrollbar,
+ // ends up within domNode, necessitating a
+ // vertical scrollbar
+ this.table.style.width = this.table.scrollWidth +"px" ;
+ var newScrollHeightPx = this.table.scrollHeight + 20 ;
+ this.domNode.style.height
+ = newScrollHeightPx +this.headerDiv.clientHeight +"px" ;
+ this.scrollDiv.style.height = newScrollHeightPx +"px" ;
+ }
+ } else if ( dojo.render.html.moz ){
+ // Fix mozilla so that we don't exceed the
+ // pre-set height by an horizontal scrollbar's worth:
+ this.domNode.style.height = h ;
+ }
+ }
+
+ if( w && h ){
+ var box = dojo.html.getContentBox(this.domNode) ;
+ box.height -= dojo.html.getMarginBox(this.headerDiv).height ;
+ if( dojo.render.html.moz ){
+// if( !this._tableLayoutModel.lastHorizontalScrollbarHeightPx){
+// box.height -= this.getHorizontalScrollbarHeightPx() ;
+// }
+ }
+ dojo.html.setMarginBox(this.scrollDiv, box) ;
+ }
+
+ dojo.lang.setTimeout(this,this.onEndSizing,1000) ;
+ // Puts a grey div in front of the upper-right corner if
+ // one is needed to hide the header there:
+ this._showUpperRightCorner();
},
- _isResized: function(w, h){
+
+ setWidth: function(aWidth){ //debug::this.loggit('setWidth') ;
+ // If we don't have real (non-{zero-extent})
+ // domNode/scrollDiv/table, don't bother yet
+ // ---reschedule for a later time when
+ // they've arrived.
+ // TODO: Handle case where user _wants_
+ // a zero-height or -width table:
+ if (this._isNotRoughedIn() ){
+ // Don't reschedule another one if
+ // one's there already:
+ if( !this._setWidthTask ){
+ this._setWidthTask
+ = dojo.lang.setTimeout(this,this.setWidth,100,aWidth) ;
+ }
+ return ;
+ }
+
+ this.scrollDiv.style.overflow="auto" ;
+
+
+ // Table style might have been at "100%" in width or height;
+ // if that were so then when the scroll div were resized
+ // the table would too, and so not overflow:
+ if( this.table ){
+ var tableBox = dojo.html.getMarginBox(this.table) ;
+ dojo.html.setMarginBox(this.table,tableBox) ;
+ }
+
+ this._tableLayoutModel.lastHorizontalScrollbarHeightPx
+ = this.getHorizontalScrollbarHeightPx() ;
+
+ var oWidth = (dojo.html.getContentBox(this.domNode)).width ;
+ this.scrollDiv.style.width = "100%" ;
+ this.domNode.style.width = aWidth ;
+ // We might have to move a grey box in the upper right:
+ this._showUpperRightCorner() ;
+
+ var fWidth = (dojo.html.getContentBox(this.domNode)).width ;
+
+
+ this._tableLayoutModel.resetWidthPx= fWidth ;
+
+ var deltaPx = fWidth - oWidth ;
+
+ if( deltaPx == 0 ){
+
+ } else if( deltaPx < 0){
+ // any need to do anything else?
+ } else {
+ // widened dom node:
+ if( !this.headerRow
+ || !this.headerRow.childNodes
+ || this.headerRow.childNodes.length == 0
+ ){
+ this._resetScrollDivLater(this._resetScrollDivDelayMs,"width") ;
+
+ return ;
+ }
+ // widened, but wider than the table?---if
+ // not, then we're eseentially done:
+ var deltaLastColumnPx
+ = fWidth - this.table.scrollWidth ;
+ if( deltaLastColumnPx >= 0 ){
+
+ var w = fWidth + "px" ;
+
+ this.table.style.width = "100%" ;
+ var tableWidth = this.table.clientWidth +"px" ;
+ this.table.style.width = tableWidth ;
+
+ this.headerDiv.style.width = "100%" ;
+ this.headerDiv.style.width = this.headerDiv.clientWidth +"px";
+ this.headerTable.style.width = tableWidth ;
+
+ this.columnsSizer.paneWidth = fWidth ;
+ this.columnsSizer.domNode.style.width = w ;
+ this.extendLastColumn(deltaLastColumnPx) ;
+ }
+ }
+
+ this._resetScrollDivLater(this._resetScrollDivDelayMs,"width") ;
+ },
+
+ extendLastColumn: function(changeInPixels){ //debug::this.loggit('extendLastColumn') ;
+
+ // Since their layout is fixed, this will mean that
+ // the tables in question will end up as wide as their
+ // columns (or first row cells, under IE) and borders
+ // will need. If we don't do this, space ends up getting
+ // added to or subtracted from (it seems) the first cell,
+ // which ends up with a width of "100%":
+ this.headerTable.style.tableLayout = "fixed" ;
+ this.headerTable.style.width = "auto" ;
+ this.table.style.width = "auto" ;
+ // We're extending the table past its rightmost
+ // column, so we definitely shouldn't get
+ // a horisontal scrollbar:
+ this.scrollDiv.style.width="auto";
+
+
+ var headerChildren = this.headerRow.childNodes ;
+ var len = headerChildren.length ;
+ var lastIdx = len - 1 ;
+ if(len > 0){
+ var newWidth = headerChildren[len-1].clientWidth ;
+ newWidth += changeInPixels ;
+ headerChildren[lastIdx].style.width = newWidth+"px";
+
+ var sizer = this.columnsSizer ;
+ // Put all the extra space in the last column:
+ sizer.children[lastIdx].sizeShare = newWidth ;
+ sizer.children[lastIdx].sizeActual = newWidth ;
+ this._columns[lastIdx].setStatedWidth(newWidth) ;
+ }
+
+
+
+ // Fix these widths (in the sense of "set them");
+ // leaving them free seems to hurt scrolling:
+ this.headerTable.style.width
+ = this.headerTable.scrollWidth +"px" ;
+ this.table.style.width
+ = this.headerTable.scrollWidth +"px" ;
+ // Match body to to the changed header column:
+ this._fixColumnWidths(lastIdx,lastIdx) ;
+ this.onEndSizing() ;
+ },
+
+
+
+
+ _isResized: function(w, h){ //debug::this.loggit('_isResized') ;
// summary
// Test if my size has changed.
// If width & height are specified then that's my new size; otherwise,
@@ -412,32 +985,65 @@
// If I'm not being displayed then disregard (show() must
// check if the size has changed)
- if(!this.isShowing()){ return false; }
+ if(!this.isShowing()){
+ return false;
+ }
// If my parent has been resized and I have style="height: 100%"
// or something similar then my size has changed too.
var wh = dojo.html.getMarginBox(this.domNode);
- var width=w||wh.width;
- var height=h||wh.height;
- if(this.width == width && this.height == height){ return false; }
-
- this.width=width;
- this.height=height;
+ var width = (w||wh.width) ;
+ var height = (h||wh.height) ;
+ var setWidth = this.getExplicitWidth() ;
+ var setHeight = this.getExplicitHeight() ;
+ if(setWidth == (width +"px") && setHeight == (height+"px")){
+ return false;
+ }
+// Hmmm...we should only reset these when
+// we perform a setWidth or setHeight.....
+// this._tableLayoutModel.width = width ;
+// this._tableLayoutModel.height = height ;
return true;
+ },
+
+ onResizedLater: function(delay){
+ //if a resize is pending don't bother
+ if (!this._onResizedTask ){
+ var theDelay = delay || 0 ;
+ this._onResizedTask
+ = dojo.lang.setTimeout(this, this.onResized, delay);
+ }
},
- onResized:function(){
- if ( this.scrollDiv && this.headerDiv){
- if (this._initialResizePending && this.width) {
- this._rebuildTableLater();
- }
- /* recalculate the content scrollDiv */
- var contentHt = "100%";
- var ht = this.domNode.clientHeight - this.headerDiv.clientHeight;
- if ( ht > 0 ) contentHt = ht + "px";
- this.scrollDiv.style.height = contentHt;
+ onResized:function(){ //debug::this.loggit('onResized') ;
+
+ if ( !this.scrollDiv || !this.headerDiv){
+ return ;
+ }
+
+ if( !this.domNode || !this.domNode.clientWidth
+ ||!this.domNode.clientHeight
+ ){
+ return ;
+ }
+
+ //cancel any partial rebuild tasks
+ if (this._onResizedTask){
+ window.clearTimeout(this._onResizedTask);
+ this._onResizedTask = null;
+ }
+
+
+ if (this._initialResizePending && this.getExplicitWidth()) {
+ this._rebuildTableLater();
}
+
+ // This is where most of the scrollbar-enabling
+ // logic that used to be in onResized() ended up:
+ this._resetScrollDivLater(0) ;
},
+
+
/**
*
*
@@ -446,7 +1052,7 @@
*
*/
- insertColumn: function(column, index){
+ insertColumn: function(column, index){ //debug::this.loggit('insertColumn') ;
column.setTable(this);
if (index && index>=0){
@@ -459,14 +1065,14 @@
//more efficient by inserting the column in place
},
- removeColumn: function(column){
+ removeColumn: function(column){ //debug::this.loggit('removeColumn') ;
xap.util.ArrayHelper.removeElement (this._columns,column);
//TODO efficiency
this._rebuildTableLater();
},
//index here is relative to parent row?
- insertRow: function(row, index){
+ insertRow: function(row, index){ //debug::this.loggit('insertRow') ;
if (index && index>=0){
xap.util.ArrayHelper.insertElementAt(this._rows,row,index);
}
@@ -477,12 +1083,12 @@
this._rowAdded(row);
},
- removeRow: function( row ){
+ removeRow: function( row ){ //debug::this.loggit('removeRow') ;
xap.util.ArrayHelper.removeElement (this._rows,row);
this._rowRemoved(row);
},
- _rowAdded: function(row){
+ _rowAdded: function(row){ //debug::this.loggit('_rowAdded') ;
row.setTable(this);
//if the row starts as selected when it is added,
@@ -500,10 +1106,21 @@
//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();
+
+ // TODO important: find out why the first row
+ // added to an IE table created with no rows
+ // gets messed-up column widths:
+ if(!this._created
+ || !dojo.render.html.ie
+ ||this._rows.length>1
+ ){
+ this._rebuildRowsLater();
+ } else {
+ this._rebuildTableLater(500);
+ }
},
- _rowRemoved: function(row){
+ _rowRemoved: function(row){ //debug::this.loggit('_rowRemoved') ;
if (this.isSelected(row)){
xap.util.ArrayHelper.removeElement(this._selectedItems, row);
@@ -524,51 +1141,66 @@
* Row selection stuff
*/
- selectRow: function(row){
+ selectRow: function(row){ //debug::this.loggit(' selectRow') ;
if (this.isSelected(row)){
return false;
}
if (this._selectionMode=="singleRow"){
this.clearSelection();
}
- dojo.html.addClass(row.domNode,"selectedRow");
+ dojo.html.addClass(row.domNode,this._selectedRowClass);
this._selectedItems.push(row);
return true;
},
- selectRowByUser: function(row){
+ // remove from selected items
+ deselectRow: function(row) {
+ var items = this._selectedItems;
+ if(items.length === 0) { return; }
+ for (var i = 0; i < items.length; i++) {
+ if(items[i] == row) {
+ dojo.html.removeClass(row.domNode, this._selectedRowClass);
+ this.onDeselectRow(row);
+ items.splice(i, 1);
+ }
+ }
+ },
+
+
+ selectRowByUser: function(row){ //debug::this.loggit(' selectRowByUser') ;
if (this.selectRow(row)){
this.onSelectRow(row);
}
},
- onSelectRow : function(row){
+ onSelectRow : function(row){ //debug::this.loggit(' onSelectRow ') ;
//event hook
},
- clearSelection : function(){
+ clearSelection : function(){ //debug::this.loggit(' clearSelection ') ;
for (var i =0; i<this._selectedItems.length; i++){
- dojo.html.removeClass(this._selectedItems[i].domNode,"selectedRow");
+ dojo.html.removeClass(this._selectedItems[i].domNode,this._selectedRowClass);
this.onDeselectRow(this._selectedItems[i]);
}
this._selectedItems = [];
},
- activateRow: function(row){
+ activateRow: function(row){ //debug::this.loggit(' activateRow') ;
this.onActivateRow(row);
},
- onDeselectRow : function(row){
+ onDeselectRow : function(row){ //debug::this.loggit(' onDeselectRow ') ;
//event hook
},
- onActivateRow : function(row){
+ onActivateRow : function(row){ //debug::this.loggit(' onActivateRow ') ;
//event hook
},
- isSelected: function(row){
- return (xap.util.ArrayHelper.indexOf(this._selectedItems,row)>=0);
- },
+ isSelected: function(row){ //debug::this.loggit(' isSelected') ;
+ var result = xap.util.ArrayHelper.indexOf(this._selectedItems,row) >= 0;
+ return result;
+ },
@@ -578,26 +1210,69 @@
*
*/
- onExpandRow : function(row, expanded){
- this._recolorAlternateRows();
- //event hook
- },
+ onExpandRow : function(row, expanded){ //debug::this.loggit('onExpandRow ') ;
+ this._recolorAlternateRows();
+ this._redoSplitPanelStyling(1000) ;
+ //event hook
+ },
+
+
+ _showUpperRightCorner: function(){
+ if( !this._upperRightCorner ){
+ this._upperRightCorner = document.createElement("DIV") ;
+ this._upperRightCorner.style.position="absolute" ;
+ this._upperRightCorner.style.display="" ;
+ this._upperRightCorner.style.visibility="visible" ;
+ this._upperRightCorner.style.top = "0px" ;
+ this._upperRightCorner.style.width = "0px" ;
+ this._upperRightCorner.style.height = "20px" ;
+ this._upperRightCorner.style.zIndex = 0 ;
+ //this._upperRightCorner.style.backgroundColor = "Scrollbar" ;
+ dojo.html.addClass(this._upperRightCorner,"xapHeaderBackground") ;
+ this.domNode.appendChild(this._upperRightCorner) ;
+ this._upperRightCorner._displayed = false ;
+
+ }
+
+ var w = this.getVerticalScrollbarWidthPx() ;
+
+ this._upperRightCorner.style.width = w +"px" ;
+ var heightFudge = 0 ;
+
+ this._upperRightCorner.style.height = (this.headerRow.clientHeight -heightFudge )+"px" ;
+ if(w){
+ this._upperRightCorner.style.left
+ = (this.domNode.clientWidth
+ - this._upperRightCorner.offsetWidth
+ ) +"px";
+ } else {
+
+ }
+
+ },
- onScrollCallback : function(event){
+ onScrollCallback : function(event){ //debug::this.loggit('onScrollCallback ') ;
if (this.scrollDiv){
+ // We have a vertical scrollbar, adjust header to
+ // look like it's to the left of it:
+ this.headerDiv.style.width
+ =(this.getVerticalScrollbarWidthPx()
+ + this.scrollDiv.scrollWidth
+ )+"px" ;
this.headerDiv.style.left = -this.scrollDiv.scrollLeft + "px";
+ this.splitterContainer.style.left =this.headerDiv.offsetLeft+"px";
}
},
- sortColumn: function( column ){
+ sortColumn: function( column ){ //debug::this.loggit('sortColumn') ;
//blank out the sort icon on the column we previously sorted
if (this._lastSortedColumn && (this._lastSortedColumn != column)){
- var oldHint = this._lastSortedColumn ._header.getImgHint();
- dojo.html.removeClass(oldHint,'xapSortDescendingImage');
- dojo.html.removeClass(oldHint,'xapSortAscendingImage');
- dojo.html.addClass(oldHint,'xapSortNoneImage');
+ this._lastSortedColumn.setSortNone() ;
+ // Block resizing the table
+ // as a result of this sort:
+ this._justSorted = true ;
}
var dataType = column._dataType || "string";
@@ -627,23 +1302,31 @@
}
+ var bSortAscending = !column._sort || column._sort=='descending' ;
+
//sort the array and change _rows to match
- this._rows.sort(sortFunction);
+ this._rows.sort( sortFunction ) ;
-
- var headerHint = column._header.getImgHint();
- if (!column._sort || column._sort=='descending'){
- column._sort = "ascending";
- dojo.html.removeClass(headerHint,'xapSortDescendingImage');
- dojo.html.addClass(headerHint,'xapSortAscendingImage');
+ if (bSortAscending){
+ column.setSortAsc();
+ // Block resizing the table
+ // (in the rebuildRows op.)
+ // as a result of this sort:
+ this._justSorted = true ;
}
else{
- column._sort = "descending";
- dojo.html.removeClass(headerHint,'xapSortAscendingImage');
- dojo.html.addClass(headerHint,'xapSortDescendingImage');
+ column.setSortDesc() ;
this._rows.reverse();
+
+ // Block resizing the table
+ // (in the rebuildRows op.)
+ // as a result of this sort:
+ this._justSorted = true ;
+
}
+
+
// before we do anything set the widths of what will become the new first row of cells
// so IE won't freak out (fixed layout without fixed sizes in the first inserted row)
if (dojo.render.html.ie){
@@ -654,7 +1337,7 @@
this._rebuildRowsLater();
},
- _sortStringsFunction: function(a, b){
+ _sortStringsFunction: function(a, b){ //debug::this.loggit('_sortStringsFunction') ;
var aVal = a._sortValue.toLowerCase();
var bVal = b._sortValue.toLowerCase();
if (aVal==bVal) return 0;
@@ -662,13 +1345,621 @@
return 1;
},
- _sortNumbersFunction: function(a, b){
+ _sortNumbersFunction: function(a, b){ //debug::this.loggit('_sortNumbersFunction') ;
var aVal = a._sortValue;
var bVal = b._sortValue;
if (aVal==bVal) return 0;
if (aVal<bVal) return -1;
return 1;
- }
+ },
+
+ _sizeSplitterContainer: function(){ //debug::this.loggit('_sizeSplitterContainer') ;
+ var box = {} ;
+
+ box.width = Math.max(this.domNode.scrollWidth,this.table.scrollWidth) ;
+ box.height = this.headerTable.clientHeight ;
+
+ dojo.html.setMarginBox(this.splitterContainer,box) ;
+ },
+
+ _addSplitterPane: function(aBox, lastPaneP){
+ var widg = dojo.widget.createWidget("DivWrapper",aBox) ;
+ // This is the proportion of the entire split
+ // pane given over to this panel:
+ var dom = widg.domNode ;
+
+ widg.sizeShare = aBox.width ;
+ this.columnsSizer.addChild( widg ) ;
+ if( lastPaneP ){
+ widg.sizeMin = 0 ;
+ this._lastSplitterPane = widg.domNode ;
+ }
+ },
+
+ // Add sizers for the columns that have just been built:
+ // TODO: Re-write table so that the header is already
+ // a split container instead of a table row---should make
+ // things much simpler here:
+ _renewColumnSizers: function(){ //debug::this.loggit('_renewColumnSizers') ;
+ if( !this.headerDiv || !this._columns|| this._columns.length==0 ){
+ return ;
+ }
+
+
+
+ var sizer = this.columnsSizer ;
+ if( sizer ){
+ dojo.event.disconnect(
+ sizer,
+ sizer.endSizing,
+ this,
+ this.onEndSizing
+ ) ;
+ dojo.event.disconnect(
+ sizer,
+ sizer.beginSizing,
+ this,
+ this.onBeginSizing
+ ) ;
+
+
+ if( this.splitterContainer ){
+ this.splitterContainer.parentNode.removeChild(this.splitterContainer) ;
+ }
+ delete this.columnsSizer ;
+ }
+
+ this.splitterContainer
+ = this.domNode.appendChild(document.createElement("div")) ;
+ var splitterContainer = this.splitterContainer ;
+ var splitterContainerStyle = splitterContainer.style ;
+ splitterContainerStyle.position = "absolute" ;
+ splitterContainerStyle.display = "block" ;
+ splitterContainerStyle.top = "0px" ;
+ splitterContainerStyle.left = "0px" ;
+
+ var box = {} ;
+
+
+ this._sizeSplitterContainer() ;
+
+
+
+ // Get a more accurate result with
+ // a splitter width of 1px; make wider
+ // at rest...
+ this.columnsSizer =
+ dojo.widget.createWidget(
+ "SplitContainer",
+ {
+ height:1,
+ width:box.width,
+ sizerWidth:1,
+ persist:false,
+ activeSizing:false
+ },
+ splitterContainer
+ );
+
+
+ this._alterSizerMethods() ;
+
+ splitterContainerStyle.zIndex = 0 ;
+
+
+ var h = this.domNode.offsetHeight +"px" ;
+
+ // Add a splitter panel for each header:
+ for (var ii = 0; ii<this.headerRow.childNodes.length; ++ii){
+ var node = this.headerRow.childNodes[ii] ;
+ var box = dojo.html.getMarginBox(node) ;
+ this._addSplitterPane(box) ;
+ }
+
+ // Add an additional panel for any space that might
+ // exist between the last true column and the right
+ // edge of the table:
+ var box = {height: this.headerDiv.clientHeight,
+ width: this.domNode.scrollWidth - this.headerTable.scrollWidth
+ }
+ this._addSplitterPane(box,true) ;
+
+ this._lastSizer
+ = this.columnsSizer.sizers[this.columnsSizer.sizers.length - 1] ;
+// This was recreating the sizers,producing too
+// many of them, and appears to be unneeded:
+// this.columnsSizer.postCreate() ;
+
+ dojo.lang.setTimeout(this,this._applyBasicSizerStyling,0) ;
+
+
+ //this.columnsSizer._layoutPanels();
+
+
+
+ // Trigger out methods when the splitter
+ // beings and ends dragging a sizer line:
+ dojo.event.connect(
+ this.columnsSizer,
+ this.columnsSizer.endSizing,
+ this,
+ this.onEndSizing
+ ) ;
+ dojo.event.connect(
+ this.columnsSizer,
+ this.columnsSizer.beginSizing,
+ this,
+ this.onBeginSizing
+ ) ;
+ // Firefox seems to leave this in a weird state, out of the
+ // gate, that produces doubled sizer if the parent window
+ // is resized
+ if( dojo.render.html.moz ){
+ dojo.event.connectOnce(
+ window,
+ window.onresize,
+ this,
+ this.onEndSizing
+ ) ;
+ }
+
+ this._redoSplitPanelStyling();
+ this.onEndSizing();
+ },
+
+ _applyBasicSizerStyling: function(){
+
+ var lastSizer = null ;
+ for( var idx = 0; idx < this.columnsSizer.sizers.length; ++idx){
+
+ var aSizer = this.columnsSizer.sizers[idx] ;
+//*debug*/ aSizer.id = this.domNode.id + "_sizer_"+idx ;
+//*debug*/ aSizer.setAttribute("id",aSizer.id) ;
+//*debug*/ dojo.html.addClass(aSizer, "sizer_"+idx) ;
+ aSizer.style.visibility="hidden" ;
+ aSizer.style.height =
+ /*(this.headerRow.clientHeight)*/0 +"px" ;
+ dojo.html.removeClass(aSizer, "dojoSplitContainerSizerH") ;
+ dojo.html.addClass(aSizer, "xapTableStationarySizers") ;
+ // No need to see the sizers; they should
+ // line up with the header boundaries
+ // --if they're off by a lot (O(5px))
+ // we'll care, but if they're off
+ // by ~1px we're better off not seeing
+ // them. Full accuracy is probably impossible
+ // until the headerTable itself is made a
+ // splitter container descendent:
+ aSizer.style.visibility="visible" ;
+ // Good Dojo!
+ dojo.html.setOpacity(aSizer,1.0);
+
+ aSizer.style.backgroundColor="Scrollbar" ;
+ this._fixSizerWidthAndPosition(idx) ;
+
+ aSizer._xapReformatted = true ;
+ lastSizer = aSizer ;
+ }
+
+ dojo.html.setOpacity(lastSizer,0.5);
+ },
+
+ _fixSizerWidthAndPosition: function(index){
+ var sizerNode = this.columnsSizer.sizers[index] ;
+ var left = null ;
+ var lastNode = null
+ if( index < this.headerRow.childNodes.length - 1 ){
+ lastNode = this.headerRow.childNodes[index+1] ;
+ left
+ = this.headerRow.childNodes[index+1].offsetLeft ;
+
+ } else {
+ // Pseudo-column at the end:
+ left
+ = dojo.html.getMarginBox(this.headerTable).width ;
+ }
+ // under Firefox, looks like we're off by a border width
+ // or something (margin?)
+ // TODO: Do a better job explaining this.
+ if(dojo.render.html.moz){
+ left += 1 ;
+ }
+
+
+
+ // Now we're setting the sizer to be visible (see )
+ // and it's only 1px wide; if we went back to the older way
+ // (wider invisible sizers centred about the proper line)
+ // we'll need that (width/2) factor---innoccuous now:
+ sizerNode.style.left
+ = (left -Math.floor(this._sizerWidth/2)) +"px";
+ sizerNode.style.width=this._sizerWidth +"px" ;
+ sizerNode.style.height = (this.headerRow.clientHeight - 1)+"px";
+ sizerNode.style.top = "1px" ;
+ },
+
+
+ _fixAllSizerWidthsAndPositions: function(){
+ // Readjust sizer handles to match
+ // headers:
+ if( !this.columnSizer ){
+ return ;
+ }
+ var sizerHandles = this.columnSizer.sizers ;
+ if( sizerHandles ){
+ return ;
+ }
+
+ for(var kk=0; kk < sizerHandles.length ; ++kk){
+ // Widen the sizers so they're more selectable:
+ //---sizers behave more accurately when they're
+ // slimmer, but are harder to select....
+ this._fixSizerWidthAndPosition(kk) ;
+ }
+ },
+
+
+ _redoSplitPanelStyling: function(delay){ //debug::this.loggit('_redoSplitPanelStyling') ;
+ if( delay != undefined ){
+ this._redoSplitPanelStylingTask
+ = dojo.lang.setTimeout(this,this._redoSplitPanelStyling,delay) ;
+ return ;
+ }
+ if( this._redoSplitPanelStylingTask ){
+ window.clearTimeout(this._redoSplitPanelStylingTask) ;
+ this._redoSplitPanelStylingTask = null ;
+ }
+
+ var sizer = this.columnsSizer ;
+
+ if(!sizer ){
+ return ;
+ }
+
+ var sizerDomNode = sizer.domNode ;
+
+ this._sizeSplitterContainer() ;
+ sizer.onResized(null) ;
+
+ var sizerDivs = sizer.sizers ;
+ var sizerPanes = sizer.children ;
+
+ // We end up with superfluous sizers at the
+ // end of the list; trim them:
+ // TODO: Keep them from showing up in the
+ // first place.
+ var nColumns = this._columns.length ;
+
+ if( nColumns==0 ){
+ // No columns, no sizers:
+ return ;
+ }
+
+ // One for each real inter-column border, one for the
+ // border between the last column and the rightmost,
+ // spacer, pseudo-column:
+ var nSizers = nColumns ;
+
+ var remainingWidthPx
+ = this.columnsSizer.paneWidth ;
+
+ for(var ii=0; ii<sizerPanes.length; ++ii){
+ var sizerPane = sizerPanes[ii] ;
+
+ if( this.headerRow.childNodes[ii] ){
+ // This is a pane corresponding to a header cell:
+ var w = dojo.html.getMarginBox(this.headerRow.childNodes[ii]).width ;
+ sizerPane.sizeShare = w ;
+ sizerPane.sizeActual = w ;
+ sizerPane.domNode.style.width = (w)+"px" ;
+ remainingWidthPx -= w ;
+ } else {
+ // this is the extra pane on the right
+ sizerPane.sizeShare = remainingWidthPx ;
+ sizerPane.sizeActual = remainingWidthPx ;
+ sizerPane.domNode.style.width = (remainingWidthPx)+"px" ;
+ }
+ }
+ sizer._layoutPanels() ;
+
+ if( dojo.render.html.ie ){
+ this._hideSplitterPanelsAndShowSizers(500) ;
+ } else {
+ this._hideSplitterPanelsAndShowSizers(0) ;
+ }
+ },
+
+ _hideSplitterPanelsAndShowSizers: function(delay){
+ if( delay != undefined ){
+ this._hideSplitterPanelsAndShowSizersTask
+ = dojo.lang.setTimeout(this,this._hideSplitterPanelsAndShowSizers,delay) ;
+ return ;
+ }
+ // Don't bother if there are no columns or,
+ // if we haven't built the full header row yet:
+ //("this.columnsSizer.children.length-1" because
+ // we have an extra split pane for the rightmost, spacer,
+ // pseudo-column:
+ if( !this._columns
+ ||(this._columns.length==0)
+ || (this._columns.length != (this.columnsSizer.children.length-1) )
+ ){
+ return ;
+ }
+
+ if( this._hideSplitterPanelsAndShowSizersTask ){
+ window.clearTimeout(this._hideSplitterPanelsAndShowSizersTask ) ;
+ this._hideSplitterPanelsAndShowSizersTask = null ;
+ }
+//debug::this.loggit('_hideSplitterPanelsAndShowSizers') ;
+ this._applyBasicSizerStyling() ;
+
+ // Figure out now if we'r in a browser
+ // that will need an explicitly transparent
+ // background colour---IE6 under XP
+ var isXpIe6 =
+ dojo.render.html.ie60 &&
+ ( dojo.render.html.UA.indexOf("Windows NT 5.1") != -1 ) ;
+
+ var sizer = this.columnsSizer ;
+ var parent = this.columnsSizer.domNode ;
+ var sizerHandles = sizer.sizers ;
+ var splitterPanes = this.columnsSizer.children ;
+ // Under Firefox and IE7, this is innocuous
+ // and in fact necessary to get the splitter
+ // dom node out of the way of the column headers.
+ // under IE6 this screws up the sizing of
+ // the splitter dom node, making it 0-by-0:
+ if(!isXpIe6){
+ parent.style.visibility = "hidden" ;
+ }
+
+
+ for(var ii=0; ii < this._columns.length; ++ii){
+ var sizerHandle = sizerHandles[ii] ;
+ var sizerHandleStyle = sizerHandle.style ;
+ sizerHandleStyle.visibility = "visible" ;
+ sizerHandleStyle.zIndex = 0 ;
+
+// Now, sizers are thin (1px) and visible:
+// if(isXpIe6){
+// /* Can't set it to "transparent" in CSS because
+// because that removes selectability under IE7;
+// ---instead, apply it in code to IE6/XP, which is
+// the only place it's needed,as the stylesheet's
+// {0 opacity} xor {alpha-filter stuff} works fine in Fire-
+// fox, IE7, and IE6/Win2K.
+// */
+// // To debug, you'll probably want to
+// // set this to something more noticeable:
+// sizerHandleStyle.backgroundColor="transparent" ;
+// }
+ }
+
+ var headers = this.headerRow.childNodes ;
+ var totalSizeShare = 0 ;
+ for(var jj=0; jj < headers.length; ++jj){
+ var paneWidget = splitterPanes[jj] ;
+ var paneStyle = paneWidget.domNode.style ;
+ paneStyle.visibility="hidden" ;
+ paneStyle.zIndex = 500 ;
+ paneWidget.sizeShare
+ = dojo.html.getMarginBox(headers[jj]).width ;
+ paneWidget.sizeActual = paneWidget.sizeShare ;
+ totalSizeShare += paneWidget.sizeShare ;
+ }
+ // style the spacer pane at the far right to avoid
+ // a weird effect under ie that displays overflowed
+ // text from the rightmost header
+ // TODO: eliminate headerDiv, since this does
+ // the same filling-in thing, more effectively?
+ var paneWidget = splitterPanes[headers.length] ;
+ var paneStyle = paneWidget.domNode.style ;
+ paneStyle.visibility="visible" ;
+// dojo.html.addClass(paneWidget.domNode,"xapHeaderBackground");
+ paneStyle.zIndex = 0 ;
+ paneWidget.sizeShare
+ = this.splitterContainer.clientWidth
+ - totalSizeShare ;
+ paneWidget.sizeActual = paneWidget.sizeShare ;
+
+ // Readjust sizer handles to match
+ // headers:
+ this._fixAllSizerWidthsAndPositions() ;
+
+ if(sizer.virtualSizer){
+ sizer.virtualSizer.style.visibility = "visible" ;
+ }
+ },
+
+ onBeginSizing: function(e){ //debug::this.loggit('onBeginSizing') ;
+
+
+ // Find out which sizer handle was grabbed:
+ this._grabbedSizer = e.target ;
+
+ var sizers = this.columnsSizer.sizers ;
+ if( this._grabbedSizer == this._lastSizer ){
+ this._lastTableRightPx
+ = this._lastSizer.offsetLeft ;
+ this._grabbedSizerIndex
+ = sizers.length - 1 ;
+ this._grabbedTheLastSizer = true ;
+ } else {
+ // Find which one we grabbed:
+ var idx = -1 ;
+ for( idx = -1 ; idx < sizers.length - 1; ++idx){
+ if( sizers[idx] == this._grabbedSizer ){
+ break ;
+ }
+ }
+ this._grabbedSizerIndex = idx ;
+ }
+
+
+ var dragger = this.columnsSizer.virtualSizer ;
+
+
+
+ dojo.html.removeClass( dragger, "dojoSplitContainerVirtualSizerH" ) ;
+ dojo.html.addClass( dragger, "xapTableMovingSizer" ) ;
+ // Can't cache: table height might changed
+ dragger.style.height
+ = (this.scrollDiv.offsetHeight + this.headerDiv.clientHeight)+"px" ;
+ dragger.style.width = "1px" ;
+ // Bring splitter container to front so
+ // that we're not getting the column mouseover effects:
+ this.splitterContainer.style.visibility = "visible" ;
+ this.splitterContainer.style.overflow = "visible" ;
+ },
+
+ onEndSizing: function(e){ //debug::this.loggit('onEndSizing') ;
+ if(this.columnsSizer && this.columnsSizer.virtualSizer){
+ dojo.html.removeClass( this.columnsSizer.virtualSizer, "xapTableMovingSizer" ) ;
+ }
+ // Was set to "visible" to show taller-than-header dragging sizer:
+ if( this.splitterContainer ){
+ this.splitterContainer.style.overflow = "hidden" ;
+ }
+
+ // user grabbed the last sizer:
+ if( this._grabbedTheLastSizer && this._lastTableRightPx ){
+
+ // The last sizer corresponds to a non-column;
+ // it defines the right boundary of the table:
+ var currentTableRightPx = this._lastSizer.offsetLeft ;
+
+ var deltaTableRightPx
+ = currentTableRightPx
+ - this._lastTableRightPx ;
+
+ // As soon as possible, avoid muddying the waters
+ // for the next drag:
+ delete this._lastTableRightPx ;
+ delete this._grabbedSizerIndex ;
+ delete this._grabbedTheLastSizer ;
+
+ this.extendLastColumn(deltaTableRightPx) ;
+
+ return ;
+ }
+ // else---all other sizers:
+//debug: alert("gsi: "+this._grabbedSizerIndex) ;
+ if( this._grabbedSizerIndex > -1 ){
+ dojo.lang.setTimeout(
+ this,
+ this._reconcileHeaderAndBodyColumns,
+ 10,
+ this._grabbedSizerIndex,
+ this._grabbedSizerIndex + 1
+ ) ;
+ } else {
+ // Can't identify the sizer grabbed:
+ dojo.lang.setTimeout(
+ this,
+ this._reconcileHeaderAndBodyColumns,
+ 10
+ ) ;
+ }
+ },
+
+ // With arguments, should only adjust the columns in the
+ // range:
+ _reconcileHeaderAndBodyColumns: function(pStartCol,pEndCol){ //debug::this.loggit('_reconcileHeaderAndBodyColumns') ;
+
+
+ var startCol = 0 ;
+ var endCol = this._columns.length - 1 ;
+ if( pStartCol ){
+ startCol = pStartCol ;
+ if( pEndCol ){
+ endCol = pEndCol ;
+ }
+ }
+
+ if(!this.columnsSizer){
+ this._fixColumnWidths();
+ for (var i =0; i<this._rows.length; i++){
+ this._rebuildRow(this._rows[i], 0);
+ }
+ return ;
+ }
+
+
+
+ this.columnsSizer._layoutPanels() ;
+
+ // tell the columns how wide they ought to be:
+ var children = this.columnsSizer.children ;
+
+//debug: alert(pStartCol+":"+pEndCol+"----"+startCol+":"+endCol) ;
+ for(var ii=startCol ; ii < endCol+1; ++ii ){
+
+ var w = children[ii].sizeShare ;
+
+ var wPx = w +"px" ;
+ this._columns[ii].setStatedWidth(w) ;
+ this._columns[ii]._explicitColumnWidth = wPx ;
+ dojo.html.setMarginBox(
+ this._columns[ii].domNode,
+ {width:w}
+ ) ;
+ dojo.html.setMarginBox(
+ this.headerRow.childNodes[ii],
+ {width:w}
+ ) ;
+ this.headerRow.childNodes[ii].style.overflow="hidden";
+ }
+
+
+
+
+ this._fixColumnWidths() ;
+ //now repopulate the body rows using the good new columns:
+ for (var i =0; i<this._rows.length; i++){
+ this._rebuildRow(this._rows[i], 0);
+ }
+
+ // hide split panels, otherwise they'd
+ // block mouse events to the column headers
+ // they're over:
+ this._hideSplitterPanelsAndShowSizers(10) ;
+
+ } ,
+
+
+ _alterSizerMethods: function(){
+ this.columnsSizer._addSizer=function() {
+ // Altered so that the sizer won't flash
+ // as much on creation:
+ var i = this.sizers.length;
+
+ this.sizers[i] = document.createElement('div');
+ this.sizers[i].style.position = 'absolute';
+ /* Altered:*/
+ this.sizers[i].style.height="1px" ;
+ /* Altered. */
+ this.sizers[i].className = this.isHorizontal ? 'dojoSplitContainerSizerH' : 'dojoSplitContainerSizerV';
+
+ var self = this;
+ var handler = (function(){ var sizer_i = i; return function(e){ self.beginSizing(e, sizer_i); } })();
+ dojo.event.connect(this.sizers[i], "onmousedown", handler);
+
+ this.domNode.appendChild(this.sizers[i]);
+ dojo.html.disableSelection(this.sizers[i]);
+ } ;
+ this.columnsSizer.onResized = function(e){
+ var content = dojo.html.getContentBox(this.domNode);
+ this.paneWidth = content.width;
+ // Alter this so we can have a drag-line
+ // the height of the whole box, but not
+ // the static sizer handles:
+ //this.paneHeight = content.height;
+ this._layoutPanels();
+ } ;
+
+ }
+
+
}
);
@@ -691,23 +1982,66 @@
templateCssPath: null ,
widgetType: "TableColumn",
isContainer: true,
+ _horizontalAlignment: "left",
-
+ ascImageUri:dojo.uri.moduleUri("xap","widgets/dojo/images/arrow_up.gif"),
+ descImageUri:dojo.uri.moduleUri("xap","widgets/dojo/images/arrow_down.gif"),
+ noneImageUri:dojo.uri.moduleUri("xap","widgets/dojo/images/spaced.gif"),
+
//we need this because setting the template string to
//<col></col> doesn't work for whatever reason,
//oversight in dojo code
fillInTemplate: function(args, frag){
this.domNode = document.createElement("col");
},
+
+ setSortNone: function(){
+ var xapLabel = this._header ;
+ var oldHint = xapLabel.getImgHint();
+ dojo.html.removeClass(oldHint,'xapSortDescendingImage');
+ dojo.html.removeClass(oldHint,'xapSortAscendingImage');
+ dojo.html.addClass(oldHint,'xapSortNoneImage');
+ delete this._sort ;
+ },
+
+ setSortDesc: function( ){
+ var xapLabel = this._header ;
+ var oldHint = xapLabel.getImgHint();
+ dojo.html.removeClass(oldHint,'xapSortNoneImage');
+ dojo.html.removeClass(oldHint,'xapSortAscendingImage');
+ dojo.html.addClass(oldHint,'xapSortDescendingImage');
+ this._sort = "descending" ;
+ },
+
+ setSortAsc: function( ){
+ var xapLabel = this._header ;
+ var oldHint = xapLabel.getImgHint();
+ dojo.html.removeClass(oldHint,'xapSortNoneImage');
+ dojo.html.removeClass(oldHint,'xapSortDescendingImage');
+ dojo.html.addClass(oldHint,'xapSortAscendingImage');
+ this._sort = "ascending" ;
+ },
+
setHeader: function( xapLabel ){
this._header = xapLabel;
- dojo.html.addClass(xapLabel.getImgHint(),'xapSortNoneImage');
+ this.setSortNone();
dojo.event.connect(xapLabel._rootDomNode, "onclick", this, "onClickCallback");
+
- // if there are explicit widths then save those
- if ( xapLabel._rootDomNode.style.width )
+ // if there's an explicitly-set width in the header
+ // then save it, else stick with any we might have got from XAL:
+ if ( xapLabel._rootDomNode.style.width ){
this._headerWidth = xapLabel._rootDomNode.style.width;
+ }
+ // if no h-align stated, use column's if exists,
+ // else default to "left":
+ var hAlign = xapLabel._horizontalAlignment
+ || this._horizontalAlignment
+ || "left" ;
+
+ dojo.lang.setTimeout(xapLabel,xapLabel.setAlignHorizontal,0,hAlign);
+
},
setTable: function(table){
@@ -718,7 +2052,37 @@
if (this._table){
this._table.sortColumn(this);
}
+ },
+
+ getStatedWidth: function(){
+ return this._sStatedWidth ;
+ },
+
+ setStatedWidth: function(val){
+ var res = val ;
+ // We want a string value that
+ // can be used to directly set
+ // a style object member:
+ if(!isNaN(val)){
+ res += "px" ;
+ }
+ this._sStatedWidth = res ;
+ },
+
+ getBestWidth: function(){
+ var res = this.getStatedWidth() ;
+ if( !res ){
+ // Use column width; if not set,
+ // use header width:
+ if( res = this._explicitColumnWidth ){
+ } else if( res = this._headerWidth ){
+ }
+ }
+ return res ;
}
+
+
+
});
@@ -767,21 +2131,37 @@
//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
- addCell : function( cell , cellInfo){
+ addCell : function( cell , cellInfo, columnIndex){
this._cellInfo.push(cellInfo);
var td = document.createElement("td");
this.domNode.appendChild(td);
td.style.whiteSpace = "nowrap";
- td.align="left";
+ td.style.overflow = "hidden";
+ cell.style.whiteSpace = "nowrap";
+ cell.style.overflow = "hidden";
+
+ var hAlignment = null ;
+ if ( cell.style.textAlign ) {
+ hAlignment = cell.style.textAlign;
+ } else {
+ var col = this._table._columns[columnIndex] ;
+ if(col){
+ hAlignment = col._horizontalAlignment ;
+ }
+ }
+
+ if( hAlignment ){
+ td.align = hAlignment ;
+ }
+
+
td.valign = "top";
// read cell attributes and apply to the td
if ( cell.style.backgroundColor ){
td.style.backgroundColor = cell.style.backgroundColor;
}
- if ( cell.style.textAlign ) {
- td.align = cell.style.textAlign;
- }
+
if (this._table && this._table._tableCellClass){
dojo.html.addClass(td,this._table._tableCellClass);
@@ -791,7 +2171,8 @@
//everywhere???
if (!this._indentSpan){
this._indentSpan = document.createElement("span");
- td.appendChild(this._indentSpan);
+ this._indentSpan.style.overflow= "hidden" ;
+ this._indentSpan.style.whitespace= "nowrap" ; td.appendChild(this._indentSpan);
this._indentSpan.innerHTML = " ";
dojo.event.connect(this._indentSpan, "onclick", this, "onExpandCallback");
this._adjustImage();
@@ -823,13 +2204,13 @@
newClass = "ImgNodeCollapsed";
}
dojo.html.addClass(this._indentSpan, newClass);
- this._imageClass= newClass;
+ this._imageClass = newClass;
},
setDepth : function( depth ){
this._depth = depth;
if (this._indentSpan){
- this._indentSpan.style.marginLeft = (depth*10)+"px";
+ this._indentSpan.style.marginLeft = (depth*12)+"px";
}
},
@@ -854,10 +2235,20 @@
// occurs
// ALSO we need to write back to the Xml element when the user selects or de-selects
// a row.
- this._selected = selected;
- if (this._table && selected){
- this._table.selectRow(this);
- }
+ if( (selected != this._lastSelected) ) {
+ this._lastSelected = selected;
+ if (this._table) {
+ if(selected === true) {
+ this._table.selectRow(this);
+ return;
+ }
+ if(selected === false) {
+ this._table.deselectRow(this);
+ delete this._lastSelected;
+ return;
+ }
+ }
+ }
},
//if we set to invis, set all children to invis as well
@@ -913,4 +2304,137 @@
}
}
-});
\ No newline at end of file
+});
+
+
+
+
+
+
+//Debugging:
+/*
+xap.widgets.dojo.TreeTable.prototype.getWidths = function(){
+
+ var s = "width\tdom\tscroll\ttable\ttbody\theaderDiv\theaderTable" ;
+
+ s += "^style" ;
+ s+= "\t"+this.domNode.style.width;
+ s+= "\t"+this.scrollDiv.style.width;
+ s+= "\t"+this.table.style.width;
+ s+= "\t"+this.tbody.style.width;
+ s+= "\t"+this.headerDiv.style.width;
+ s+= "\t"+this.headerTable.style.width;
+
+ s += "^client" ;
+ s+= "\t"+this.domNode.clientWidth;
+ s+= "\t"+this.scrollDiv.clientWidth;
+ s+= "\t"+this.table.clientWidth;
+ s+= "\t"+this.tbody.clientWidth;
+ s+= "\t"+this.headerDiv.clientWidth;
+ s+= "\t"+this.headerTable.clientWidth;
+
+ s += "^offset" ;
+ s+= "\t"+this.domNode.offsetWidth;
+ s+= "\t"+this.scrollDiv.offsetWidth;
+ s+= "\t"+this.table.offsetWidth;
+ s+= "\t"+this.tbody.offsetWidth;
+ s+= "\t"+this.headerDiv.offsetWidth;
+ s+= "\t"+this.headerTable.offsetWidth;
+
+ s += "^scroll" ;
+ s+= "\t"+this.domNode.scrollWidth;
+ s+= "\t"+this.scrollDiv.scrollWidth;
+ s+= "\t"+this.table.scrollWidth;
+ s+= "\t"+this.tbody.scrollWidth;
+ s+= "\t"+this.headerDiv.scrollWidth;
+ s+= "\t"+this.headerTable.scrollWidth;
+
+
+ prompt("",s);
+
+}
+
+xap.widgets.dojo.TreeTable.prototype.getHeights = function(){
+
+ var s = "height\tdom\tscroll\ttable\ttbody\theaderDiv\theaderTable" ;
+
+ s += "^style" ;
+ s+= "\t"+this.domNode.style.height;
+ s+= "\t"+this.scrollDiv.style.height;
+ s+= "\t"+this.table.style.height;
+ s+= "\t"+this.tbody.style.height;
+ s+= "\t"+this.headerDiv.style.height;
+ s+= "\t"+this.headerTable.style.height;
+
+ s += "^client" ;
+ s+= "\t"+this.domNode.clientHeight;
+ s+= "\t"+this.scrollDiv.clientHeight;
+ s+= "\t"+this.table.clientHeight;
+ s+= "\t"+this.tbody.clientHeight;
+ s+= "\t"+this.headerDiv.clientHeight;
+ s+= "\t"+this.headerTable.clientHeight;
+
+ s += "^offset" ;
+ s+= "\t"+this.domNode.offsetHeight;
+ s+= "\t"+this.scrollDiv.offsetHeight;
+ s+= "\t"+this.table.offsetHeight;
+ s+= "\t"+this.tbody.offsetHeight;
+ s+= "\t"+this.headerDiv.offsetHeight;
+ s+= "\t"+this.headerTable.offsetHeight;
+
+ s += "^scroll" ;
+ s+= "\t"+this.domNode.scrollHeight;
+ s+= "\t"+this.scrollDiv.scrollHeight;
+ s+= "\t"+this.table.scrollHeight;
+ s+= "\t"+this.tbody.scrollHeight;
+ s+= "\t"+this.headerDiv.scrollHeight;
+ s+= "\t"+this.headerTable.scrollHeight;
+
+
+ prompt("",s);
+
+}
+*/
+
+/**
+ * Animate the width out to a given value---in intermediate steps,
+ * just changes the dom node and nothing else(for speed's sake).
+ * Careful using the last two parameters---can override total time requirement;
+ * best to call either as <code>animateToWidth(width,time)</code>
+ * or as <code>animateToWidth(width,null,δwidth[px]/step,time[ms]/step).</code>
+ * @param finalWidthPx{integer} final width in pixels for the table. Required.
+ * @param totalTimeMs{integer} nominal total time for the animation. Required.
+ * @param pDeltaWPx{integer} width change per animation step.
+ * @param pDelayMs{integer} step time.
+ **/
+xap.widgets.dojo.TreeTable.prototype.animateToWidth = function(finalWidthPx,pTotalTimeMs,pDeltaWPx,pDelayMs){
+ if( !finalWidthPx ){
+ return ;
+ }
+ var deltaW = pDeltaWPx ;
+ if(!pDeltaWPx){
+ deltaW = 5 ;
+ }
+ var w = foo.domNode.clientWidth ;
+ var diff = finalWidthPx - w ;
+ var sign = (diff>0)?+1:-1;
+ if( (diff*sign) < deltaW ){
+ this.setWidth(finalWidthPx +"px") ;
+ return ;
+ } else {
+ var delay = pDelayMs ;
+ if(!pDelayMs){
+ if(!pTotalTimeMs){
+ this.setWidth(finalWidthPx +"px") ;
+ return ;
+ }
+ delay
+ = Math.max(1, Math.floor((deltaW*pTotalTimeMs)/(sign*diff))) ;
+ }
+ // Don't _try_ to do a good setWidth---do that at the end.
+ this.domNode.style.width = ((w+(deltaW*sign))+"px") ;
+ dojo.lang.setTimeout(this,this.animateToWidth,delay,finalWidthPx,null,deltaW,delay);
+ }
+}
+
+