$package("com.qn.ui");

com.qn.ui.FileIconRenderer = function (owner){
	this.owner = owner;
}

com.qn.ui.FileIconRenderer.prototype = new js.ui.list.IconListItemRenderer();

com.qn.ui.FileIconRenderer.prototype.size = 16;

com.qn.ui.FileIconRenderer.prototype.getNativeClass = function (){
	if(this.style==0)
		return "com.qn.ui.FileIconRenderer_Report";
	else
		return "js.ui.list.IconListItemRenderer";
}

com.qn.ui.FileIconRenderer.prototype.bindEvents = function (){
	var __this = this;
	if(this.style==0){
		this.checkbox = this.ui.getElementsByTagName("input")[0];
		this.sizeSpan = this.ui.getElementsByTagName("span")[0];
		this.lastModified = this.ui.getElementsByTagName("span")[1];
		this.absoluteIP = this.ui.getElementsByTagName("span")[2];
		this.editButton = this.ui.getElementsByTagName("a")[1];
		this.linkButton = this.ui.getElementsByTagName("a")[2];
	}

	this.__superBindEvents = js.ui.list.IconListItemRenderer.prototype.bindEvents;
	this.__superBindEvents();

	var curListBox = this.owner;
	this.text.onclick = function(){
		if(curListBox.onclickItem) curListBox.onclickItem(__this);
	}
/*	this.iconDiv.onclick = function(){
		if(curListBox.onclickItem) curListBox.onclickItem(__this);
	}*/

	
	if(this.style==0){
		this.ui.onclick = null;
		this.ui.onmousedown = null;
		this.checkbox.onclick = function(event){
			curListBox.setSelectedValue(__this.userObject, this.checked);
		}
		this.editButton.onclick = function(event){
			if(curListBox.onedit) curListBox.onedit(__this);
			return js.ui.Component.eventCancelBubble(event);
		}
		if(curListBox.columns.size()<5) {
			this.absoluteIP.style.display = "none";
			this.editButton.style.display = "none";
			this.linkButton.style.display = "none";
		}
	}
	else{
		//this.ui.onclick = null;
	}
}

com.qn.ui.FileIconRenderer.prototype.setValue = function(value){
	this.userObject = value;
	this.getUI().title = value.getFilename();
	this.paint();
}

com.qn.ui.FileIconRenderer.prototype.paintType = function(){
	var typeIcon = this.userObject.getTypeIcon();
	if(typeIcon&&!this.typeIcon){
		this.typeIcon = new js.ui.Img();
		this.typeIcon.getUI().className = "typeIcon";
		this.iconDiv.appendChild(this.typeIcon.getUI());
	}
	if(typeIcon && this.typeIcon){
		this.typeIcon.show();
		this.typeIcon.setSrc(typeIcon);
		this.typeIcon.ui.style.left = this.icon.ui.offsetLeft;
		this.typeIcon.ui.style.top = this.icon.ui.offsetTop;
	}
	else if(this.typeIcon) this.typeIcon.hide();
}

com.qn.ui.FileIconRenderer.prototype.paintText = function(){
	if(this.style==0)
		this.linkButton.href = this.userObject.getLinkUrl();
	if(this.userObject.isDirectory()){
		this.text.href = "#";
	}
	else{
		this.text.href = this.userObject.getDownLink();
		this.text.target = "_blank";
	}

	var text = this.userObject.getDisplayName();
	if(!text) text = "";
	this.text.innerHTML = text;
	this.edit.value = text;
	if(this.viewType>0 && text.length>20)
		this.textDiv.style.height = 30;
	else
		this.textDiv.style.height = "";

	if(this.style==0){
		this.sizeSpan.innerHTML = this.userObject.getSizeDisp();
		this.lastModified.innerHTML = this.userObject.getLastModifiedDisp();
		this.absoluteIP.innerHTML = this.userObject.getAbsoluteIPDisp();
	}
}

com.qn.ui.FileIconRenderer.prototype.paintIcon = function (){
	var icon;
	if(this.size>16)
		icon = this.userObject.getBigIcon();
	else
		icon = this.userObject.getSmallIcon();
	this.setIcon(icon);
	this.paintType();
}
com.qn.ui.FileIconRenderer.prototype.paintSelect = function(selected){
	this.getUI().className = this.getCSS();
	if(this.checkbox){
		if(selected==null) {
			if (this.isSelected()){
				this.checkbox.checked = true;
			}
			else{
				this.checkbox.checked = false;
			}
		}
		else
			this.checkbox.checked = selected;
	}
}
com.qn.ui.FileIconRenderer.prototype.onchange = function (text){
	this.userObject.setFilename(text);
	this.getUI().title = this.userObject.getFilename();
	this.paintText();
}

com.qn.ui.FileIconRenderer.prototype.onopen = function (){
	var __this = this;
	this.owner.openWithExplorer(__this.userObject.getPath());
}

