subclass(HierarchyTreeSingleSelect, HierarchyTree);
function HierarchyTreeSingleSelect(id)
{
  HierarchyTree.call(this, id);

  this.selectedNodeKey = null;
  this.highlightSubNodes = false;
  
  this.onSelectItem.addEventListener( new REventListener(HierarchyTreeSingleSelect.prototype.onSelectItemListener, this) );
}

HierarchyTreeSingleSelect.prototype.getSelectedNodeKey = function()
{
  return this.selectedNodeKey;
}

HierarchyTreeSingleSelect.prototype.setSelectedNodeKey = function(key)
{
  this.onSelectItem.trigger(true, key);
}

HierarchyTreeSingleSelect.prototype.getHighlightSubNodes = function()
{
  return this.highlightSubNodes;
}

HierarchyTreeSingleSelect.prototype.setHighlightSubNodes = function(highlightSubNodes)
{
  this.highlightSubNodes = highlightSubNodes;
  if(this.highlightSubNodes)
    this.updateChildNodeClassNames(this.getNode(this.selectedNodeKey),"treeNodeDown");
  else
    this.updateChildNodeClassNames(this.getNode(this.selectedNodeKey),"");
}

HierarchyTreeSingleSelect.prototype.getRootNode = function()
{
  if(0<this.rootNodeList.length)
    return this.rootNodeList[0];
  return null;
}

HierarchyTreeSingleSelect.prototype.updateChildNodeClassNames = function(node, className)
{
  if(node && node.childNodes && 0<node.childNodes.length)
  {
    for (var i=0; i<node.childNodes.length; i++)
    {
      var rowNode = $(RegisterControl.statics.encodeId( this, node.childNodes[i].getId(), "nodeRow" ));
      if(rowNode)
      {
        rowNode.className = className;
        this.updateChildNodeClassNames(node.childNodes[i],className);
      }
    }
  }
}

HierarchyTreeSingleSelect.prototype.onSelectItemListener = function(selected, id)
{
  if (this.readOnlyId == id)
    return;
    
  var element = $(RegisterControl.statics.encodeId( this, id, "nodeRow" ));
  if (element)
  {
    if (selected)
    {
      if (this.selectedNodeKey)
        this.onSelectItem.trigger(false, this.selectedNodeKey);
      this.selectedNodeKey = id;
      element["className"] = "treeNodeSelect";
      if (this.highlightSubNodes)
        this.updateChildNodeClassNames(this.getNode(id),"treeNodeDown");
    }
    else
    {
      element["className"] = "";
      if(this.highlightSubNodes)
        this.updateChildNodeClassNames(this.getNode(id),"");
    }
  }
}

// override base class
HierarchyTreeSingleSelect.prototype.renderNode = function( tr, node )
{
    var td = $C( "td" );
    var nodeText = node.getText()
    if( node.bDisabled )
    {
        nodeText += " (Disabled)";
    }
    td.innerHTML = nodeText;
    td.style.whiteSpace = "nowrap";

    if(node.bReadOnly || node.bDisabled) 
      td.stateDisabled = true;
    else 
      td.stateDisabled = false;
    
    td.id = this.getNodeDomElementId(node);
    td.instanceId = this.getId();
    td.nodeId = node.getId();

    td.onmouseout    = HierarchyTree.statics._mouseOut;
    td.onclick       = HierarchyTree.statics._clickItem;
    td.onmouseover   = HierarchyTree.statics._mouseOver;
    
    this.setMouseOutStyle(td);

    tr.appendChild( td );
}
