示例#1
0
void frmDatabaseDesigner::setModelChanged(bool value)
{
	previousChanged = changed;
	changed = value;

	// optimization to avoid unneeded operations
	// false changed for false don't trigger it, but false changed to true trigger it.
	if (previousChanged != changed)
	{
		wxMenuItem *itemMenu = fileMenu->FindItem(MNU_SAVEMODEL);

		if (value)
		{
			itemMenu->Enable(true);
			toolBar->EnableTool(MNU_SAVEMODEL, true);
			setExtendedTitle();
		}
		else
		{
			itemMenu->Enable(false);
			toolBar->EnableTool(MNU_SAVEMODEL, false);
			setExtendedTitle();
		}
	}
}
示例#2
0
void frmDatabaseDesigner::OnDeleteTable(wxCommandEvent &event)
{
	if (diagrams->GetPageCount() > 0)
	{
		hdDrawingView *view = (hdDrawingView *) diagrams->GetPage(diagrams->GetSelection());
		view->getDrawing()->deleteSelectedFigures();
		setModelChanged(true);
		setExtendedTitle();
	}
}
示例#3
0
void frmDatabaseDesigner::OnModelSave(wxCommandEvent &event)
{
	if (lastFile != wxEmptyString)
	{
		design->writeXmlModel(lastFile);
		setModelChanged(false);
		setExtendedTitle();
	}
	else
	{
		OnModelSaveAs(event);
	}
}
示例#4
0
void frmDatabaseDesigner::OnAddColumn(wxCommandEvent &event)
{
	if (diagrams->GetPageCount() > 0)
	{
		hdDrawingView *view = (hdDrawingView *) diagrams->GetPage(diagrams->GetSelection());
		ddTableFigure *table = design->getSelectedTable(view->getIdx());
		wxTextEntryDialog nameDialog (this, wxT("New column name"), wxT("Add a column"), wxT("NewColumn"));
		int answer;
		wxString tmpString;

		if (table)
		{
			bool again;
			do
			{
				again = false;
				answer = nameDialog.ShowModal();
				if (answer == wxID_OK)
				{
					tmpString = nameDialog.GetValue();
					if(table->getColByName(tmpString) == NULL)
					{
						table->addColumn(view->getIdx(), new ddColumnFigure(tmpString, table));
						setModelChanged(true);
						setExtendedTitle();
					}
					else
					{
						wxString msg(wxT("Error trying to add new column '"));
						msg.Append(tmpString);
						msg.Append(wxT("' column name already in use"));
						wxMessageDialog info( this, msg ,
						                      wxT("Column name already in use"),
						                      wxNO_DEFAULT | wxOK | wxICON_EXCLAMATION);
						again = true;
						info.ShowModal();
					}

				}
			}
			while(again);
		}
		view->Refresh();
	}
	else
	{
		wxMessageBox(_("Warning about adding a column to a table without a diagram"), _("Please create a model diagram first"), wxICON_EXCLAMATION | wxOK);
	}
}
示例#5
0
void frmDatabaseDesigner::OnChangeConnection(wxCommandEvent &event)
{
	// On Solaris, this event seems to get fired when the form closes(!!)
	if(!IsVisible() && !loading)
		return;

	unsigned int sel = cbConnection->GetSelection();
	if (sel == cbConnection->GetCount() - 1)
	{
		// new Connection
		dlgSelectConnection dlg(this, mainForm);
		int rc = dlg.Go(connection, cbConnection);
		if (rc == wxID_OK)
		{
			bool createdNewConn;
			wxString applicationname = appearanceFactory->GetLongAppName() + _(" - Database Designer");
			pgConn *newconn = dlg.CreateConn(applicationname, createdNewConn);
			if (newconn && createdNewConn)
			{
#if wxCHECK_VERSION(2, 9, 0)
				cbConnection->Insert(newconn->GetName(), CreateBitmap(GetServerColour(newconn)), sel, (wxClientData *)newconn);
#else
				cbConnection->Insert(newconn->GetName(), CreateBitmap(GetServerColour(newconn)), sel, (void *)newconn);
#endif
				cbConnection->SetSelection(sel);
				OnChangeConnection(event);
			}
			else
				rc = wxID_CANCEL;
		}
		if (rc != wxID_OK)
		{
			unsigned int i;
			for (i = 0 ; i < sel ; i++)
			{
				if (cbConnection->GetClientData(i) == connection)
				{
					cbConnection->SetSelection(i);
					break;
				}
			}
		}
	}
	else
	{
		connection = (pgConn *)cbConnection->GetClientData(sel);
		setExtendedTitle();
	}
}
示例#6
0
void frmDatabaseDesigner::OnModelLoad(wxCommandEvent &event)
{
	if(changed)
	{
		// Ask what to do with old model
		int answer = wxMessageBox(_("Save model changes?"), _("Confirm"), wxYES_NO | wxCANCEL);
		if (answer == wxYES)
		{
			if (lastFile != wxEmptyString)
				OnModelSave(event);
			else
				OnModelSaveAs(event);
		}

		if(answer == wxCANCEL)
			return;
	}

	//Open Model
	wxFileDialog openFileDialog(this, _("Open model"), wxT(""), wxT(""), wxT("*.pgd"),
	                            wxFD_OPEN | wxFD_FILE_MUST_EXIST, wxDefaultPosition);

	if (openFileDialog.ShowModal() == wxID_OK)
	{
		wxString path;
		path.append(openFileDialog.GetDirectory());
		path.append(wxFileName::GetPathSeparator());
		path.append(openFileDialog.GetFilename());
		if(!path.Lower().Matches(wxT("*.pgd")))
			path.append(wxT(".pgd"));
		lastFile = path;

		// Clean treeview, notebook, and sql pane
		design->emptyModel();
		while(diagrams->GetPageCount() > 0)
		{
			diagrams->RemovePage(0);
			design->deleteDiagram(0);
		}
		sqltext->SetText(wxEmptyString);

		// Read model from xml file
		design->readXmlModel(path, diagrams);
		setModelChanged(false);
		setExtendedTitle();
	}
}
示例#7
0
void frmDatabaseDesigner::OnClose(wxCloseEvent &event)
{
	closing = true;

	// Ask what to do with old model
	if (changed)
	{
		int answer = wxMessageBox(_("Save model changes?"), _("Confirm"), wxYES_NO | wxCANCEL);

		if (answer == wxYES)
		{
			if (lastFile.IsEmpty())
			{
				wxFileDialog openFileDialog( this, _("Save model"), wxT(""), wxT(""), wxT("*.pgd"),
				                             wxFD_SAVE | wxFD_OVERWRITE_PROMPT, wxDefaultPosition);

				if (openFileDialog.ShowModal() == wxID_OK)
				{
					wxString path;
					path.append(openFileDialog.GetDirectory());
					path.append(wxFileName::GetPathSeparator());
					path.append(openFileDialog.GetFilename());
					if(!path.Lower().Matches(wxT("*.pgd")))
						path.append(wxT(".pgd"));
					lastFile = path;
				}
			}

			if (!lastFile.IsEmpty())
			{
				design->writeXmlModel(lastFile);
				setModelChanged(false);
				setExtendedTitle();
			}
		}
		else if (answer == wxCANCEL)
		{
			event.Veto();
			return;
		}
	}

	Hide();
	Destroy();
}
void frmDatabaseDesigner::OnAddTable(wxCommandEvent &event)
{
	if (diagrams->GetPageCount() > 0)
	{
		hdDrawingView *view = (hdDrawingView *) diagrams->GetPage(diagrams->GetSelection());

		ddTableNameDialog *newTableDialog = new ddTableNameDialog(
		    this,
		    design->getNewTableName(),
		    wxEmptyString,
		    NULL
		);

		bool done = false, existsTable;
		int answer;

		do
		{
			answer = newTableDialog->ShowModal();
			existsTable = design->getTable(newTableDialog->GetValue1()) != NULL;

			if (answer == wxID_OK && !newTableDialog->GetValue1().IsEmpty() && !existsTable)
			{
				ddTableFigure *newTable = new ddTableFigure(newTableDialog->GetValue1(),
				        view->getIdx(),
				        rand() % 90 + 200,
				        rand() % 90 + 140,
				        newTableDialog->GetValue2()
				                                           );
				design->addTableToView(view->getIdx(), newTable);
				design->refreshDraw(view->getIdx());
				setModelChanged(true);
				setExtendedTitle();
				done = true;
			}
			else if(existsTable && answer == wxID_OK)
			{
				wxMessageBox(_("You have to change the table name because there is already a table with that name in this model."), _("Table already existing"), wxICON_EXCLAMATION);
			}
		}
		while (answer != wxID_CANCEL && !done);

		delete newTableDialog;
	}
}
示例#9
0
void frmDatabaseDesigner::OnModelSaveAs(wxCommandEvent &event)
{
	wxFileDialog openFileDialog( this, _("Save model"), wxT(""), wxT(""), wxT("*.pgd"),
	                             wxFD_SAVE | wxFD_OVERWRITE_PROMPT, wxDefaultPosition);

	if (openFileDialog.ShowModal() == wxID_OK)
	{
		wxString path;
		path.append( openFileDialog.GetDirectory() );
		path.append( wxFileName::GetPathSeparator() );
		path.append( openFileDialog.GetFilename() );
		if(!path.Lower().Matches(wxT("*.pgd")))
			path.append(wxT(".pgd"));
		lastFile = path;
		setModelChanged(false);
		setExtendedTitle();
		design->writeXmlModel(path);
	}
}
示例#10
0
void frmDatabaseDesigner::OnNewModel(wxCommandEvent &event)
{
	hdDrawingView *view = (hdDrawingView *) diagrams->GetPage(diagrams->GetSelection());

	if (changed)
	{
		// Ask what to do with old model
		int answer = wxMessageBox(_("Save model changes?"), _("Confirm"), wxYES_NO | wxCANCEL);

		if (answer == wxYES)
		{
			if (!lastFile.IsEmpty())
				OnModelSave(event);
			else
				OnModelSaveAs(event);
		}
		else if (answer == wxCANCEL)
			return;
	}

	// Clean treeview, notebook, and sql pane
	design->emptyModel();
	while (diagrams->GetPageCount() > 0)
	{
		diagrams->RemovePage(0);
		design->deleteDiagram(0);
	}
	sqltext->SetText(wxEmptyString);

	// Add new diagram
	diagrams->AddPage(design->createDiagram(diagrams, _("unnamed"), false)->getView(), _("unnamed"));

	// Misc
	lastFile = wxEmptyString;
	setModelChanged(false);
	setExtendedTitle();
	UpdateToolbar();
}