$package("js.ui.tree");

js.ui.tree.AbstractTree = function (){
	this.selections = new js.lang.Array();
}

js.ui.tree.AbstractTree.prototype = new js.ui.Container();

js.ui.tree.AbstractTree.prototype.getNativeClass = function (){
	return "js.ui.tree.AbstractTree";
}

js.ui.tree.AbstractTree.prototype.renderClass = js.ui.tree.AbstractTreeCellRenderer;

js.ui.tree.AbstractTree.prototype.treeModel = new js.ui.tree.AbstractTreeModel();

js.ui.tree.AbstractTree.prototype.setRoot = function(value){
	this.getModel().setRoot(value);
	var rootui = this.getRoot().getRenderer().getUI();
	if(rootui.parentNode!=this.getUI()){
		this.getUI().appendChild(rootui);
		this.getRoot().getRenderer().paint();
	}
}
js.ui.tree.AbstractTree.prototype.getRoot = function(){
	if (this.treeModel) {
		return this.treeModel.getRoot();
	} else return null;
}
js.ui.tree.AbstractTree.prototype.clearSelections = function(){
	this.selections.Clear();
}
js.ui.tree.AbstractTree.prototype.getSelections = function(){
	return this.selections;
}
js.ui.tree.AbstractTree.prototype.getSelectionsCount = function(){
	return this.selections.length;
};
js.ui.tree.AbstractTree.prototype.setModel =	function(newModel){ 
	this.treeModel = newModel; 
}
js.ui.tree.AbstractTree.prototype.setAutoExpand = function(value){ 
	this.autoExpand = value; 
};

js.ui.tree.AbstractTree.prototype.setEditable = function(value){ 
	this.editable = value; 
}

js.ui.tree.AbstractTree.prototype.setRootVisible = function(value){ 
	this.rootVisible = value; 
	if (!this.rootVisible){
		var	root = this.treeModel.getRoot(); 
		root.row0TreeNode.style.display = "none";
		this.expand(root);
	}
} 
js.ui.tree.AbstractTree.prototype.setSelected = function(treeNode){
	if (!treeNode) return;
	if (this.oldSelected == treeNode) return;
	this.selected =	treeNode;
	this.selected.focused =	true;
	if (this.oldSelected){		
		this.oldSelected.focused = false;
		this.oldSelected.getRenderer().paintSelect();
	}
	this.selected.getRenderer().paintSelect();
	if(this.onchange) this.onchange(this.selected);
	this.oldSelected = this.selected;
}
js.ui.tree.AbstractTree.prototype.isSelected = function(treeNode){
	return this.selected==treeNode;
}
js.ui.tree.AbstractTree.prototype.getAutoExpand = function(){ 
	return this.autoExpand; 
};
js.ui.tree.AbstractTree.prototype.getModel = function(){ 
	return this.treeModel; 
} 

js.ui.tree.AbstractTree.prototype.isEditable = function(){
	return this.editable;
}
js.ui.tree.AbstractTree.prototype.isRootVisible = function(){ 
	return this.rootVisible; 
} 
js.ui.tree.AbstractTree.prototype.isExpanded = function(treeNode){
	return treeNode.isExpanded();
} 
js.ui.tree.AbstractTree.prototype.isCollapsed = function(treeNode){
	return treeNode.isCollapsed();
}
js.ui.tree.AbstractTree.prototype.isVisible = function(treeNode) {}
js.ui.tree.AbstractTree.prototype.isEditing = function(){}
js.ui.tree.AbstractTree.prototype.stopEditing = function(){}
js.ui.tree.AbstractTree.prototype.cancelEditing = function(){}
js.ui.tree.AbstractTree.prototype.expand = function(treeNode){ 
	treeNode.expand(); 
}
js.ui.tree.AbstractTree.prototype.collapse = function(treeNode){ 
	treeNode.collapse(); 
}
js.ui.tree.AbstractTree.prototype.fullExpand = function(){ 
	if (!this.selected) return; 
	else this.selected.expandAll(); 
}
js.ui.tree.AbstractTree.prototype.fullCollapse = function (){ 
	if (!this.selected) return; 
	else this.selected.collapseAll(); 
} 
js.ui.tree.AbstractTree.prototype.removeChild = function(treeNode){
	var parentTreeNode = treeNode.getParent();
	parentTreeNode.remove(treeNode);
}
js.ui.tree.AbstractTree.prototype.addChild = function(aParentNode, aChildNode){
	aParentNode.add(aChildNode);
}
js.ui.tree.AbstractTree.prototype.paintChild = function(parent) {
	for	(var i = 0;	i <	parent.getChildCount();	i++) {
		var	child =	parent.getChildAt(i);
		child.rreeView = parent.treeview;
		var	childRenderer = child.getRenderer();
		childRenderer.paint(child);
		if (child.getChildCount() >	0) this.paintChild(child);
	}
}
js.ui.tree.AbstractTree.prototype.paint = function(){
/*	var	root = this.treeModel.getRoot(); 
	root.treeview = this;
	if(root.parentNode!=this)
		this.appendChild(root);
	var rootRenderer = root.getRenderer();
	rootRenderer.paint();
	this.paintChild(root);*/
} 
js.ui.tree.AbstractTree.prototype.onaddition = function( node){}
js.ui.tree.AbstractTree.prototype.onchange =	function( node){}
js.ui.tree.AbstractTree.prototype.onchanging = function( node){}
js.ui.tree.AbstractTree.prototype.onclick = function(){}
js.ui.tree.AbstractTree.prototype.oncollapsed= function( node){}
js.ui.tree.AbstractTree.prototype.oncollapsing = function( node){}
js.ui.tree.AbstractTree.prototype.ondblClick = function(){}
js.ui.tree.AbstractTree.prototype.ondeletion	= function( node){}
js.ui.tree.AbstractTree.prototype.onenter = function(){}
js.ui.tree.AbstractTree.prototype.onexit = function(){}
js.ui.tree.AbstractTree.prototype.onexpanded = function( node){} 
js.ui.tree.AbstractTree.prototype.onexpanding = function( node, allowExpansion){}
js.ui.tree.AbstractTree.prototype.onkeydown = function( key, shift){}
js.ui.tree.AbstractTree.prototype.onkeypress = function( key){} 
js.ui.tree.AbstractTree.prototype.onkeyup  = function( key, shift){}
js.ui.tree.AbstractTree.prototype.onstopEditing = function(node){}

