Hierarchical display works!! Need a way to check to see if a container is empty.

This commit is contained in:
David Norton 2006-05-16 19:33:44 +00:00
parent 5fb98853bc
commit c51f612098
2 changed files with 44 additions and 50 deletions

View file

@ -14,9 +14,7 @@ Scholar.TreeView.prototype.setTree = function(treebox)
var newRows = Scholar.Objects.getTreeRows(); var newRows = Scholar.Objects.getTreeRows();
for(var i = 0; i < newRows.length; i++) for(var i = 0; i < newRows.length; i++)
{ this._dataObjects.push( [ newRows[i], false, 0 ] ); //object ref, isContainerOpen, level
this._dataObjects.push( [ newRows[i],false ] );
}
this.rowCount = this._dataObjects.length; this.rowCount = this._dataObjects.length;
} }
@ -35,63 +33,50 @@ Scholar.TreeView.prototype.getCellText = function(row, column)
else else
{ {
if(column.id == "title_column") if(column.id == "title_column")
{
return obj.getField("title"); return obj.getField("title");
}
else if(column.id == "creator_column") else if(column.id == "creator_column")
{
return obj.getField("firstCreator"); return obj.getField("firstCreator");
}
else else
{
return obj.getField("source"); return obj.getField("source");
} }
}
}
Scholar.TreeView.prototype.isContainer = function(row)
{
return this._getObjectAtRow(row).isFolder();
}
Scholar.TreeView.prototype.isContainerOpen = function(row)
{
return this._dataObjects[row][1];
} }
Scholar.TreeView.prototype.isContainer = function(row) { return this._getObjectAtRow(row).isFolder(); }
Scholar.TreeView.prototype.isContainerOpen = function(row) { return this._dataObjects[row][1]; }
Scholar.TreeView.prototype.isContainerEmpty = function(row) { return false; } Scholar.TreeView.prototype.isContainerEmpty = function(row) { return false; }
Scholar.TreeView.prototype.getLevel = function(row) { return this._dataObjects[row][2]; }
Scholar.TreeView.prototype.getLevel = function(row)
{
return this._getObjectAtRow(row).getLevel();
}
Scholar.TreeView.prototype.getParentIndex = function(row) Scholar.TreeView.prototype.getParentIndex = function(row)
{ {
thisLevel = this._getObjectAtRow(row).getLevel(); var thisLevel = this.getLevel(row);
if(thisLevel == 0) return -1;
for(var i = row - 1; i >= 0; i--) for(var i = row - 1; i >= 0; i--)
if(this._getObjectAtRow(i).getLevel() < thisLevel) if(this.getLevel(i) < thisLevel)
return i; return i;
return -1;
} }
Scholar.TreeView.prototype.hasNextSibling = function(row, afterIndex) Scholar.TreeView.prototype.hasNextSibling = function(row, afterIndex)
{ {
thisLevel = this._getObjectAtRow(row).getLevel(); var thisLevel = this.getLevel(row);
// for(var i = afterIndex + 1; i < this.rowCount; i++) for(var i = afterIndex + 1; i < this.rowCount; i++)
return (this._getObjectAtRow(afterIndex+1).getLevel() == thisLevel) {
//return false; var nextLevel = this.getLevel(i);
//return true; if(nextLevel == thisLevel) return true;
else if(nextLevel < thisLevel) return false;
}
} }
Scholar.TreeView.prototype.toggleOpenState = function(row) Scholar.TreeView.prototype.toggleOpenState = function(row)
{ {
var count = 0; var count = 0;
var thisLevel = this.getLevel(row);
if(this.isContainerOpen(row)) if(this.isContainerOpen(row))
{ {
var thisLevel = this._getObjectAtRow(row).getLevel(); while((row + 1 < this._dataObjects.length) && (this.getLevel(row + 1) > thisLevel))
while(this._getObjectAtRow(row + 1).getLevel() > thisLevel)
{ {
this._dataObjects.splice(row+1,1); this._dataObjects.splice(row+1,1);
count--; count--;
@ -99,18 +84,19 @@ Scholar.TreeView.prototype.toggleOpenState = function(row)
} }
else else
{ {
var newRows = Scholar.Objects.getTreeRows(this._getObjectAtRow(row).getID()); //Get children of var newRows = Scholar.Objects.getTreeRows(this._getObjectAtRow(row).getID()); //Get children
for(var i = 0; i < newRows.length; i++) for(var i = 0; i < newRows.length; i++)
{ {
count++ count++;
this._dataObjects.splice(row+i+1,0,[ newRows[i], false ]); this._dataObjects.splice(row+i+1,0,[ newRows[i], false, thisLevel+1 ]); //insert new row
} }
} }
this._dataObjects[row][1] = !this._dataObjects[row][1]; this._dataObjects[row][1] = !this._dataObjects[row][1];
this.rowCount = this._dataObjects.length; this.rowCount = this._dataObjects.length;
this._treebox.rowCountChanged(row, count); this._treebox.rowCountChanged(row, count); //tell treebox to repaint these
} }
Scholar.TreeView.prototype.selectionChanged = function() Scholar.TreeView.prototype.selectionChanged = function()
@ -135,6 +121,7 @@ Scholar.TreeView.prototype.selectionChanged = function()
} }
/*
Scholar.TreeView.prototype._insertRow = function(item, beforeRow) Scholar.TreeView.prototype._insertRow = function(item, beforeRow)
{ {
return false; return false;
@ -144,6 +131,7 @@ Scholar.TreeView.prototype._deleteRow = function(row)
{ {
return false; return false;
} }
*/
Scholar.TreeView.prototype._getObjectAtRow = function(row) Scholar.TreeView.prototype._getObjectAtRow = function(row)
{ {
@ -152,10 +140,15 @@ Scholar.TreeView.prototype._getObjectAtRow = function(row)
Scholar.TreeView.prototype.isSorted = function() { return false; } Scholar.TreeView.prototype.isSorted = function() { return false; }
Scholar.TreeView.prototype.isSeparator = function(row) { return false; } Scholar.TreeView.prototype.isSeparator = function(row) { return false; }
Scholar.TreeView.prototype.getRowProperties = function(row, prop) { return null; } Scholar.TreeView.prototype.isEditable = function(row, idx) { return false; }
Scholar.TreeView.prototype.getColumnProperties = function(col, prop) { return null; }
Scholar.TreeView.prototype.getCellProperties = function(row, col, prop) { return null; } Scholar.TreeView.prototype.getRowProperties = function(row, prop) { }
Scholar.TreeView.prototype.getImageSrc = function(row, col) { return null; } Scholar.TreeView.prototype.getColumnProperties = function(col, prop) { }
Scholar.TreeView.prototype.getCellProperties = function(row, col, prop) { }
Scholar.TreeView.prototype.getImageSrc = function(row, col) { }
Scholar.TreeView.prototype.performAction = function(action) { }
Scholar.TreeView.prototype.performActionOnCell = function(action, row, col) { }
Scholar.TreeView.prototype.getProgressMode = function(row, col) { }
function setObjectPaneVisibility(vis) function setObjectPaneVisibility(vis)
{ {
@ -213,7 +206,6 @@ function populateObjectPane(objectRow)
dynamicBox.insertBefore(row, beforeField); dynamicBox.insertBefore(row, beforeField);
} }
} }
function selectionChanged() function selectionChanged()

View file

@ -15,19 +15,17 @@
<tree <tree
id="scholar-sidebar-items" id="scholar-sidebar-items"
seltype="multiple"
onselect="selectionChanged()" onselect="selectionChanged()"
flex="1"
enableColumnDrag="true" enableColumnDrag="true"
datasources="rdf:null" seltype="multiple"
ref="" flex="1">
flags="dont-build-content">
<treecols> <treecols>
<treecol <treecol
id="title_column" id="title_column"
label="&sidebar.items.title_column;" label="&sidebar.items.title_column;"
flex="1"/> flex="1"
primary="true"/>
<splitter class="tree-splitter"/> <splitter class="tree-splitter"/>
<treecol <treecol
id="creator_column" id="creator_column"
@ -36,7 +34,11 @@
</treecols> </treecols>
<treechildren/> <treechildren/>
</tree> </tree>
<label id="status-text" value="(No selection)"/> <label id="status-text" value="(No selection)"/>
<grid id="scholar-sidebar-object-pane" hidden="true"> <grid id="scholar-sidebar-object-pane" hidden="true">
<columns> <columns>
<column/> <column/>