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

Go to the SVN repository for this file.

1 /* $Id: lblast_ui_data_source.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: Liangshou Wu
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 
33 
36 
38 #include <gui/core/app_dialogs.hpp>
42 
45 
49 
52 
54 
55 #include <wx/menu.h>
56 
60 
62 
65 
66 static const char* kLBLASTLoadOption = "Local BLAST DB";
67 static const int kLoaderPriority = 90;
68 
69 
70 ///////////////////////////////////////////////////////////////////////////////
71 /// CLBLASTDSEvtHandler - wxEvtHandler-derived adapter for local BLAST data source.
72 
73 class CLBLASTDSEvtHandler : public wxEvtHandler
74 {
76 public:
78  : m_Workbench(workbench) {
79  }
80  void OnLoadBLASTDB(wxCommandEvent& event)
81  {
82  if(m_Workbench) {
84  }
85  }
86 protected:
88 };
89 
90 BEGIN_EVENT_TABLE(CLBLASTDSEvtHandler, wxEvtHandler)
93 
94 
95 ///////////////////////////////////////////////////////////////////////////////
96 /// CLBLASTUIDataSource
97 
98 static const char* kLBLAST_DS_Icon = "icon::lblast_data_source";
99 
101 : m_Type(&type),
102  m_Descr("Local BLAST", kLBLAST_DS_Icon),
103  m_SrvLocator(NULL),
104  m_Open(false)
105 {
106 }
107 
109 {
110 }
111 
112 
114 {
115  return "local_blast_data_source";
116 }
117 
118 
120 {
121  return "Local BLAST Data Source";
122 }
123 
124 
126 {
127  m_SrvLocator = locator;
128 }
129 
130 
132 {
134 
135  /// this is not a good solution, but simple
136  IWorkbench* workbench = dynamic_cast<IWorkbench*>(m_SrvLocator);
137 
138  if(items.size() != 1 || workbench == NULL) {
139  return contrib; // return empty object - nothin to contribute
140  }
141 
143 
144  PT::CItem* item = items[0];
145  int type = item->GetType();
146 
147  if(type == PT::eDataSource) {
148  PT::CDataSource* ds_item = dynamic_cast<PT::CDataSource*>(item);
149 
150  if(ds_item) {
151  CIRef<IUIDataSource> ds = ds_item->GetData();
152  CLBLASTUIDataSource* bam_ds = dynamic_cast<CLBLASTUIDataSource*>(ds.GetPointer());
153 
154  if(bam_ds) {
155  wxMenu* menu = new wxMenu;
156  menu->Append(wxID_SEPARATOR, wxT("Top Actions"));
157  cmd_reg.AppendMenuItem(*menu, eCmdLoadDB);
158 
159  contrib.first = menu;
160  contrib.second = new CLBLASTDSEvtHandler(workbench);
161  }
162  }
163  }
164  return contrib;
165 }
166 
167 
169 {
170  return *m_Type;
171 }
172 
173 
175 {
176  return m_Descr;
177 }
178 
179 
181 {
182  return m_Open;
183 }
184 
185 //static const char* kCmdExtPoint = "scoped_objects::cmd_contributor";
186 static const char* kAppExpCmdExtPoint = "project_tree_view::context_menu::item_cmd_contributor";
187 
189 {
190  if (m_Open) {
191  LOG_POST(Error << "CLBLASTUIDataSource::Open(): "
192  "attempt to open already open data source");
193  return false;
194  }
195 
196  CStopWatch sw;
197  sw.Start();
198 
199  /// register itself as menu contributor
201  reg->AddExtension(kAppExpCmdExtPoint, *this);
202 
203  m_Open = true;
204  return true;
205 }
206 
207 
209 {
210  if (m_Open) {
211  /// remove itself from menu contribution points
213  reg->RemoveExtension(kAppExpCmdExtPoint, *this);
214 
215  m_Open = false;
216  return true;
217  }
218 
219  return false;
220 }
221 
222 
224 {
225  //TODO
226 }
227 
228 
230 {
231  // TODO may need to link the manager to this particular datasource
232  return new CLBLASTUILoadManager();
233 }
234 
236  return eCmdLoadDB;
237 }
238 
240 
241 
242  IWorkbench* workbench = dynamic_cast<IWorkbench*>(m_SrvLocator);
243 
244  return new CLBLASTDSEvtHandler( workbench );
245 }
246 
247 string CLBLASTUIDataSource::AddDataLoader(const objects::CUser_object& obj)
248 {
250 }
251 
252 string CLBLASTUIDataSource::GetLoaderName(const objects::CUser_object& obj) const
253 {
255 }
256 
257 
258 ///////////////////////////////////////////////////////////////////////////////
259 /// CLBLASTUIDataSourceType
261  : m_Descr("Local BLAST data Loader", "")
262 {
265  wxT("lblast_data_source.png"));
266 }
267 
268 
270 {
271  return m_Descr;
272 }
273 
274 
276 {
277  return new CLBLASTUIDataSource(*this);
278 }
279 
280 
282 {
283  return true; // we want to create default "Bam" datasource
284 }
285 
286 
288 {
289  static string ext_id("local_blast_data_source_type");
290  return ext_id;
291 }
292 
293 
295 {
296  return m_Descr.GetLabel();
297 }
298 
299 
300 
301 ///////////////////////////////////////////////////////////////////////////////
302 /// CLBLASTUILoadManager
304 : m_SrvLocator(NULL),
305  m_ParentWindow(NULL),
306  m_Descriptor(kLBLASTLoadOption, ""),
307  m_State(eInvalid),
308  m_ParamsPanel(),
309  m_ProjectSelPanel()
310 {
312  m_Descriptor.SetLogEvent("loaders");
313 }
314 
315 
317 {
318  m_SrvLocator = srv_locator;
319 }
320 
321 
323 {
324  m_ParentWindow = parent;
325 }
326 
327 
329 {
330  return m_Descriptor;
331 }
332 
333 
335 {
337 }
338 
339 
341 {
342  m_State = eInvalid;
343  m_ParamsPanel = 0;
344  m_ProjectSelPanel = 0; // window is destroyed by its parent
345 }
346 
347 
349 {
350  switch (m_State) {
351  case eSelectDir:
352  if (m_ParamsPanel == NULL) {
356  }
357  return m_ParamsPanel;
358  case eSelectProject:
359  if(m_ProjectSelPanel == NULL) {
365  }
366  return m_ProjectSelPanel;
367  default:
368  return NULL;
369  }
370  return NULL;
371 }
372 
373 
375 {
376  switch(m_State) {
377  case eSelectDir:
378  return action == eNext;
379  case eSelectProject:
380  return action == eBack || action == eNext;
381  case eCompleted:
382  return false; // nothing left to do
383  default:
384  _ASSERT(false);
385  return false;
386  }
387 }
388 
389 
391 {
392  return m_State == eSelectProject;
393 }
394 
395 
397 {
398  return m_State == eCompleted;
399 }
400 
401 
403 {
404  if (m_State == eSelectDir) {
405  if (action == eNext) {
409  return true;
410  }
411  return false;
412  }
413  else {
414  return false;
415  }
416  }
417  else if (m_State == eSelectProject) {
418  if (action == eBack) {
420  return true;
421  }
422  else if (action == eNext) {
425  return true;
426  }
427  return false;
428  }
429  }
430 
431  _ASSERT(false);
432  return false;
433 }
434 
435 
437 {
439 
441  string folder_name = m_ProjectParams.m_CreateFolder ? m_ProjectParams.m_FolderName : "";
442 
444  CSelectProjectOptions options;
446  return new CObjectLoadingTask(srv, *loader, options);
447 }
448 
449 
451 {
452  m_RegPath = path; // store for later use
453  if (!m_RegPath.empty())
454  m_LBLASTParams.SetRegistryPath(m_RegPath + ".LBLASTParams");
455  else
457 }
458 
459 static const char* kProjectParamsTag = "ProjectParams";
460 static const char* kMappingAssembly = ".MapAssembly";
461 
463 {
464  if ( !m_RegPath.empty() ) {
466  CRegistryWriteView view = gui_reg.GetWriteView(m_RegPath);
467 
468  /// save Project Panel settings
471  }
472 }
473 
475 {
476  if( ! m_RegPath.empty()) {
478  CRegistryReadView view = gui_reg.GetReadView(m_RegPath);
479 
480  /// load Project Panel settings
483  }
484 }
485 
#define static
User-defined methods of the data storage class.
Data loader implementation that uses the blast databases.
static void COpenDialog(IWorkbench *workbench, const string &loader_label=NcbiEmptyString, const vector< wxString > &filenames=vector< wxString >())
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
CLBLASTDSEvtHandler - wxEvtHandler-derived adapter for local BLAST data source.
CLBLASTDSEvtHandler(IWorkbench *workbench)
void OnLoadBLASTDB(wxCommandEvent &event)
virtual void LoadSettings()
virtual void SaveSettings() const
virtual void SetRegistryPath(const string &path)
CLBLASTObjectLoader.
CLBLASTLoadParams & GetData()
Data access.
virtual bool TransferDataFromWindow()
Transfer data from the window.
virtual bool TransferDataToWindow()
Transfer data to the window.
void SetData(const CLBLASTLoadParams &data)
CLBLASTUIDataSourceType.
CLBLASTUIDataSource.
CLBLASTUILoadManager.
CProjectSelectorPanel - a panel that allows the user to specify how the project items created by a pl...
void SetProjectService(CProjectService *service)
void GetParams(SProjectSelectorParams &params) const
void SetParams(const SProjectSelectorParams &params)
CProjectService - a service providing API for operations with Workspaces and Projects.
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
CProjectSelectOptions - describes how new Project Items shall be added to a workspace.
CStopWatch –.
Definition: ncbitime.hpp:1937
CUICommandRegistry is a centralized registry where all application commands should be registered.
Definition: ui_command.hpp:146
static CUICommandRegistry & GetInstance()
the main instance associated with the application
Definition: ui_command.cpp:176
wxMenuItem * AppendMenuItem(wxMenu &menu, TCmdID cmd_id) const
Definition: ui_command.cpp:300
IAppTask.
Definition: app_task.hpp:83
pair< wxMenu *, wxEvtHandler * > TContribution
Contribution consists of a Menu object and event handler.
Definition: pt_item.hpp:152
IServiceLocator - an abstract mechanism for locating services.
Definition: service.hpp:71
IUIDataSourceType - defines a type of a Data Source, can serve as a Data Source factory.
IUIDataSource - an interface representing a Data Source.
IUIObject - object that provides basic properties often required in a UI object.
Definition: ui_object.hpp:63
IWorkbench is the central interface in the application framework.
Definition: workbench.hpp:113
virtual int GetType() const =0
const TData & GetData() const
Definition: pt_item.hpp:135
virtual void RegisterFileAlias(const wxArtID &anId, const wxArtClient &aClient, const wxSize &aSize, const wxString &aName, long aType=wxBITMAP_TYPE_ANY, int anIndex=-1)
#define false
Definition: bool.h:36
#define NULL
Definition: ncbistd.hpp:225
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
static string AddDataLoader(const objects::CUser_object &obj)
static string GetLoaderName(const objects::CUser_object &obj)
CIRef< T > GetServiceByType()
retrieves a typed reference to a service, the name of C++ type is used as the name of the service.
Definition: service.hpp:91
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
virtual void SaveSettings() const
IServiceLocator * m_SrvLocator
virtual IUIDataSourceType & GetType() const
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
virtual wxPanel * GetCurrentPanel()
Return the panel corresponding to the current state of Tool Manager.
CLBLASTUILoadManager()
CLBLASTUILoadManager.
virtual string GetExtensionIdentifier() const
returns the unique human-readable identifier for the extension the id should use lowercase letters se...
virtual bool IsOpen()
a Data source needs to be open before use and closed after.
virtual const IUIObject & GetDescr()
returns UI description of the object (label, icon etc.)
virtual bool IsCompletedState()
Manager goes into "Complete" state when "Finish" button is pressed and all input data is gatherred an...
CLBLASTUIDataSourceType()
CLBLASTUIDataSourceType.
virtual bool AutoCreateDefaultDataSource()
returns "true" if this type needs to create a default instance of the Data Source at start-up
virtual void CleanUI()
CleanUI() is called after the host finished using the manager.
virtual void SetServiceLocator(IServiceLocator *srv_locator)
Sets / unsets Service Locator.
virtual void SetServiceLocator(IServiceLocator *locator)
virtual IUIDataSource * CreateDataSource()
factory method; create an Data Source instance
virtual bool Open()
Prepares Data Source for use, any initialization that can be potentially time-consuming or may requir...
virtual IExplorerItemCmdContributor::TContribution GetMenu(wxTreeCtrl &treeCtrl, PT::TItems &items)
for the given set of items returns a contribution
virtual string AddDataLoader(const objects::CUser_object &obj)
Add a new data loader to object manager.
virtual string GetLoaderName(const objects::CUser_object &obj) const
Get the data loader's name based on input object.
virtual IUIToolManager * GetLoadManager()
virtual void SetRegistryPath(const string &path)
virtual void SetParentWindow(wxWindow *parent)
CLBLASTParamsPanel * m_ParamsPanel
CLBLASTLoadParams m_LBLASTParams
CRef< CLBLASTUIDataSourceType > m_Type
virtual wxEvtHandler * CreateEvtHandler()
CProjectSelectorPanel * m_ProjectSelPanel
SProjectSelectorParams m_ProjectParams
virtual bool DoTransition(EAction action)
Performs transition if possible and returns true, otherwise the function shall warn the user about th...
virtual string GetExtensionIdentifier() const
returns the unique human-readable identifier for the extension the id should use lowercase letters se...
virtual void InitUI()
Initializes the Manager before using it in UI.
virtual const IUIObject & GetDescriptor() const
Returns the object describing this tool (UI meta data).
virtual bool IsFinalState()
True if Tool Manager has reached its final state, i.e.
IServiceLocator * m_SrvLocator
virtual IAppTask * GetTask()
Once parameters are gathered and validated this function is called to produce the final Task object t...
virtual const IUIObject & GetDescr()
returns UI description of the type (label, icon etc.)
virtual bool CanDo(EAction action)
Indicates whether given transition is possible in the current state.
static CIRef< IExtensionRegistry > GetInstance()
provides access to the Singleton
virtual void SetLogEvent(const string &log_event)
Definition: ui_object.cpp:118
virtual const string & GetLabel() const
Definition: ui_object.cpp:124
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
void Start(void)
Start the timer.
Definition: ncbitime.hpp:2764
static CStopWatch sw
USING_SCOPE(objects)
static const char * kProjectParamsTag
static const char * kMappingAssembly
END_EVENT_TABLE()
static const char * kLBLAST_DS_Icon
CLBLASTUIDataSource.
static const int kLoaderPriority
static const char * kAppExpCmdExtPoint
static const char * kLBLASTLoadOption
#define wxT(x)
Definition: muParser.cpp:41
@ eDataSource
Definition: pt_item.hpp:121
vector< CItem * > TItems
Definition: pt_item.hpp:113
The Object manager core.
ViewerWindowBase::OnEditMenu ViewerWindowBase::OnJustification EVT_MENU(MID_SHOW_GEOM_VLTNS, ViewerWindowBase::OnShowGeomVltns) EVT_MENU(MID_FIND_PATTERN
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
Definition: type.c:6
#define _ASSERT
wxFileArtProvider * GetDefaultFileArtProvider()
Definition: wx_utils.cpp:334
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
#define const
Definition: zconf.h:232
Modified on Mon May 20 04:59:24 2024 by modify_doxy.py rev. 669887