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

Go to the SVN repository for this file.

1 /* $Id: project_selector_panel.cpp 47479 2023-05-02 13:24:02Z ucko $
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: Andrey Yazhuk
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
36 
38 #include <gui/core/document.hpp>
40 
41 #include <serial/iterator.hpp>
45 
46 #include <corelib/ncbi_process.hpp>
47 
48 #include <wx/bitmap.h>
49 #include <wx/icon.h>
50 #include <wx/sizer.h>
51 #include <wx/listbox.h>
52 #include <wx/checkbox.h>
53 #include <wx/radiobut.h>
54 #include <wx/textctrl.h>
55 
56 ////@begin includes
57 ////@end includes
58 
59 
62 
63 
64 ///////////////////////////////////////////////////////////////////////////////
66 : m_EnablePackaging(false),
67  m_EnableDecideLater(true),
68  m_EnableCreateSeparate(true),
69  m_ProjectMode(eAddToExistingProject),
70  m_SelectedProjectId(-1),
71  m_Package(false),
72  m_CreateFolder(false),
73  m_FolderName("New Folder")
74 {
75 }
76 
77 
79  CProjectService* srv)
80 {
81  if (!objects.empty()) {
82  CScope* scope = objects.front().scope;
83  if (!scope)
84  return;
85 
87  if (!ws) return;
88 
89  CGBDocument* doc = dynamic_cast<CGBDocument*>(ws->GetProjectFromScope(*scope));
90  if (doc)
91  m_SelectedProjectId = doc->GetId();
92  }
93 }
94 
95 
96 static const char* kModeTag = "Mode";
97 static const char* kCreateFolderTag = "CreateFolder";
98 static const char* kFolderNameTag = "FolderName";
99 static const char* kPIDTag = "PID";
100 static const char* kSelPrjIdTag = "Selected Project Id";
101 
103  const string& section) const
104 {
108 
109  /// project IDs are valid only within a single application session
110  /// so we use TPid to distinguish between the runs
111  /// (this is not 100% guarantee but works for practical purposes)
113  view.Set(CGuiRegistryUtil::MakeKey(section, kPIDTag), int(pid));
115 }
116 
117 
119  const string& section)
120 {
124 
125  int pid = CCurrentProcess::GetPid();
126  int saved_pid = view.GetInt(CGuiRegistryUtil::MakeKey(section, kPIDTag), 0);
127  if(saved_pid == pid) {
129  view.GetInt(CGuiRegistryUtil::MakeKey(section, kSelPrjIdTag), static_cast<int>(m_SelectedProjectId));
130  }
131 }
132 
133 
135 {
136  string folder_name = m_CreateFolder ? m_FolderName : kEmptyStr;
137 
138  switch(m_ProjectMode) {
140  options.Set_CreateNewProject(folder_name);
141  break;
142 
144  options.Set_CreateSeparateProjects();
145  break;
146 
148  options.Set_AddToExistingProject(m_SelectedProjectId, folder_name);
149  break;
150 
151  default:
152  _ASSERT(false);
153  }
154 }
155 
156 
157 ///////////////////////////////////////////////////////////////////////////////
158 /// CProjectSelectorPanel
159 
160 IMPLEMENT_DYNAMIC_CLASS( CProjectSelectorPanel, wxPanel )
161 
162 BEGIN_EVENT_TABLE( CProjectSelectorPanel, wxPanel )
163 
164 ////@begin CProjectSelectorPanel event table entries
165  EVT_INIT_DIALOG( CProjectSelectorPanel::OnInitDialog )
166 
167  EVT_RADIOBUTTON( ID_CREATE_NEW_BTN, CProjectSelectorPanel::OnCreateNewBtnSelected )
168 
169  EVT_RADIOBUTTON( ID_CREATE_DEP_BTN, CProjectSelectorPanel::OnCreateDepBtnSelected )
170 
171  EVT_RADIOBUTTON( ID_ADD_TO_EXIST_BTN, CProjectSelectorPanel::OnAddToExistBtnSelected )
172 
173  EVT_LISTBOX( ID_PROJECT_LIST, CProjectSelectorPanel::OnProjectListSelected )
174 
176 
177 ////@end CProjectSelectorPanel event table entries
178 
179 
181 
183 {
184  Init();
185 }
186 
187 CProjectSelectorPanel::CProjectSelectorPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
188 {
189  Init();
190  Create(parent, id, pos, size, style);
191 }
192 
193 bool CProjectSelectorPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
194 {
195 ////@begin CProjectSelectorPanel creation
196  wxPanel::Create( parent, id, pos, size, style );
197 
198  CreateControls();
199  if (GetSizer())
200  {
201  GetSizer()->SetSizeHints(this);
202  }
203  Centre();
204 ////@end CProjectSelectorPanel creation
205  return true;
206 }
207 
208 
210 {
211 ////@begin CProjectSelectorPanel destruction
212 ////@end CProjectSelectorPanel destruction
213 }
214 
215 
217 {
218 ////@begin CProjectSelectorPanel member initialisation
222  m_Separator = NULL;
226 ////@end CProjectSelectorPanel member initialisation
227 
228  m_SimpleMode = false;
229 
231  m_SelProjectIndex = -1;
232 }
233 
234 
236 {
237  m_ProjectService = service;
238 
240 }
241 
242 
244 {
245  m_Params = params;
246 }
247 
248 
250 {
251  params = m_Params;
252 }
253 
254 
256 {
257 ////@begin CProjectSelectorPanel content construction
258  CProjectSelectorPanel* itemPanel1 = this;
259 
260  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
261  itemPanel1->SetSizer(itemBoxSizer2);
262 
263  wxRadioButton* itemRadioButton3 = new wxRadioButton( itemPanel1, ID_CREATE_NEW_BTN, _("Create a new Project"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
264  itemRadioButton3->SetValue(false);
265  itemBoxSizer2->Add(itemRadioButton3, 0, wxALIGN_LEFT|wxALL, 5);
266 
267  m_CreateSeparateRadio = new wxRadioButton( itemPanel1, ID_CREATE_DEP_BTN, _("Create a separate Project for every item"), wxDefaultPosition, wxDefaultSize, 0 );
268  m_CreateSeparateRadio->SetValue(false);
269  itemBoxSizer2->Add(m_CreateSeparateRadio, 0, wxALIGN_LEFT|wxALL, 5);
270 
271  m_ExistingRadio = new wxRadioButton( itemPanel1, ID_ADD_TO_EXIST_BTN, _("Add to an existing Project"), wxDefaultPosition, wxDefaultSize, 0 );
272  m_ExistingRadio->SetValue(false);
273  itemBoxSizer2->Add(m_ExistingRadio, 0, wxALIGN_LEFT|wxALL, 5);
274 
275  wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
276  itemBoxSizer2->Add(itemBoxSizer6, 1, wxGROW|wxALL, 0);
277 
278  itemBoxSizer6->Add(5, 5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
279 
280  wxArrayString m_ProjectListStrings;
281  m_ProjectList = new wxListBox( itemPanel1, ID_PROJECT_LIST, wxDefaultPosition, wxSize(200, 100), m_ProjectListStrings, wxLB_SINGLE );
282  itemBoxSizer6->Add(m_ProjectList, 1, wxGROW|wxALL, 5);
283 
284  m_Separator = new wxStaticLine( itemPanel1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
285  itemBoxSizer2->Add(m_Separator, 0, wxGROW|wxALL, 5);
286 
287  m_PackageCheck = new wxCheckBox( itemPanel1, ID_PACKAGE_CHECK, _("Package as a single item"), wxDefaultPosition, wxDefaultSize, 0 );
288  m_PackageCheck->SetValue(false);
289  itemBoxSizer2->Add(m_PackageCheck, 0, wxALIGN_LEFT|wxALL, 5);
290 
291  m_FolderCheck = new wxCheckBox( itemPanel1, ID_CREATE_FOLDER_CHECK, _("Create a Folder for the items"), wxDefaultPosition, wxDefaultSize, 0 );
292  m_FolderCheck->SetValue(false);
293  itemBoxSizer2->Add(m_FolderCheck, 0, wxALIGN_LEFT|wxALL, 5);
294 
295  wxBoxSizer* itemBoxSizer12 = new wxBoxSizer(wxHORIZONTAL);
296  itemBoxSizer2->Add(itemBoxSizer12, 0, wxGROW|wxALL, 0);
297 
298  itemBoxSizer12->Add(5, 5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
299 
300  m_FolderInput = new wxTextCtrl( itemPanel1, ID_FOLDER_INPUT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
301  itemBoxSizer12->Add(m_FolderInput, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
302 
303  // Set validators
304  itemRadioButton3->SetValidator( wxGenericValidator(& m_CreateOption) );
305  m_CreateSeparateRadio->SetValidator( wxGenericValidator(& m_SeparateOption) );
306  m_ExistingRadio->SetValidator( wxGenericValidator(& m_ExistingOption) );
307  m_PackageCheck->SetValidator( wxGenericValidator(& m_Params.m_Package) );
308  m_FolderCheck->SetValidator( wxGenericValidator(& m_Params.m_CreateFolder) );
309  m_FolderInput->SetValidator( wxGenericValidator(& m_FolderName) );
310 ////@end CProjectSelectorPanel content construction
311 }
312 
313 
315 {
316  m_Separator->Hide();
317  m_PackageCheck->Hide();
318  m_FolderCheck->Hide();
319  GetSizer()->Hide(GetSizer()->GetItemCount() - 1);
320  //m_FolderInput->Hide();
321  //m_LaterRadio->Hide();
322 
323  Layout();
324 }
325 
326 
328 {
330 
331  m_ProjectIds.clear();
332  m_ProjectList->Clear();
333 
335  if (!ws) return;
336 
337  CWorkspaceFolder& root_folder = ws->SetWorkspace();
338 
339  for (CTypeConstIterator<CGBProjectHandle> it(root_folder); it; ++it) {
340  const CGBDocument* doc = dynamic_cast<const CGBDocument*>(&*it);
341  if (doc && doc->IsLoaded()) {
342  m_ProjectIds.push_back(doc->GetId());
343  const CProjectDescr& descr = doc->GetDescr();
344  m_ProjectList->Append(ToWxString(descr.GetTitle()));
345  }
346  }
347 }
348 
349 
351 {
354 }
355 
356 
358 {
361 }
362 
363 
365 {
367  //x_SelectProjectByParams();
369 }
370 
371 
372 void CProjectSelectorPanel::OnProjectListSelected( wxCommandEvent& event )
373 {
374  m_ExistingRadio->SetValue(true);
377 }
378 
379 
381 {
382  if(m_ExistingOption && m_SelProjectIndex < 0 && ! m_ProjectIds.empty()) {
383  m_SelProjectIndex = 0;
384  for( size_t i = 0; i < m_ProjectIds.size(); i++ ) {
387  break;
388  }
389  }
390  }
391 }
392 
393 
395 {
398 }
399 
400 
402 {
403  typedef SProjectSelectorParams TParams;
404 
405  int prj_count = m_ProjectList->GetCount();
406 
407  // correct option if needed
408  if( ! prj_count && m_Params.m_ProjectMode == TParams::eAddToExistingProject) {
409  m_Params.m_ProjectMode = TParams::eCreateOneProject;
410  }
411 
415 
416  // update Project List
417  bool en_list = (prj_count > 0);
418  m_ProjectList->Enable(en_list);
419 
421 
422  int sel_index = (m_ExistingOption && m_SelProjectIndex > -1) ? m_SelProjectIndex : wxNOT_FOUND;
423  m_ProjectList->SetSelection(sel_index);
424 
425  m_ExistingRadio->Enable( ! m_ProjectIds.empty());
426 
427  bool en_package = (m_SeparateOption && m_Params.m_EnablePackaging);
428  m_PackageCheck->Enable(en_package);
429 
431 
433 
435  return wxPanel::TransferDataToWindow();
436 }
437 
438 
440 {
441  if(wxPanel::TransferDataFromWindow()) {
442  if(m_ProjectList->IsEnabled()) {
443  // save item selection, it can be removed
444  m_SelProjectIndex = m_ProjectList->GetSelection();
445  if(m_SelProjectIndex >= 0) {
447  }
448  }
449  if(m_CreateOption) {
451  } else if(m_SeparateOption) {
453  } else {
455  }
457 
458  return true;
459  }
460  return false;
461 }
462 
463 
464 void CProjectSelectorPanel::OnInitDialog( wxInitDialogEvent& event )
465 {
466  wxPanel::OnInitDialog(event);
467 }
468 
469 
471 {
472  return true;
473 }
474 
475 
476 wxBitmap CProjectSelectorPanel::GetBitmapResource( const wxString& name )
477 {
478  // Bitmap retrieval
479 ////@begin CProjectSelectorPanel bitmap retrieval
480  wxUnusedVar(name);
481  return wxNullBitmap;
482 ////@end CProjectSelectorPanel bitmap retrieval
483 }
484 
485 
486 wxIcon CProjectSelectorPanel::GetIconResource( const wxString& name )
487 {
488  // Icon retrieval
489 ////@begin CProjectSelectorPanel icon retrieval
490  wxUnusedVar(name);
491  return wxNullIcon;
492 ////@end CProjectSelectorPanel icon retrieval
493 }
494 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
EVT_CHECKBOX(ID_CADJUSTFEATURES_CHECKBOX, CAdjustFeaturesForGaps::OnKnownUnknownSelected) EVT_CHECKBOX(ID_CADJUSTFEATURES_CHECKBOX1
CGBDocument.
Definition: document.hpp:113
static string MakeKey(const string &section, const string &key, const string &delim=CGuiRegistry::kDecimalDot)
create a key from a section and a subkey
Definition: registry.cpp:504
CProjectSelectorPanel - a panel that allows the user to specify how the project items created by a pl...
SProjectSelectorParams m_Params
void OnInitDialog(wxInitDialogEvent &event)
void OnProjectListSelected(wxCommandEvent &event)
void OnCreateFolderCheckClick(wxCommandEvent &event)
bool Create(wxWindow *parent, wxWindowID id=ID_CPROJECTSELECTORPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL)
void OnCreateDepBtnSelected(wxCommandEvent &event)
CProjectService * m_ProjectService
this member is used for saving projects IDs within the session static TProjectId m_LastSelectedProjec...
void OnCreateNewBtnSelected(wxCommandEvent &event)
wxBitmap GetBitmapResource(const wxString &name)
CProjectSelectorPanel()
CProjectSelectorPanel.
void SetProjectService(CProjectService *service)
wxIcon GetIconResource(const wxString &name)
void GetParams(SProjectSelectorParams &params) const
void OnAddToExistBtnSelected(wxCommandEvent &event)
void SetParams(const SProjectSelectorParams &params)
CProjectService - a service providing API for operations with Workspaces and Projects.
CRef< objects::CGBWorkspace > GetGBWorkspace()
CRef –.
Definition: ncbiobj.hpp:618
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
bool GetBool(const string &key, bool default_val=false) const
Definition: reg_view.cpp:241
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
CScope –.
Definition: scope.hpp:92
CProjectSelectOptions - describes how new Project Items shall be added to a workspace.
void Set_CreateNewProject(const string &folder=kEmptyStr)
void Set_AddToExistingProject(TProjectId &project_id, const string &folder=kEmptyStr)
Template class for iteration on objects of class C (non-medifiable version)
Definition: iterator.hpp:767
#define _(proto)
Definition: ct_nlmzip_i.h:78
#define true
Definition: bool.h:35
#define false
Definition: bool.h:36
static void Init(void)
Definition: cursor6.c:76
string
Definition: cgiapp.hpp:687
#define NULL
Definition: ncbistd.hpp:225
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
static TPid GetPid(void)
Get process identifier (pid) for the current process.
pid_t TPid
Process identifier (PID) and process handle.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
const TTitle & GetTitle(void) const
Get the Title member data.
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
END_EVENT_TABLE()
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
Defines process management classes.
USING_SCOPE(objects)
static const char * kCreateFolderTag
static const char * kSelPrjIdTag
static const char * kModeTag
static const char * kPIDTag
static const char * kFolderNameTag
SProjectSelectorParams - holds data for CProjectSelectorPanel.
void SelectProjectByObjects(TConstScopedObjects &objects, CProjectService *srv)
is all objects belong to the same project - selects the project
void LoadSettings(CRegistryReadView &view, const string &section)
bool m_CreateFolder
package in a single item
void ToLoadingOptions(CSelectProjectOptions &options)
void SaveSettings(CRegistryWriteView &view, const string &section) const
#define _ASSERT
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Fri Apr 12 17:22:44 2024 by modify_doxy.py rev. 669887