void UIFileTree::OnDirectoryChange(BaseObject * obj, void * userData, void * callerData)
{
	UIFileTreeCell * cell = dynamic_cast<UIFileTreeCell*> (obj);
	UIEvent * event = reinterpret_cast<UIEvent*> (callerData);	
	if (cell && event)
	{
		Logger::Debug("Click count: %d", event->tapCount);
		if (event->tapCount == 2)
		{
			UITreeItemInfo * info = cell->GetItemInfo();
			String pathname = info->GetPathname();
			Logger::Debug("Switch to path: %s", pathname.c_str());
			SetPath(FileSystem::RealPath(pathname), originalExtensionsString);
			treeHead->ToggleExpanded();
		}
	}
}
UIListCell *UIFileTree::CellAtIndex(UIList *forList, int32 index)
{
	UIFileTreeCell *c = (UIFileTreeCell *)forList->GetReusableCell("FileTreeCell"); //try to get cell from the reusable cells store
	if(!c)
	{ //if cell of requested type isn't find in the store create new cell
		c = new UIFileTreeCell(Rect(0, 0, 200, 20), "FileTreeCell");
	}
	//fill cell whith data
	//c->serverName = GameServer::Instance()->totalServers[index].name + LocalizedString("'s game");

	UITreeItemInfo * entry = treeHead->EntryByIndex(index);

//	String empty;
//	for (int k = 0; k < entry->GetLevel(); ++k)
//	{
//		empty += ' ';
//		empty += ' ';
//	}
	float32 shiftX = entry->GetLevel() * 10.0f;
	c->SetRect(Rect(shiftX, 0, 200 - shiftX, 16));
	c->SetStateText(UIControl::STATE_NORMAL, StringToWString(entry->GetName()));
	c->GetStateTextControl(UIControl::STATE_NORMAL)->SetAlign(ALIGN_LEFT | ALIGN_VCENTER);
	c->SetItemInfo(entry);
	
	/*
		WTF ??? I can't call RemoveAllEvents here.
	 */
	c->RemoveEvent(UIControl::EVENT_TOUCH_DOWN, Message(this, &UIFileTree::OnDirectoryChange));
	
	if (entry->IsDirectory())
		c->AddEvent(UIControl::EVENT_TOUCH_DOWN, Message(this, &UIFileTree::OnDirectoryChange));
	
	//c->connection = GameServer::Instance()->totalServers[index].connection;
	//c->serverIndex = GameServer::Instance()->totalServers[index].index;

	return c;//returns cell
	//your application don't need to manage cells. UIList do all cells management.
	//you can create cells of your own types derived from the UIListCell
}
UIFileTreeCell *ResourcePackerScreen::CellAtIndex(UIFileTree * tree, UITreeItemInfo *entry, int32 index)
{
    int32 width = (int32)tree->GetRect().dx;
    
	UIFileTreeCell *c = (UIFileTreeCell *)tree->GetReusableCell("FileTreeCell"); //try to get cell from the reusable cells store
	if(!c)
	{ //if cell of requested type isn't find in the store create new cell
		c = new UIFileTreeCell(Rect(0, 0, (float32)width, 20.f), "FileTreeCell");
	}
	//fill cell whith data
	//c->serverName = GameServer::Instance()->totalServers[index].name + LocalizedString("'s game");

	c->SetStateText(UIControl::STATE_NORMAL, StringToWString(entry->GetName()));
    c->GetStateTextControl(UIControl::STATE_NORMAL)->SetAlign(ALIGN_LEFT | ALIGN_VCENTER);
    c->SetStateText(UIControl::STATE_SELECTED, StringToWString(entry->GetName()));
	c->GetStateTextControl(UIControl::STATE_SELECTED)->SetAlign(ALIGN_LEFT | ALIGN_VCENTER);

    c->SetSelected(false, false);
	
	return c;//returns cell
}