wxGxObject* wxGxPrjFactory::GetGxObject(wxGxObject* pParent, const wxString &soName, const CPLString &szPath, wxGISEnumPrjFileType nType, bool bCheckNames)
{
    if(bCheckNames && IsNameExist(pParent, soName))
    {
        return NULL;
    }

    wxGxPrjFile* pFile = new wxGxPrjFile(nType, pParent, soName, szPath);
	return wxStaticCast(pFile, wxGxObject);
}
wxGxObject* wxGxRasterFactory::GetGxObject(wxGxObject* pParent, const wxString &soName, const CPLString &szPath, wxGISEnumRasterDatasetType type, bool bCheckNames)
{
    if(bCheckNames && IsNameExist(pParent, soName))
    {
        return NULL;
    }

    wxGxRasterDataset* pDataset = new wxGxRasterDataset(type, pParent, soName, szPath);
    return wxStaticCast(pDataset, wxGxObject);
}
wxGxObject* wxGxFolderFactoryUI::GetGxObject(wxGxObject* pParent, const wxString &soName, const CPLString &szPath, bool bCheckNames)
{
    if(bCheckNames && IsNameExist(pParent, soName))
    {
        return NULL;
    }

    wxGxFolder* pFolder = new wxGxFolderUI(pParent, soName, szPath, m_oLargeFolderIcon, m_oSmallFolderIcon);
	return static_cast<wxGxObject*>(pFolder);
}
String HierarchyTreeScreenNode::GetNewControlName(const String& baseName) const
{
	int i = 0;
	while (true)
	{
		QString newName = QString().fromStdString(baseName) + QString::number(++i);
		
		if (!IsNameExist(newName, this))
			return newName.toStdString();
	}
}
wxGxObject* wxGxDBConnectionFactory::GetGxObject(wxGxObject* pParent, const wxString &soName, const CPLString &szPath, bool bCheckNames)
{
    if (bCheckNames && IsNameExist(pParent, soName))
    {
        return NULL;
    }

    //TODO: other DB like MySQL my have different ifdefs
#ifdef wxGIS_USE_POSTGRES
	wxGxRemoteConnection* pDataset = new wxGxRemoteConnection(pParent, soName, szPath);
	return static_cast<wxGxObject*>(pDataset);
#else
    return NULL;
#endif //wxGIS_USE_POSTGRES
}
wxGxObject* wxGxLocalDBFactoryUI::GetGxObject(wxGxObject* pParent, const wxString &soName, const CPLString &szPath, wxGISEnumContainerType eType, bool bCheckNames)
{
    if (eType == enumContGDBFolder && !m_bHasOFGDBDriver)
        return NULL;

    if (bCheckNames && IsNameExist(pParent, soName))
    {
        return NULL;
    }

    if (eType == enumContGDBFolder)
    {
        wxGxOpenFileGDBUI* pDB = new wxGxOpenFileGDBUI(pParent, soName, szPath, m_oLargeFolderIcon, m_oSmallFolderIcon);
        return static_cast<wxGxObject*>(pDB);
    }

    return NULL;
}
bool HierarchyTreeScreenNode::IsNameExist(const QString &name, const HierarchyTreeNode *parent) const
{
	if (!parent)
		return false;
	
	const HIERARCHYTREENODESLIST& items = parent->GetChildNodes();
	for (HIERARCHYTREENODESLIST::const_iterator iter = items.begin();
		 iter != items.end();
		 ++iter)
	{
		HierarchyTreeNode* node = (*iter);
		if (node->GetName().compare(name) == 0)
			return true;

		if (IsNameExist(name, node))
			return true;
	}
	
	return false;
}
wxGxObject* wxGxMapInfoFactoryUI::GetGxObject(wxGxObject* pParent, const wxString &soName, const CPLString &szPath, wxGISEnumVectorDatasetType type, bool bCheckNames)
{
    if(!m_bHasDriver)
        return NULL;

    if(bCheckNames && IsNameExist(pParent, soName))
    {
        return NULL;
    }

    switch(type)
    {
    case enumVecMapinfoTab:
        {
            CPLString sTestPath;
            wxGxObject *pCompoundObjectPart = NULL;
            wxGxObjectContainer* pParentCont = wxDynamicCast(pParent, wxGxObjectContainer);

            for (int j = 0; mi_filter_exts[j] != NULL; ++j)
            {
                sTestPath = (char*)CPLResetExtension(szPath, mi_filter_exts[j]);

                wxGxObjectList::const_iterator iter;
                for (iter = pParentCont->GetChildren().begin(); iter != pParentCont->GetChildren().end(); ++iter)
                {
                    wxGxObject *current = *iter;
                    if (wxGISEQUAL(current->GetPath(), sTestPath))
                    {
                        current->Destroy();
                        break;
                    }
                }
            }

            if(!m_SmallTabIcon.IsOk())
                m_SmallTabIcon = wxIcon(mi_dset_16_xpm);
            if(!m_LargeTabIcon.IsOk())
                m_LargeTabIcon = wxIcon(mi_dset_48_xpm);

            return wxStaticCast(new wxGxFeatureDatasetUI(type, pParent, soName, szPath, m_LargeTabIcon, m_SmallTabIcon), wxGxObject);
        }
    case enumVecMapinfoMif:
        if(!m_SmallMifIcon.IsOk())
            m_SmallMifIcon = wxIcon(md_dset_16_xpm);
        if(!m_LargeMifIcon.IsOk())
            m_LargeMifIcon = wxIcon(md_dset_48_xpm);
        return wxStaticCast(new wxGxFeatureDatasetUI(type, pParent, soName, szPath, m_LargeMifIcon, m_SmallMifIcon), wxGxObject);
    case enumVecMAX + 1:
        if(!m_SmallTabTIcon.IsOk())
            m_SmallTabTIcon = wxIcon(table_tab_16_xpm);
        if(!m_LargeTabTIcon.IsOk())
            m_LargeTabTIcon = wxIcon(table_tab_48_xpm);
        return wxStaticCast(new wxGxTableDatasetUI(enumTableMapinfoTab, pParent, soName, szPath, m_LargeTabTIcon, m_SmallTabTIcon), wxGxObject);
    case enumVecMAX + 2:
        if(!m_SmallTabTIcon.IsOk())
            m_SmallTabTIcon = wxIcon(table_tab_16_xpm);
        if(!m_LargeTabTIcon.IsOk())
            m_LargeTabTIcon = wxIcon(table_tab_48_xpm);
        return wxStaticCast(new wxGxTableDatasetUI(enumTableMapinfoMif, pParent, soName, szPath, m_LargeTabTIcon, m_SmallTabTIcon), wxGxObject);
    default:
        return NULL;
    }
}