Esempio n. 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();
}
Esempio n. 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;
            }
        }
    }
}
Esempio n. 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;
}
Esempio n. 4
0
void ErdPanel::Init(wxWindow* parent, IDbAdapter* dbAdapter)
{

    SetExtraStyle(wxWS_EX_BLOCK_EVENTS);

    ErdInfo* pInfo = new ErdInfo();
    pInfo->SetAdapterType(m_pDbAdapter->GetAdapterType());
    m_diagramManager.SetRootItem(pInfo);

    m_pFrameCanvas = new FrameCanvas(&m_diagramManager, dbAdapter, m_wxsfPanel, this, wxID_ANY);
    m_wxsfPanel->GetSizer()->Add(m_pFrameCanvas, 1, wxEXPAND, 2);
    m_wxsfPanel->Layout();

    m_nToolMode = modeDESIGN;

    BitmapLoader* bmpLoader = DatabaseExplorer::GetManager()->GetStdIcons();

    //	m_toolBarErd->SetToolBitmapSize(wxSize(16, 16));
    m_toolBarErd->AddTool(
        XRCID("IDT_OPEN"), _("Open"), bmpLoader->LoadBitmap(wxT("toolbars/16/standard/file_open")), _("Open diagram"));
    m_toolBarErd->AddTool(
        XRCID("IDT_SAVE"), _("Save"), bmpLoader->LoadBitmap(wxT("toolbars/16/standard/file_save")), _("Save diagram"));
    m_toolBarErd->AddTool(XRCID("IDT_ERD_SAVE_SQL"), _("Save SQL"), wxBitmap(export_sql_xpm), _("Save SQL"));
    m_toolBarErd->AddTool(XRCID("IDT_ERD_COMMIT"), _("Commit ERD"), wxBitmap(export_db_xpm), _("Commit ERD"));
    m_toolBarErd->AddTool(
        XRCID("IDT_ERD_SAVE_IMG"), _("Export canvas to image"), wxBitmap(export_img_xpm), _("Export canvas to image"));
    m_toolBarErd->AddSeparator();
    m_toolBarErd->AddTool(XRCID("IDT_PRINT"), _("Print"), wxBitmap(fileprint_xpm), _("Print diagram"));
    m_toolBarErd->AddTool(XRCID("IDT_PREVIEW"), _("Preview"), wxBitmap(filepreview_xpm), _("Print preview"));
    m_toolBarErd->AddSeparator();
    m_toolBarErd->AddTool(
        XRCID("IDT_COPY"), _("Copy"), bmpLoader->LoadBitmap(wxT("toolbars/16/standard/copy")), _("Copy item"));
    m_toolBarErd->AddTool(
        XRCID("IDT_CUT"), _("Cut"), bmpLoader->LoadBitmap(wxT("toolbars/16/standard/cut")), _("Cut item"));
    m_toolBarErd->AddTool(
        XRCID("IDT_PASTE"), _("Paste"), bmpLoader->LoadBitmap(wxT("toolbars/16/standard/paste")), _("Paste item"));
    m_toolBarErd->AddSeparator();
    m_toolBarErd->AddTool(
        XRCID("IDT_UNDO"), _("Undo"), bmpLoader->LoadBitmap(wxT("toolbars/16/standard/undo")), _("Undo"));
    m_toolBarErd->AddTool(
        XRCID("IDT_REDO"), _("Redo"), bmpLoader->LoadBitmap(wxT("toolbars/16/standard/redo")), _("Redo"));
    m_toolBarErd->AddSeparator();
    m_toolBarErd->AddTool(XRCID("IDT_ERD_TOOL"),
                          _("Tool"),
                          wxBitmap(Tool_xpm),
                          wxNullBitmap,
                          wxITEM_RADIO,
                          _("Design tool"),
                          _("Design tool"),
                          NULL);
    m_toolBarErd->AddTool(XRCID("IDT_ERD_TABLE"),
                          _("DBETable"),
                          bmpLoader->LoadBitmap(wxT("db-explorer/16/table")),
                          wxNullBitmap,
                          wxITEM_RADIO,
                          _("Database table"),
                          _("Database table"),
                          NULL);
    m_toolBarErd->AddTool(XRCID("IDT_ERD_VIEW"),
                          _("View"),
                          bmpLoader->LoadBitmap(wxT("toolbars/16/search/find")),
                          wxNullBitmap,
                          wxITEM_RADIO,
                          _("Database view"),
                          _("Database view"),
                          NULL);
    m_toolBarErd->AddTool(XRCID("IDT_ERD_LINE"),
                          _("Constraint 1:N"),
                          wxXmlResource::Get()->LoadBitmap(wxT("link_editor")),
                          wxNullBitmap,
                          wxITEM_RADIO,
                          _("Foreign key connection"),
                          _("Foreign key connection"),
                          NULL);
    m_toolBarErd->AddSeparator();
    m_toolBarErd->AddTool(
        XRCID("IDT_ERD_ALIGN_CIRCLE"), _("Align into circle"), wxBitmap(AlignCircle_xpm), _("Align into circle"));
    m_toolBarErd->AddTool(
        XRCID("IDT_ERD_ALIGN_MESH"), _("Align into mesh"), wxBitmap(AlignMesh_xpm), _("Align into mesh"));
    m_toolBarErd->AddTool(XRCID("IDT_ERD_ALIGN_VTREE"),
                          _("Align into vertical tree"),
                          wxBitmap(AlignVTree_xpm),
                          _("Align into vertical tree"));
    m_toolBarErd->AddTool(XRCID("IDT_ERD_ALIGN_HTREE"),
                          _("Align into horizontal tree"),
                          wxBitmap(AlignHTree_xpm),
                          _("Align into horizontal tree"));
    m_toolBarErd->AddSeparator();
    m_toolBarErd->AddTool(XRCID("IDT_ERD_ZOOM100"), _("Zoom 100%"), wxBitmap(Zoom100_xpm), _("Zoom 100%"));
    m_toolBarErd->AddTool(XRCID("IDT_ERD_ZOOMALL"), _("Zoom to all"), wxBitmap(ZoomAll_xpm), _("Zoom to all"));
    m_toolBarErd->Realize();

    wxAcceleratorEntry entries[4];
    entries[0].Set(wxACCEL_CTRL, (int)'C', XRCID("IDT_COPY"));
    entries[1].Set(wxACCEL_CTRL, (int)'X', XRCID("IDT_CUT"));
    entries[2].Set(wxACCEL_CTRL, (int)'V', XRCID("IDT_PASTE"));
    entries[3].Set(wxACCEL_CTRL, (int)'A', XRCID("IDT_SELECTALL"));
    wxAcceleratorTable accel(4, entries);
    SetAcceleratorTable(accel);
}