NCBI C++ ToolKit
assign_column_value_dlg.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: assign_column_value_dlg.cpp 39666 2017-10-25 16:01:13Z katargir $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Roman Katargin
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 
32 ////@begin includes
33 ////@end includes
34 
39 
40 #include <wx/sizer.h>
41 #include <wx/stattext.h>
42 #include <wx/combobox.h>
43 #include <wx/button.h>
44 #include <wx/radiobox.h>
45 
46 
47 ////@begin XPM images
48 ////@end XPM images
49 
51 
52 /*!
53  * CAssignColumnValueDlg type definition
54  */
55 
56 IMPLEMENT_DYNAMIC_CLASS( CAssignColumnValueDlg, CDialog )
57 
58 
59 /*!
60  * CAssignColumnValueDlg event table definition
61  */
62 
63 BEGIN_EVENT_TABLE( CAssignColumnValueDlg, CDialog )
64 
65 ////@begin CAssignColumnValueDlg event table entries
67 
68 ////@end CAssignColumnValueDlg event table entries
69 
71 
72 
73 /*!
74  * CAssignColumnValueDlg constructors
75  */
76 
78 : m_Table()
79 {
80  Init();
81 }
82 
84 : m_Table(&table)
85 {
86  Init();
87  Create(parent,
93 }
94 
95 
96 /*!
97  * CAssignColumnValueDlg creator
98  */
99 
100 bool CAssignColumnValueDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
101 {
102 ////@begin CAssignColumnValueDlg creation
103  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
104  CDialog::Create( parent, id, caption, pos, size, style );
105 
106  CreateControls();
107  if (GetSizer())
108  {
109  GetSizer()->SetSizeHints(this);
110  }
111  Centre();
112 ////@end CAssignColumnValueDlg creation
113  return true;
114 }
115 
116 
117 /*!
118  * CAssignColumnValueDlg destructor
119  */
120 
122 {
123 ////@begin CAssignColumnValueDlg destruction
124 ////@end CAssignColumnValueDlg destruction
125 }
126 
127 
128 /*!
129  * Member initialisation
130  */
131 
133 {
134  if (m_Table) {
135  m_RegPath = "Dialogs.CAssignColumnValueDlg." + m_Table->GetTableTypeId();
136  }
137 
138 ////@begin CAssignColumnValueDlg member initialisation
139  m_Column = -1;
140  m_Op = 0;
141  m_Columns = NULL;
142  m_Values = NULL;
143 ////@end CAssignColumnValueDlg member initialisation
144 }
145 
146 
147 /*!
148  * Control creation for CAssignColumnValueDlg
149  */
150 
152 {
153 ////@begin CAssignColumnValueDlg content construction
154  CAssignColumnValueDlg* itemCDialog1 = this;
155 
156  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
157  itemCDialog1->SetSizer(itemBoxSizer2);
158 
159  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
160  itemBoxSizer2->Add(itemBoxSizer3, 0, wxGROW|wxALL, 5);
161 
162  wxStaticText* itemStaticText4 = new wxStaticText( itemCDialog1, wxID_STATIC, _("Select Column:"), wxDefaultPosition, wxDefaultSize, 0 );
163  itemBoxSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
164 
165  wxArrayString m_ColumnsStrings;
166  m_Columns = new wxComboBox( itemCDialog1, ID_COMBOBOX, wxEmptyString, wxDefaultPosition, wxDefaultSize, m_ColumnsStrings, wxCB_READONLY );
167  itemBoxSizer3->Add(m_Columns, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
168 
169  wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
170  itemBoxSizer2->Add(itemBoxSizer6, 0, wxGROW|wxALL, 5);
171 
172  wxStaticText* itemStaticText7 = new wxStaticText( itemCDialog1, wxID_STATIC, _("Select (enter) value:"), wxDefaultPosition, wxDefaultSize, 0 );
173  itemBoxSizer6->Add(itemStaticText7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
174 
175  wxArrayString m_ValuesStrings;
176  m_Values = new wxComboBox( itemCDialog1, ID_COMBOBOX1, wxEmptyString, wxDefaultPosition, wxDefaultSize, m_ValuesStrings, wxCB_DROPDOWN );
177  itemBoxSizer6->Add(m_Values, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
178 
179  wxArrayString itemRadioBox9Strings;
180  itemRadioBox9Strings.Add(_("&Assign"));
181  itemRadioBox9Strings.Add(_("&Append"));
182  itemRadioBox9Strings.Add(_("&Prepend"));
183  wxRadioBox* itemRadioBox9 = new wxRadioBox( itemCDialog1, ID_RADIOBOX1, _("What to Do"), wxDefaultPosition, wxDefaultSize, itemRadioBox9Strings, 1, wxRA_SPECIFY_ROWS );
184  itemRadioBox9->SetSelection(0);
185  itemBoxSizer2->Add(itemRadioBox9, 0, wxALIGN_LEFT|wxALL, 5);
186 
187  itemBoxSizer2->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
188 
189  wxStdDialogButtonSizer* itemStdDialogButtonSizer11 = new wxStdDialogButtonSizer;
190 
191  itemBoxSizer2->Add(itemStdDialogButtonSizer11, 0, wxGROW|wxALL, 5);
192  wxButton* itemButton12 = new wxButton( itemCDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
193  itemStdDialogButtonSizer11->AddButton(itemButton12);
194 
195  wxButton* itemButton13 = new wxButton( itemCDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
196  itemStdDialogButtonSizer11->AddButton(itemButton13);
197 
198  itemStdDialogButtonSizer11->Realize();
199 
200  // Set validators
201  m_Values->SetValidator( wxTextValidator(wxFILTER_NONE, & m_Value) );
202  itemRadioBox9->SetValidator( wxGenericValidator(& m_Op) );
203 ////@end CAssignColumnValueDlg content construction
204 
205  if (m_Table) {
206  size_t cols = m_Table->GetColsCount();
207  for (size_t i = 0 ; i < cols; ++i) {
209  string label = m_Table->GetColumnLabel(i);
210  m_Columns->Append(wxString::FromUTF8(label.c_str()), (void*)i);
211  }
212  }
213  if (m_Columns->GetCount() > 0) {
214  m_Columns->Select(0);
215  m_Column = (int)(intptr_t)m_Columns->GetClientData(0);
216  x_UpdateValues();
217  }
218  }
219 }
220 
222 {
223  if (!CDialog::TransferDataFromWindow())
224  return false;
225 
226  int sel = m_Columns->GetSelection();
227  if (sel != wxNOT_FOUND) {
228  m_Column = (int)(intptr_t)m_Columns->GetClientData(sel);
229  }
230  else
231  m_Column = -1;
232 
233  return true;
234 }
235 
237 {
238  if (!m_Table)
239  return;
240 
241  m_Value = m_Values->GetValue();
242  m_Values->Clear();
243  int sel = m_Columns->GetSelection();
244  if (sel != wxNOT_FOUND) {
245  m_Column = (int)(intptr_t)m_Columns->GetClientData(sel);
246  size_t rows = m_Table->GetRowsCount();
247  set<string> values;
248  string s;
249  for (size_t i = 0; i < rows; ++i) {
250  m_Table->GetStringValue(i, (size_t)m_Column, s);
251  values.insert(s);
252  if (values.size() >= 10)
253  break;
254  }
255  ITERATE(set<string>, it, values) {
256  m_Values->Append(*it);
257  }
258  }
259  else {
260  m_Column = -1;
261  }
262  m_Values->SetValue(m_Value);
263 }
264 
266 {
267  size_t cols = table.GetColsCount();
268  for (size_t i = 0 ; i < cols; ++i) {
269  if (table.GetColumnType(i) == ITableData::kString && table.AllowEdit(i)) {
270  return true;
271  }
272  }
273  return false;
274 }
275 
276 
277 /*!
278  * Should we show tooltips?
279  */
280 
282 {
283  return true;
284 }
285 
286 /*!
287  * Get bitmap resources
288  */
289 
290 wxBitmap CAssignColumnValueDlg::GetBitmapResource( const wxString& name )
291 {
292  // Bitmap retrieval
293 ////@begin CAssignColumnValueDlg bitmap retrieval
294  wxUnusedVar(name);
295  return wxNullBitmap;
296 ////@end CAssignColumnValueDlg bitmap retrieval
297 }
298 
299 /*!
300  * Get icon resources
301  */
302 
303 wxIcon CAssignColumnValueDlg::GetIconResource( const wxString& name )
304 {
305  // Icon retrieval
306 ////@begin CAssignColumnValueDlg icon retrieval
307  wxUnusedVar(name);
308  return wxNullIcon;
309 ////@end CAssignColumnValueDlg icon retrieval
310 }
311 
312 /*!
313  * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_COMBOBOX
314  */
315 
316 void CAssignColumnValueDlg::OnComboboxSelected( wxCommandEvent& event )
317 {
318  x_UpdateValues();
319 }
320 
322 {
323  if (m_Column < 0)
324  return 0;
325 
327  if (m_Op == 1)
329  else if (m_Op == 2)
331 
332  return new CCmdTableAssignColumn(*m_Table, m_Column, m_Value, op);
333 }
334 
335 static const char* kColumn = "Column";
336 static const char* kValue = "Value";
337 static const char* kOp = "Op";
338 
339 
341 {
343 
344  if (m_Table && !m_RegPath.empty()) {
346 
348  m_Columns->SetValue(ToWxString(view.GetString(kColumn)));
349  m_Op = view.GetInt(kOp, m_Op);
350  if (m_Op < 0 || m_Op > 2)
351  m_Op = 0;
352  }
353 }
354 
356 {
358 
359  if (m_Table && !m_RegPath.empty()) {
361  view.Set(kValue, ToStdString(m_Value));
362  view.Set(kColumn, ToStdString(m_Columns->GetValue()));
363  view.Set(kOp, m_Op);
364  }
365 }
366 
static const char * kOp
static const char * kColumn
static const char * kValue
#define SYMBOL_CASSIGNCOLUMNVALUEDLG_STYLE
#define SYMBOL_CASSIGNCOLUMNVALUEDLG_SIZE
#define SYMBOL_CASSIGNCOLUMNVALUEDLG_POSITION
#define SYMBOL_CASSIGNCOLUMNVALUEDLG_IDNAME
#define SYMBOL_CASSIGNCOLUMNVALUEDLG_TITLE
#define ID_COMBOBOX
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void CreateControls()
Creates the controls and sizers.
void OnComboboxSelected(wxCommandEvent &event)
wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_COMBOBOX
virtual void SaveSettings() const
bool Create(wxWindow *parent, wxWindowID id=10003, const wxString &caption=_("Assign column value dlg"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
static bool CanAssignColumn(ITableData &table)
static bool ShowToolTips()
Should we show tooltips?
void Init()
Initialises member variables.
CDialog.
Definition: dialog.hpp:47
virtual void SaveSettings() const
Definition: dialog.cpp:67
virtual void LoadSettings()
Definition: dialog.cpp:112
string m_RegPath
Definition: dialog.hpp:70
CRegistryWriteView GetWriteView(const string &section)
get a read-write view at a particular level.
Definition: registry.cpp:462
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
CRegistryReadView GetReadView(const string &section) const
get a read-only view at a particular level.
Definition: registry.cpp:428
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
int GetInt(const string &key, int default_val=0) const
access a named key at this level, with no recursion
Definition: reg_view.cpp:230
string GetString(const string &key, const string &default_val=kEmptyStr) const
Definition: reg_view.cpp:246
void Set(const string &key, int val)
access a named key at this level, with no recursion
Definition: reg_view.cpp:533
Interface (functor) for object editing.
virtual string GetTableTypeId() const =0
virtual bool AllowEdit(size_t)
Definition: table_data.hpp:81
virtual string GetColumnLabel(size_t col) const =0
virtual size_t GetRowsCount() const =0
virtual ColumnType GetColumnType(size_t col) const =0
virtual void GetStringValue(size_t, size_t, string &) const =0
virtual size_t GetColsCount() const =0
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
size_type size() const
Definition: set.hpp:132
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
int intptr_t
Definition: ncbitype.h:185
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static const char label[]
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
#define ID_RADIOBOX1
<!DOCTYPE HTML >< html > n< header > n< title > PubSeq Gateway Help Page</title > n< style > n table
END_EVENT_TABLE()
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
#define ID_COMBOBOX1
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Tue Apr 23 07:40:11 2024 by modify_doxy.py rev. 669887