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

Go to the SVN repository for this file.

1 /* $Id: project_tree_view.cpp 41875 2018-10-31 17:19:44Z filippov $
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 
35 
37 
40 #include <gui/core/pt_project.hpp>
41 #include <gui/core/pt_utils.hpp>
44 
47 
49 
51 
52 #include <serial/iterator.hpp>
53 
54 
57 
58 
61  "Project View - commands applicable to Explorer Items");
62 
63 /// register the factory in the Extention Point
65  decl1("view_manager_service::view_factory", new CProjectTreeViewFactory());
66 
67 
68 ///////////////////////////////////////////////////////////////////////////////
69 /// CProjectTreeView
70 
72  "Project View", // type name
73  "project_tree_view", // icon alias TODO
74  "Project View hint - TODO",
75  "Project View description - TODO",
76  "PROJECT_TREE_VIEW", // help Id
77  "System", // category
78  true); // singleton
79 
81  ON_EVENT(CEvent, CViewEvent::eWidgetSelectionChanged,
82  &CProjectTreeView::OnWidgetSelChanged)
84 
85 
87 : m_Workbench(NULL),
88  m_SelectionService(NULL),
89  m_Panel(NULL)
90 {
91 }
92 
93 
95 {
96 }
97 
98 
100 {
101  return m_TypeDescr;
102 }
103 
104 
106 {
107  if(workbench) {
108  // connect to services
110  if(sel_srv) {
111  sel_srv->AttachClient(this);
112  }
113 
114  // connect
116  if (dm_srv) {
117  dm_srv->AttachContext(*this);
118  }
119 
120  m_Panel->SetWorkbench(workbench);
121 
122  // to receive selection change event
124  } else if(m_Workbench) {
125  m_Panel->RemoveListener(this);
126 
128 
129  // disconnect from services
131  if(sel_srv) {
132  sel_srv->DetachClient(this);
133  }
134 
135  // disconnect
137  if (dm_srv) {
138  dm_srv->DetachContext(*this);
139  }
140  }
141 
142  m_Workbench = workbench;
143 }
144 
146 {
147  m_Panel = new CProjectTreePanel();
148  m_Panel->Create(parent, wxID_ANY);
149 }
150 
151 
153 {
154  if(m_Panel) {
155  m_Panel->Destroy();
156  m_Panel = NULL;
157  }
158 }
159 
161 {
162  return m_Panel;
163 }
164 
165 
167 {
168  return m_TypeDescr.GetLabel();
169 }
170 
171 
173 {
174  return m_TypeDescr.GetIconAlias();
175 }
176 
177 
179 {
180  return NULL;
181 }
182 
183 
185 {
186  // do nothing
187 }
188 
189 
191 {
192  return NULL;
193 }
194 
195 
196 void CProjectTreeView::UpdateMenu(wxMenu& root_menu)
197 {
198 }
199 
200 
202 {
203  return CFingerprint(m_TypeDescr.GetLabel(), true);
204 }
205 
206 
207 void CProjectTreeView::SetRegistryPath(const string& path)
208 {
209  m_RegPath = path; // store for later use
210 }
211 
212 
213 //static const char* kDisplayModeTag = "DisplayMode";
214 
216 {
218  gui_reg.Set("GBENCH.Application.ViewOptions.HideDisabledProjectItems", PT::sm_HideDisabledItems);
219 }
220 
221 
223 {
225  PT::sm_HideDisabledItems = gui_reg.GetBool("GBENCH.Application.ViewOptions.HideDisabledProjectItems", false);
226 }
227 
228 
229 /// ISelectionClient //////////////////////////////////////////////////////////
230 
232 {
233  _ASSERT(evt);
234 
237  }
238 }
239 
241 {
242  CProjectTreeView* nc_this = const_cast<CProjectTreeView*>(this);
243 
244  PT::TItems sel_items;
245  nc_this->m_Panel->GetSelectedItems(sel_items);
246  if (sel_items.empty())
247  return;
248 
250 
251  CRef<CGBWorkspace> ws = prj_srv->GetGBWorkspace();
252  if (!ws) return;
253 
255 
256  NON_CONST_ITERATE (PT::TItems, it, sel_items) {
257  PT::CItem& item = **it;
258 
259  SConstScopedObject obj;
260 
261  switch( item.GetType() ){
262  case PT::eProject: {
263  /* TODO
264  TProjectTreeItem* prj_item = dynamic_cast<TProjectTreeItem*>(&item);
265 
266  int id = prj_item->GetData();
267  CGBDocument* doc = dynamic_cast<CGBDocument*>(ws->GetProjectFromId(id));
268  if(doc && doc->IsLoaded() && doc->GetScope()) {
269  obj.object.Reset(doc);
270  obj.scope.Reset(doc->GetScope());
271  }*/
272  break;
273  }
274 
275  case PT::eProjectItem: {
276  PT::CProjectItem* prj_item = static_cast<PT::CProjectItem*>(&item);
277  if (!prj_item) continue;
278 
279  CRef<CProjectItem> projItem = prj_item->GetData();
280  if (!projItem->IsEnabled())
281  continue;
282 
283  PT::CProject* projectItem = PT::GetProject(*m_Panel->m_Tree, *prj_item);
284  if (!projectItem) continue;
285 
286  CGBDocument* doc = projectItem->GetData();
287 
288  obj.object.Reset(projItem->GetObject());
289  obj.scope.Reset(doc->GetScope());
290  break;
291  }
292 
293  default:
294  break;
295  }
296 
297  if (obj.scope.GetPointer() && obj.object.GetPointer()) {
298  objs.push_back(obj);
299  }
300  }
301 }
302 
303 
305 {
306  m_SelectionService = service;
307 }
308 
309 
311 {
313 }
314 
315 
317 {
318  // do nothing, CProjectTreeView does not support selection broadcast
319 }
320 
321 
323 {
324  // do nothing, CProjectTreeView does not support selection broadcast
325 }
326 
327 
329 {
330  // no main object
331 }
332 
334 {
335  CProjectTreeView* nc_this = const_cast<CProjectTreeView*>(this);
336 
337  PT::TItems all_items;
338  nc_this->m_Panel->GetAllItems(all_items);
339  if (all_items.empty())
340  return;
341 
343 
344  CRef<CGBWorkspace> ws = prj_srv->GetGBWorkspace();
345  if (!ws) return;
346 
348 
349  NON_CONST_ITERATE (PT::TItems, it, all_items) {
350  PT::CItem& item = **it;
351 
352  SConstScopedObject obj;
353 
354  switch( item.GetType() ){
355  case PT::eProject: {
356  /* TODO
357  TProjectTreeItem* prj_item = dynamic_cast<TProjectTreeItem*>(&item);
358 
359  int id = prj_item->GetData();
360  CGBDocument* doc = dynamic_cast<CGBDocument*>(ws->GetProjectFromId(id));
361  if(doc && doc->IsLoaded() && doc->GetScope()) {
362  obj.object.Reset(doc);
363  obj.scope.Reset(doc->GetScope());
364  }*/
365  break;
366  }
367 
368  case PT::eProjectItem: {
369  PT::CProjectItem* prj_item = static_cast<PT::CProjectItem*>(&item);
370  if (!prj_item) continue;
371 
372  CRef<CProjectItem> projItem = prj_item->GetData();
373  if (!projItem->IsEnabled())
374  continue;
375 
376  PT::CProject* projectItem = PT::GetProject(*m_Panel->m_Tree, *prj_item);
377  if (!projectItem) continue;
378 
379  CGBDocument* doc = projectItem->GetData();
380 
381  obj.object.Reset(projItem->GetObject());
382  obj.scope.Reset(doc->GetScope());
383  break;
384  }
385 
386  default:
387  break;
388  }
389 
390  if (obj.scope.GetPointer() && obj.object.GetPointer()) {
391  objs.push_back(obj);
392  break; // only need 1 object;
393  }
394  }
395 }
396 
397 /// END of ISelectionClient ///////////////////////////////////////////////////
398 
400 {
401  if(m_Panel) {
402  m_Panel->GetSelectedItems(items);
403  }
404 }
405 
406 
408 {
410 }
411 
413 {
414  CRef<CSeq_loc> loc;
415  CRef<CSeq_id> id(new CSeq_id());
416 
417  TConstScopedObjects objs;
418  GetSelection(objs);
419  if (objs.size()>0) {
420  const CSeq_id * sid = dynamic_cast<const CSeq_id*>(objs.begin()->object.GetPointer());
421  if (sid) {
422  id->Assign(*sid);
423  loc.Reset(new CSeq_loc());
424  loc->SetWhole(*id);
425  }
426  }
427 
428  return loc;
429 }
430 
432 {
433  TConstScopedObjects objs;
434  GetSelection(objs);
435 
436  ITERATE (TConstScopedObjects, obj, objs) {
437  CRef<CSeq_loc> loc;
438  CRef<CSeq_id> id(new CSeq_id());
439 
440 
441  const CSeq_id * sid = dynamic_cast<const CSeq_id*>(obj->object.GetPointer());
442 
443  if (sid) {
444  CRef<CScope> scope = obj->scope;
445  id->Assign(*sid);
446  loc.Reset(new CSeq_loc());
447  loc->SetWhole(*id);
448  pObjects.push_back(SConstScopedObject(loc, scope));
449  }
450  }
451 }
452 
453 
455 {
456  TConstScopedObjects objs;
457  GetSelection(objs);
458  if (objs.size()==1) {
459  return objs.begin()->scope;
460  }
461  return CRef<CScope>();
462 }
463 
464 ///////////////////////////////////////////////////////////////////////////////
465 /// CProjectTreeViewFactory
467 {
468  static string sid("project_tree_view_factory");
469  return sid;
470 }
471 
472 
474 {
475  static string slabel("Project View Factory");
476  return slabel;
477 }
478 
479 
481 {
482  //TODO
483 }
484 
485 
487 {
489 }
490 
491 
493 {
494  return new CProjectTreeView();
495 }
496 
497 
499 {
501  if(print == fingerprint) {
502  return new CProjectTreeView();
503  }
504  return NULL;
505 }
506 
507 
CDataMiningService.
CEventHandler.
CEvent - generic event implementation TODO TODO - Attachments.
Definition: event.hpp:86
CExtensionDeclaration - static declaration helper.
CExtensionPointDeclaration - static declaration helper.
CGBDocument.
Definition: document.hpp:113
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
void Set(const string &key, int val)
set specific values
Definition: registry.cpp:178
bool GetBool(const string &key, bool default_val=false) const
Definition: registry.cpp:143
const CSerialObject * GetObject() const
retrieve the object pointed to as a CObject*
bool IsEnabled(void) const
enabled flag
CProjectService - a service providing API for operations with Workspaces and Projects.
CProjectTreePanel - a window that represents Project View.
void Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
void GetAllItems(PT::TItems &items)
void GetSelectedItems(PT::TItems &items)
CProjectTreeCtrl * m_Tree
void SetWorkbench(IWorkbench *workbench)
CProjectTreeViewFactory - a factory producing CProjectTreeView.
virtual void RegisterIconAliases(wxFileArtProvider &provider)
called by the framework to give Factory a chance to register images used by view
virtual const CViewTypeDescriptor & GetViewTypeDescriptor() const
returns a Descriptor for the View Type supported by the Factory
virtual string GetExtensionIdentifier() const
CProjectTreeViewFactory.
virtual IView * CreateInstance() const
creates a view instance
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
virtual IView * CreateInstanceByFingerprint(const TFingerprint &fingerprint) const
if fingerprint is recognized - creates and returns a new instance
CProjectTreeView - a system view that displays Project Tree.
virtual CRef< objects::CScope > GetSearchScope()
virtual string GetIconAlias() const
returns an icon alias that can be used to retrieve the client's icon
virtual CFingerprint GetFingerprint() const
returns a fingerprint identifying the client
virtual void SetSelectionService(ISelectionService *service)
virtual void LoadSettings()
virtual void UpdateMenu(wxMenu &root_menu)
IWorkbench * m_Workbench
virtual void GetMainObject(TConstScopedObjects &objects) const
Adds the main data objects represented by the client to "objects".
virtual void DestroyViewWindow()
destroy Window corresponding to the view
virtual void GetMultiple(TConstScopedObjects &pObjects)
virtual wxWindow * GetWindow()
returns a pointer to the wxWindow representing the client
virtual void CreateViewWindow(wxWindow *parent)
create Window corresponding to the view
virtual CRef< objects::CSeq_loc > GetSearchLoc()
virtual const wxMenu * GetMenu()
returns a menu (must be deleted by the caller) menu injections should follow a separator named "Contr...
virtual void SaveSettings() const
void GetSingleObject(TConstScopedObjects &objects) const
CProjectTreePanel * m_Panel
virtual void SetRegistryPath(const string &path)
virtual string GetDMContextName()
returns Name of the context to be used in UI
virtual const CRgbaColor * GetColor() const
returns a color associated with the client, n/a if NULL
void OnWidgetSelChanged(CEvent *evt)
ISelectionClient //////////////////////////////////////////////////////////.
ISelectionService * m_SelectionService
virtual string GetSelClientLabel()
returns a string identifying the client in UI
void GetSelectedItems(PT::TItems &items)
END of ISelectionClient ///////////////////////////////////////////////////.
static CViewTypeDescriptor m_TypeDescr
CProjectTreeView.
virtual void GetSelection(TConstScopedObjects &objects) const
shall return data objects representing selected things, return one data object for every selected thi...
virtual void SetColor(const CRgbaColor &color)
returns a color associated with the client
virtual void SetWorkbench(IWorkbench *workbench)
connect / disconnect this view with / from Workbench
virtual string GetClientLabel(IWMClient::ELabel ltype) const
returns the client label (name) to be displayed in UI
virtual void SetSelection(CSelectionEvent &evt)
set broadcasted selection
virtual const CViewTypeDescriptor & GetTypeDescriptor() const
return an object providing meta information about thei view type
CRef –.
Definition: ncbiobj.hpp:618
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
CSelectionEvent CSelectionEvent is used for broadcasting selection between views.
Definition: obj_event.hpp:68
@ eWidgetSelectionChanged
a view has been destroyed
Definition: view_event.hpp:55
CViewTypeDescriptor - holds description of a view type.
Definition: view.hpp:98
ISelectionService - an interface.
virtual void OnSelectionChanged(ISelectionClient *source)=0
notifies Service and its observers about changes in selection
IView - represents a standard visual part of Workbench UI.
Definition: view.hpp:73
CFingerprint identifies an instance of IWMClient and is used for labeling layout positions.
Definition: wm_client.hpp:58
ELabel
Different flavors of label types for different GUI aspects.
Definition: wm_client.hpp:80
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
Definition: map.hpp:338
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define NULL
Definition: ncbistd.hpp:225
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 void RemoveListener(CEventHandler *listener)
Remove a listener.
const TEventID GetID(void) const
Inline Implementation.
Definition: event.hpp:164
CRef< objects::CScope > scope
Definition: objects.hpp:53
virtual const string & GetIconAlias() const
Definition: ui_object.cpp:130
#define END_EVENT_MAP()
Ends definition of Command Map.
CConstRef< CObject > object
Definition: objects.hpp:52
#define BEGIN_EVENT_MAP(thisClass, baseClass)
Begins definition of Command Map for CEventHandler-derived class.
virtual void AddListener(CEventHandler *listener, int pool_name=ePool_Default)
Add a listener.
virtual const string & GetLabel() const
Definition: ui_object.cpp:124
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Optimized implementation of CSerialObject::Assign, which is not so efficient.
Definition: Seq_id.cpp:318
string GetLabel(const CSeq_id &id)
void SetWhole(TWhole &v)
Definition: Seq_loc.hpp:982
TObjectType * GetPointer(void) const THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:1684
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:1439
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
n background color
CProject * GetProject(wxTreeCtrl &treeCtrl, const CItem &item)
Definition: pt_utils.cpp:77
bool sm_HideDisabledItems
Definition: pt_utils.cpp:57
@ eProject
Definition: pt_item.hpp:118
@ eProjectItem
Definition: pt_item.hpp:120
vector< CItem * > TItems
Definition: pt_item.hpp:113
USING_SCOPE(objects)
static CExtensionPointDeclaration point1(EXT_POINT__PROJECT_TREE_VIEW__CONTEXT_MENU__ITEM_CMD_CONTRIBUTOR, "Project View - commands applicable to Explorer Items")
ON_EVENT(CEvent, CViewEvent::eWidgetSelectionChanged, &CProjectTreeView::OnWidgetSelChanged) CProjectTreeView
static CExtensionDeclaration decl1("view_manager_service::view_factory", new CProjectTreeViewFactory())
register the factory in the Extention Point
#define EXT_POINT__PROJECT_TREE_VIEW__CONTEXT_MENU__ITEM_CMD_CONTRIBUTOR
This Extension Point allows external components to add commands to the top part of Project Tree conte...
static static static wxID_ANY
#define _ASSERT
Modified on Fri Sep 20 14:58:05 2024 by modify_doxy.py rev. 669887