Example #1
0
void DatabaseExplorer::OnOpenWithDBE(wxCommandEvent& e) {
	// get the file name
	TreeItemInfo item = m_mgr->GetSelectedTreeItemInfo( TreeFileView );
	if ( item.m_item.IsOk() && item.m_itemType == ProjectItem::TypeFile ) {
		if (item.m_fileName.GetExt() == wxT("erd")) {
			// try to determine used database adapter
			IDbAdapter *adapter = NULL;
			IDbAdapter::TYPE type = IDbAdapter::atUNKNOWN;

			wxSFDiagramManager mgr;
			mgr.AcceptShape( wxT("All") );
			mgr.SetRootItem( new ErdInfo() );

			if( mgr.DeserializeFromXml( item.m_fileName.GetFullPath() ) ) {
				ErdInfo *info = wxDynamicCast( mgr.GetRootItem(), ErdInfo );

				if( info ) type = info->GetAdapterType();

				switch( type ) {
				case IDbAdapter::atSQLITE:
#ifdef DBL_USE_SQLITE
					adapter = new SQLiteDbAdapter();
#endif
					break;

				case IDbAdapter::atMYSQL:
#ifdef DBL_USE_MYSQL
					adapter = new MySqlDbAdapter();
#endif
					break;

				case IDbAdapter::atPOSTGRES:
#ifdef DBL_USE_POSTGRES
					adapter = new PostgreSqlDbAdapter();
#endif
					break;

				default:
					break;
				}

				if( adapter ) {
					ErdPanel *panel = new ErdPanel( m_mgr->GetEditorPaneNotebook(), adapter, NULL );
					m_mgr->AddEditorPage( panel, wxString::Format( wxT("ERD [%s]"), item.m_fileName.GetFullName().c_str() ) );
					panel->LoadERD( item.m_fileName.GetFullPath() );
					return;
				}
			}
		}
	}
	e.Skip();
}
Example #2
0
void DatabaseExplorer::DoOpenFile(const wxFileName& filename)
{
    if(filename.GetExt() == wxT("erd")) {
        // try to determine used database adapter
        IDbAdapter* adapter = NULL;
        IDbAdapter::TYPE type = IDbAdapter::atUNKNOWN;

        wxSFDiagramManager mgr;
        mgr.AcceptShape(wxT("All"));
        mgr.SetRootItem(new ErdInfo());

        if(mgr.DeserializeFromXml(filename.GetFullPath())) {
            ErdInfo* info = wxDynamicCast(mgr.GetRootItem(), ErdInfo);

            if(info) type = info->GetAdapterType();

            switch(type) {
            case IDbAdapter::atSQLITE:
#ifdef DBL_USE_SQLITE
                adapter = new SQLiteDbAdapter();
#endif
                break;

            case IDbAdapter::atMYSQL:
#ifdef DBL_USE_MYSQL
                adapter = new MySqlDbAdapter();
#endif
                break;

            case IDbAdapter::atPOSTGRES:
//#ifdef DBL_USE_POSTGRES
                adapter = new PostgreSqlDbAdapter();
//#endif
                break;

            default:
                break;
            }

            if(adapter) {
                ErdPanel* panel = new ErdPanel(m_mgr->GetEditorPaneNotebook(), adapter, NULL);
                m_mgr->AddEditorPage(panel, wxString::Format(wxT("ERD [%s]"), filename.GetFullName().c_str()));
                panel->LoadERD(filename.GetFullPath());
                return;
            }
        }
    }
}
Example #3
0
bool ErdPanel::LoadERD(const wxString& path)
{
    m_diagramManager.GetRootItem()->RemoveChildren();

    if(m_diagramManager.DeserializeFromXml(path)) {
        ErdInfo* pInfo = wxDynamicCast(m_diagramManager.GetRootItem(), ErdInfo);
        if(pInfo && (pInfo->GetAdapterType() == m_pDbAdapter->GetAdapterType())) {
            m_pFrameCanvas->UpdateERD();
            m_pFrameCanvas->Refresh();

            return true;
        } else {
            m_diagramManager.GetRootItem()->RemoveChildren();
            wxMessageBox(_("ERD type doesn't match current database adapter."), _("DB Error"), wxICON_ERROR | wxOK);

            m_pFrameCanvas->Refresh();

            return false;
        }
    }

    return false;
}