1
//////////////////////////////////////////////////////////////////////////
3
// pgAdmin III - PostgreSQL Tools
4
// RCS-ID: $Id: dlgTextSearchDictionary.cpp 7758 2009-03-26 20:49:59Z dpage $
5
// Copyright (C) 2002 - 2009, The pgAdmin Development Team
6
// This software is released under the BSD Licence
8
// dlgTextSearchDictionary.cpp - PostgreSQL Text Search Dictionary Property
10
//////////////////////////////////////////////////////////////////////////
17
#include "utils/misc.h"
18
#include "utils/pgDefs.h"
20
#include "dlg/dlgTextSearchDictionary.h"
21
#include "schema/pgSchema.h"
22
#include "schema/pgTextSearchDictionary.h"
23
#include "schema/pgDatatype.h"
26
// pointer to controls
27
#define cbTemplate CTRL_COMBOBOX2("cbTemplate")
28
#define lstOptions CTRL_LISTVIEW("lstOptions")
29
#define txtOption CTRL_TEXT("txtOption")
30
#define txtValue CTRL_TEXT("txtValue")
31
#define btnAdd CTRL_BUTTON("wxID_ADD")
32
#define btnRemove CTRL_BUTTON("wxID_REMOVE")
35
BEGIN_EVENT_TABLE(dlgTextSearchDictionary, dlgTypeProperty)
36
EVT_TEXT(XRCID("cbTemplate"), dlgTextSearchDictionary::OnChange)
37
EVT_COMBOBOX(XRCID("cbTemplate"), dlgTextSearchDictionary::OnChange)
38
EVT_LIST_ITEM_SELECTED(XRCID("lstOptions"), dlgTextSearchDictionary::OnSelChangeOption)
39
EVT_TEXT(XRCID("txtOption"), dlgTextSearchDictionary::OnChangeOptionName)
40
EVT_BUTTON(wxID_ADD, dlgTextSearchDictionary::OnAddOption)
41
EVT_BUTTON(wxID_REMOVE, dlgTextSearchDictionary::OnRemoveOption)
43
EVT_SIZE( dlgTextSearchDictionary::OnChangeSize)
49
dlgProperty *pgTextSearchDictionaryFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
51
return new dlgTextSearchDictionary(this, frame, (pgTextSearchDictionary*)node, (pgSchema*)parent);
54
dlgTextSearchDictionary::dlgTextSearchDictionary(pgaFactory *f, frmMain *frame, pgTextSearchDictionary *node, pgSchema *sch)
55
: dlgTypeProperty(f, frame, wxT("dlgTextSearchDictionary"))
62
pgObject *dlgTextSearchDictionary::GetObject()
68
int dlgTextSearchDictionary::Go(bool modal)
73
qry = wxT("SELECT tmplname, nspname\n")
74
wxT(" FROM pg_ts_template\n")
75
wxT(" JOIN pg_namespace n ON n.oid=tmplnamespace\n")
76
wxT(" ORDER BY tmplname\n");
78
set = connection->ExecuteSet(qry);
83
wxString procname = database->GetSchemaPrefix(set->GetVal(wxT("nspname"))) + set->GetVal(wxT("tmplname"));
84
cbTemplate->Append(procname);
90
lstOptions->AddColumn(_("Option"), 80);
91
lstOptions->AddColumn(_("Value"), 40);
96
cbTemplate->SetValue(dict->GetTemplate());
97
cbTemplate->Disable();
99
wxString options = dict->GetOptions();
100
wxString option, optionname, optionvalue;
101
while (options.Length() > 0)
103
option = options.BeforeFirst(',');
104
optionname = option.BeforeFirst(wxT('=')).Trim(false).Trim();
105
optionvalue = option.AfterFirst(wxT('=')).Trim(false).Trim();
106
lstOptions->AppendItem(optionname, optionvalue);
107
options = options.AfterFirst(',');
110
if (!connection->BackendMinimumVersion(8, 0))
118
txtOption->SetValue(wxT(""));
119
txtValue->SetValue(wxT(""));
121
btnRemove->Disable();
123
return dlgProperty::Go(modal);
127
pgObject *dlgTextSearchDictionary::CreateObject(pgCollection *collection)
129
pgObject *obj=textSearchDictionaryFactory.CreateObjects(collection, 0,
130
wxT("\n AND dict.dictname=") + qtDbString(GetName()) +
131
wxT("\n AND dict.dictnamespace=") + schema->GetOidStr());
138
void dlgTextSearchDictionary::OnChangeSize(wxSizeEvent &ev)
140
lstOptions->SetSize(wxDefaultCoord, wxDefaultCoord,
141
ev.GetSize().GetWidth(), ev.GetSize().GetHeight() - 350);
150
void dlgTextSearchDictionary::CheckChange()
154
EnableOK(txtName->GetValue() != dict->GetName()
155
|| txtComment->GetValue() != dict->GetComment()
156
|| cbOwner->GetValue() != dict->GetOwner()
157
|| GetOptionsSql().Length() > 0);
161
wxString name=GetName();
163
CheckValid(enable, !name.IsEmpty(), _("Please specify name."));
164
CheckValid(enable, cbTemplate->GetValue().Length() > 0 , _("Please select a template."));
171
void dlgTextSearchDictionary::OnChange(wxCommandEvent &ev)
177
void dlgTextSearchDictionary::OnChangeOptionName(wxCommandEvent &ev)
179
btnAdd->Enable(txtOption->GetValue().Length() > 0);
183
void dlgTextSearchDictionary::OnSelChangeOption(wxListEvent &ev)
185
int row=lstOptions->GetSelection();
188
txtOption->SetValue(lstOptions->GetText(row, 0));
189
txtValue->SetValue(lstOptions->GetText(row, 1));
192
btnRemove->Enable(row >= 0);
196
void dlgTextSearchDictionary::OnAddOption(wxCommandEvent &ev)
200
for (int pos = 0 ; pos < lstOptions->GetItemCount() ; pos++)
202
if (lstOptions->GetText(pos).IsSameAs(txtOption->GetValue(), false))
204
lstOptions->SetItem(pos, 1, txtValue->GetValue());
212
lstOptions->AppendItem(txtOption->GetValue(), txtValue->GetValue());
215
txtOption->SetValue(wxT(""));
216
txtValue->SetValue(wxT(""));
223
void dlgTextSearchDictionary::OnRemoveOption(wxCommandEvent &ev)
225
int sel=lstOptions->GetSelection();
226
lstOptions->DeleteItem(sel);
228
txtOption->SetValue(wxT(""));
229
txtValue->SetValue(wxT(""));
230
btnRemove->Disable();
236
wxString dlgTextSearchDictionary::GetOptionsSql()
238
wxString options = dict->GetOptions();
239
wxString option, optionname, optionvalue, sqloptions;
243
while (options.Length() > 0)
245
option = options.BeforeFirst(',');
246
optionname = option.BeforeFirst(wxT('=')).Trim(false).Trim();
247
optionvalue = option.AfterFirst(wxT('=')).Trim(false).Trim();
251
for (pos=0 ; pos < lstOptions->GetItemCount() && !found; pos++)
253
found = lstOptions->GetText(pos, 0).Cmp(optionname) == 0;
259
if (lstOptions->GetText(pos, 1).Cmp(optionvalue) != 0)
261
if (sqloptions.Length() > 0)
262
sqloptions += wxT(", ");
263
sqloptions += optionname + wxT("=") + lstOptions->GetText(pos, 1);
268
if (sqloptions.Length() > 0)
269
sqloptions += wxT(", ");
270
sqloptions += optionname;
273
options = options.AfterFirst(',');
276
for (pos=0 ; pos < lstOptions->GetItemCount() ; pos++)
278
options = dict->GetOptions();
281
while (options.Length() > 0 && !found)
283
option = options.BeforeFirst(',');
284
optionname = option.BeforeFirst(wxT('=')).Trim(false).Trim();
285
found = lstOptions->GetText(pos, 0).Cmp(optionname) == 0;
286
options = options.AfterFirst(',');
291
optionvalue = option.AfterFirst(wxT('=')).Trim(false).Trim();
293
if (sqloptions.Length() > 0)
294
sqloptions += wxT(", ");
295
sqloptions += lstOptions->GetText(pos, 0) + wxT("=") + lstOptions->GetText(pos, 1);
303
wxString dlgTextSearchDictionary::GetSql()
306
wxString objname=schema->GetQuotedPrefix() + qtIdent(GetName());
311
AppendNameChange(sql);
312
AppendOwnerChange(sql, wxT("TEXT SEARCH DICTIONARY ") + objname);
314
wxString sqloptions = GetOptionsSql();
315
if (sqloptions.Length() > 0)
317
sql += wxT("ALTER TEXT SEARCH DICTIONARY ") + objname
318
+ wxT(" (") + sqloptions + wxT(")");
324
sql = wxT("CREATE TEXT SEARCH DICTIONARY ")
325
+ schema->GetQuotedPrefix() + GetName()
327
+ wxT("\n TEMPLATE = ") + cbTemplate->GetValue();
330
for (int pos=0 ; pos < lstOptions->GetItemCount() ; pos++)
332
sql += wxT(", ") + lstOptions->GetText(pos, 0)
333
+ wxT("=") + lstOptions->GetText(pos, 1);
336
sql += wxT("\n);\n");
339
AppendComment(sql, wxT("TEXT SEARCH DICTIONARY ") + objname, dict);