/////////////////////////////////////////////////////////////////////////////
// Name:        dbsgeneric.cpp
// Purpose:     Database Server - Generic
// Author:      Daniel Horak
// Modified by:
// RCS-ID:      $Id: dbsgeneric.cc,v 1.4 2004/01/04 18:32:16 horakdan Exp $
// Copyright:   (c) Daniel Horak
// Licence:     GPL
/////////////////////////////////////////////////////////////////////////////

// ============================================================================
// declarations
// ============================================================================

// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------

// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWindows headers
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif

#include "config.h"
#include "xml.h"
#include "view.h"
#include "dbserver.h"
#include "dbsgeneric.h"

class DBServerGenericSelectDialog: public wxDialog
{
public:
	DBServerGenericSelectDialog(int cnt, const wxString servers[]);
	~DBServerGenericSelectDialog();
	
	wxChoice	*c1;

private:
	DECLARE_EVENT_TABLE();
};

wxString DBServerGeneric::m_types[] = {
    "bool",
    "char",
    "date",
    "int2",
    "int4",
    "int8",
    "int",
    "numeric",
    "real",
    "text",
    "time",
    "timestamp",
    "varchar"
};

wxString DBServerGeneric::m_servers[] = {
    "PostgreSQL"
};

DBServerGenericStyle DBServerGeneric::m_styles[] = {
    { "gen2pgsql.xsl" }
};

int DBServerGeneric::m_typescount = sizeof(DBServerGeneric::m_types) / sizeof(wxString);
int DBServerGeneric::m_serverscount = sizeof(DBServerGeneric::m_servers) / sizeof(wxString);

DBServerGeneric::DBServerGeneric()
	: DBServer(DBServerTypeGeneric, "Generic")
{
#ifdef HAVE_XSLT_SUPPORT
	int i;
	
	for (i = 0; i < m_serverscount; i++)
		m_styles[i].m_stylesheet = ParseStyle(m_styles[i].m_xslt);
#endif
}

DBServerGeneric::~DBServerGeneric()
{
}

bool DBServerGeneric::ExportDDL(DataDesignerView *view)
{
	wxLogMessage("DBServerGeneric::ExportDDL");
#ifdef HAVE_XSLT_SUPPORT
	int idx = SelectServer();
	
	if (idx == -1)
		return TRUE;

	wxLogMessage("xslt=%s style=%p", m_styles[idx].m_xslt.c_str(), m_styles[idx].m_stylesheet);
	Transform(view, m_styles[idx].m_stylesheet);
#else
	wxMessageBox(_("Function is not supported in this build."), _("Information"), wxOK | wxICON_INFORMATION);
#endif
	return TRUE;
}

int DBServerGeneric::SelectServer()
{
	DBServerGenericSelectDialog	*d = new DBServerGenericSelectDialog(m_serverscount, m_servers);
	int res = -1;
	
	if (d->ShowModal() == wxID_OK) {
		res = d->c1->GetSelection();
	}
	d->Destroy();
	
	return res;
}

BEGIN_EVENT_TABLE(DBServerGenericSelectDialog, wxDialog)
END_EVENT_TABLE()

DBServerGenericSelectDialog::DBServerGenericSelectDialog(int cnt, const wxString servers[])
	: wxDialog(NULL, -1, _("Select server"))
{
	wxBoxSizer	*s_top = new wxBoxSizer(wxVERTICAL);

	wxBoxSizer	*s_data = new wxBoxSizer(wxHORIZONTAL);
	s_top->Add(s_data);
	
	s_data->Add(new wxStaticText(this, -1, _("Server:")), 0, wxALL, 10);
	c1 = new wxChoice(this, -1, wxDefaultPosition, wxDefaultSize, cnt, servers);
	s_data->Add(c1, 1, wxEXPAND | wxALL, 10);

	s_top->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxALL, 10);
	
	SetSizer(s_top);
	s_top->SetSizeHints(this);
}

DBServerGenericSelectDialog::~DBServerGenericSelectDialog()
{
}


syntax highlighted by Code2HTML, v. 0.9.1