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

Go to the SVN repository for this file.

1 /* $Id: simple_project_view.cpp 38781 2017-06-16 16:43:17Z 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 
40 
42 
45 
46 #include <wx/msgdlg.h>
47 #include <wx/dialog.h>
48 
51 
53  FWindowFactory widgetFactory,
54  IServiceLocator* serviceLocator,
56  ISimpleProjectViewCmdHandler* cmdHandler,
57  bool bFloat)
58 {
59  CIRef<IProjectView> view(new CSimpleProjectView(viewName, widgetFactory, cmdHandler));
60  if (objects.size() == 1) {
61  const CSerialObject* so = dynamic_cast<const CSerialObject*>(objects[0].object.GetPointerOrNull());
62  if (so) {
63  string fp = viewName + ":" + so->GetThisTypeInfo()->GetName();
64  dynamic_cast<IWMClient&>(*view).SetFingerprint(fp);
65  }
66  }
67 
68 
69  IViewManagerService* view_srv = serviceLocator->GetServiceByType<IViewManagerService>();
70  _ASSERT(view_srv);
71  view_srv->AddToWorkbench(*view, bFloat);
72 
73  if (!view->InitView(objects, 0)) {
74  view_srv->RemoveFromWorkbench(*view);
75  view.Reset();
76  return view;
77  }
78 
79  CIRef<CProjectService> prj_srv = serviceLocator->GetServiceByType<CProjectService>();
80  prj_srv->OnViewAttached(view);
81 
82  CProjectViewBase* prj_view_base = dynamic_cast<CProjectViewBase*>(view.GetPointer());
83  if (prj_view_base)
84  prj_view_base->RefreshViewWindow();
85 
86  return view;
87 }
88 
90  FWindowFactory widgetFactory,
91  ISimpleProjectViewCmdHandler* cmdHandler)
92  : m_ViewDescr(
93  viewName,
94  "simple_project_view",
96  "Generic",
97  false,
98  "SerialObject",
100  m_WidgetFactory(widgetFactory),
101  m_Widget(),
102  m_CmdHandler(cmdHandler)
103 {
104 }
105 
107 {
108  // get default top level seq-entry
109  CSeq_entry_Handle seh;
110  CScope& scope = *x_GetScope();
111  CScope::TTSE_Handles handles;
112  scope.GetAllTSEs(handles);
113  if (handles.size() > 0) {
114  seh = handles.front().GetTopLevelEntry();
115  }
116 
117  if (!seh) return;
118 
119  // look for the Text View having this main object
121  CIRef<IProjectView> pTextView(prjSrv.FindView(entry.GetObject(), "Text View"));
122  if (pTextView) {
123  prjSrv.ActivateProjectView(pTextView);
124  }
125  else {
126  // for Text View whose main object is not a seq-entry
127  // look for one within the scope, and activate it if there is only one
128  vector<CIRef<IProjectView>> views;
129  prjSrv.FindViews(views);
130  auto count = 0;
131  ITERATE(vector<CIRef<IProjectView> >, it, views) {
132  CIRef<IProjectView> view = *it;
133  if (&*view->GetScope() == &scope
134  && view->GetLabel(IProjectView::eType) == "Text View") {
135  pTextView = view;
136  count++;
137  }
138  }
139  if (pTextView && count == 1) {
140  prjSrv.ActivateProjectView(pTextView);
141  }
142  }
143 
144 }
145 
146 /// IGuiWidgetHost implementation
147 
149 {
151  if (prjSrv) {
152  x_ActivateTextView(*prjSrv);
153  prjSrv->RemoveProjectView(*this);
154  }
155 }
156 
158 {
160  Send(&evt, ePool_Parent);
161 }
162 
164 {
165  if (dynamic_cast<wxDialog*>(m_Widget) == 0) return;
166 
168  CWindowManager* windowManager = srv ? srv->GetWindowManager() : 0;
169  if (windowManager) {
170  windowManager->OnFocusChanged(m_Widget);
171  }
172 }
173 
175 {
176  if (m_CmdHandler)
178 }
179 
180 void CSimpleProjectView::ShowView(const string& viewName, FWindowFactory widgetFactory, TConstScopedObjects& objects, bool bFloat)
181 {
182  if (objects.empty()) return;
184  prjSrv->ShowView(viewName, widgetFactory, objects, bFloat);
185 }
186 
187 /// IWMClient implementation
188 
190 {
191  _ASSERT(m_Widget);
192  return m_Widget;
193 }
194 
196 {
197  return (dynamic_cast<wxDialog*>(m_Widget) != 0);
198 }
199 
200 /// IView implementation
201 
203 {
204  return m_ViewDescr;
205 }
206 
208 {
209  _ASSERT(!m_Widget);
210  m_Widget = m_WidgetFactory(parent);
211  IGuiWidget* guiWidget = dynamic_cast<IGuiWidget*>(m_Widget);
212  if (guiWidget) guiWidget->SetHost(this);
213 }
214 
216 {
217  if (m_Widget) {
218  IGuiWidget* guiWidget = dynamic_cast<IGuiWidget*>(m_Widget);
219  if (guiWidget) {
220  guiWidget->SetHost(0);
221  guiWidget->SetClosing();
222  }
223  m_Widget->Destroy();
224  m_Widget = 0;
225  }
226 }
227 
228 /// IProjectView implementation
229 
230 bool CSimpleProjectView::InitView(TConstScopedObjects& objects, const objects::CUser_object* /*params*/)
231 {
232  IGuiWidget* guiWidget = dynamic_cast<IGuiWidget*>(m_Widget);
233  if (!guiWidget) {
234  string view_name = m_ViewDescr.GetLabel();
235  wxMessageBox(ToWxString(view_name + ": widget not created."), wxT("Simple view error"), wxOK | wxICON_EXCLAMATION);
236  return false;
237  }
238 
239  if (objects.empty() || !guiWidget->InitWidget(objects)) {
241  return false;
242  }
243 
244  CScope* scope = objects.front().scope.GetPointer();
245 
247  _ASSERT(srv);
248 
249  CRef<CGBWorkspace> ws = srv->GetGBWorkspace();
250  if (!ws) return false;
251 
252  CGBDocument* doc = dynamic_cast<CGBDocument*>(ws->GetProjectFromScope(*scope));
253  _ASSERT(doc);
254  if (!doc) return false;
255 
256  guiWidget->SetUndoManager(&doc->GetUndoManager());
257 
258  x_AttachToProject(*doc);
260 
262 
263  return true;
264 }
265 
267 {
268  IGuiWidget* guiWidget = dynamic_cast<IGuiWidget*>(m_Widget);
269  if (!guiWidget) return;
270 
272  guiWidget->DataChanging();
273  }
274  else if (evt.GetSubtype() == CProjectViewEvent::eData ||
276  guiWidget->DataChanged();
277  }
278 }
279 
280 /// ISelectionClient Implementation
281 
283 {
284  IGuiWidget* guiWidget = dynamic_cast<IGuiWidget*>(m_Widget);
285  if (!guiWidget) return;
286 
287  if (!x_HasProject()) return;
288 
290  guiWidget->GetSelectedObjects(objects);
292 }
293 
295 {
296  IGuiWidget* guiWidget = dynamic_cast<IGuiWidget*>(m_Widget);
297  if (!guiWidget) return;
298 
299  if (!x_HasProject()) return;
300 
301  CScope* scope = x_GetScope();
303  guiWidget->GetSelectedObjects(objects);
305  objs.push_back(SConstScopedObject(*it, scope));
306 }
307 
309 {
310  IGuiWidget* guiWidget = dynamic_cast<IGuiWidget*>(m_Widget);
311  if (!guiWidget) return;
312 
313  vector<TConstScopedObjects> widgetObjects;
314  guiWidget->GetActiveObjects(widgetObjects);
315  if (!widgetObjects.empty() && !widgetObjects.back().empty())
316  objs.insert(objs.end(), widgetObjects.back().begin(), widgetObjects.back().end());
317 }
318 
320 {
321  IGuiWidget* guiWidget = dynamic_cast<IGuiWidget*>(m_Widget);
322  if (!guiWidget) return;
323 
324  vector<TConstScopedObjects> widgetObjects;
325  guiWidget->GetActiveObjects(widgetObjects);
326  ITERATE(vector<TConstScopedObjects>, it, widgetObjects)
327  objects.insert(objects.end(), it->begin(), it->end());
328 }
329 
330 void CSimpleProjectView::GetActiveObjects(vector<TConstScopedObjects>& objects)
331 {
332  IGuiWidget* guiWidget = dynamic_cast<IGuiWidget*>(m_Widget);
333  if (!guiWidget) return;
334 
335  guiWidget->GetActiveObjects(objects);
336 }
337 
338 /// CProjectViewBase overridables
339 
341 {
342  IGuiWidget* guiWidget = dynamic_cast<IGuiWidget*>(m_Widget);
343  return guiWidget ? guiWidget->GetOrigObject() : 0;
344 }
345 
346 
348 {
349  IGuiWidget* guiWidget = dynamic_cast<IGuiWidget*>(m_Widget);
350  if (!guiWidget) return;
351 
352  if (!x_HasProject()) return;
353 
354  TConstObjects objs;
355  evt.GetAllObjects(objs);
356  evt.GetOther(objs);
357  guiWidget->SetSelectedObjects(objs);
358 }
359 
CEvent - generic event implementation TODO TODO - Attachments.
Definition: event.hpp:86
CGBDocument.
Definition: document.hpp:113
CUndoManager & GetUndoManager()
Definition: document.hpp:158
CObject –.
Definition: ncbiobj.hpp:180
CProjectService - a service providing API for operations with Workspaces and Projects.
void ActivateProjectView(IProjectView *projectView)
IProjectView * FindView(const CObject &mainObject, const string &viewType)
void RemoveProjectView(IProjectView &view)
removes the view from View manager Service and disconnects it from the project
void FindViews(vector< CIRef< IProjectView > > &projectViews, const CObject &mainObject)
CProjectViewBase - default implementation of IProjectView, the base class for CProjectView and CProje...
virtual void x_ReportInvalidInputData(TConstScopedObjects &objects)
use this function to report incompatible data in InitView()
virtual void OnProjectChanged()
virtual void x_UpdateContentLabel()
virtual string GetClientLabel(IWMClient::ELabel ltype=IWMClient::eDefault) const
returns the client label (name) to be displayed in UI
virtual objects::CScope * x_GetScope() const
virtual void x_AttachToProject(CGBDocument &doc)
virtual void RefreshViewWindow()
virtual bool x_HasProject() const
CProjectViewEvent.
Definition: document.hpp:62
EEventSubtype GetSubtype() const
Definition: document.hpp:96
CRef –.
Definition: ncbiobj.hpp:618
CScope –.
Definition: scope.hpp:92
CSelectionEvent CSelectionEvent is used for broadcasting selection between views.
Definition: obj_event.hpp:68
void GetAllObjects(TConstObjects &objs) const
Definition: obj_event.cpp:314
void GetOther(TConstObjects &objs) const
Definition: obj_event.cpp:338
bool AddObjectSelection(const CObject &obj)
Definition: obj_event.cpp:177
CSeq_entry_Handle –.
Base class for all serializable objects.
Definition: serialbase.hpp:150
FWindowFactory m_WidgetFactory
virtual void OnWidgetCommand(const string &command)
void x_ActivateTextView(CProjectService &prjSrv)
virtual void CloseWidget()
IGuiWidgetHost implementation.
CIRef< ISimpleProjectViewCmdHandler > m_CmdHandler
virtual void CreateViewWindow(wxWindow *parent)
create Window corresponding to the view
virtual bool InitView(TConstScopedObjects &objects, const objects::CUser_object *params)
IProjectView implementation.
CSimpleProjectView(const string &viewName, FWindowFactory widgetFactory, ISimpleProjectViewCmdHandler *cmdHandler)
virtual void WidgetActivated()
static CIRef< IProjectView > CreateView(const string &viewName, FWindowFactory widgetFactory, IServiceLocator *serviceLocator, TConstScopedObjects &objects, ISimpleProjectViewCmdHandler *cmdHandler=0, bool bFloat=false)
virtual void DestroyViewWindow()
destroy Window corresponding to the view
virtual void GetSelection(CSelectionEvent &evt) const
ISelectionClient Implementation.
virtual void WidgetSelectionChanged()
virtual void GetActiveObjects(TConstScopedObjects &objects) const
virtual void GetMainObject(TConstScopedObjects &objs) const
Adds the main data objects represented by the client to "objects".
virtual wxWindow * GetWindow()
IWMClient implementation.
virtual void ShowView(const string &viewName, FWindowFactory widgetFactory, TConstScopedObjects &objects, bool bFloat)
CProjectViewTypeDescriptor m_ViewDescr
virtual const CViewTypeDescriptor & GetTypeDescriptor() const
IView implementation.
virtual bool IsADialog() const
returns true if client is a non-modal dioalog
@ eWidgetSelectionChanged
a view has been destroyed
Definition: view_event.hpp:55
CViewTypeDescriptor - holds description of a view type.
Definition: view.hpp:98
CWindowManager - component controlling windowing of client windows.
virtual void SetClosing()
Definition: gui_widget.hpp:69
virtual void DataChanging()
Definition: gui_widget.hpp:77
virtual void SetUndoManager(ICommandProccessor *cmdProccessor)=0
virtual void GetSelectedObjects(TConstObjects &) const
Definition: gui_widget.hpp:72
virtual void SetSelectedObjects(const TConstObjects &)
Definition: gui_widget.hpp:73
virtual void GetActiveObjects(vector< TConstScopedObjects > &objects)=0
virtual void SetWidgetTitle(const wxString &)
Definition: gui_widget.hpp:68
virtual bool InitWidget(TConstScopedObjects &objects)=0
virtual void DataChanged()
Definition: gui_widget.hpp:78
virtual void SetHost(IGuiWidgetHost *host)=0
virtual const CObject * GetOrigObject() const
Definition: gui_widget.hpp:67
IServiceLocator - an abstract mechanism for locating services.
Definition: service.hpp:71
IViewManagerService IViewManagerService manages views in Workbench.
IWClient - abstract Window Manager client.
Definition: wm_client.hpp:50
virtual void SetFingerprint(const string &)
Definition: wm_client.hpp:116
IWindowManagerService Window Manager Service provides access to Window Manager functionality.
static const char fp[]
Definition: des.c:87
#define false
Definition: bool.h:36
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
virtual const CObject * x_GetOrigObject() const
CProjectViewBase overridables.
virtual void x_OnSetSelection(CSelectionEvent &evt)
override in derived classes in order to handle selection broadcast
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 AddToWorkbench(IView &view, bool bFloat=false)=0
adds view to Workbench and connects to the services the view must be already initialized
virtual void RemoveFromWorkbench(IView &view)=0
disconnects view from services and removes from the Workbench
vector< CConstRef< CObject > > TConstObjects
Definition: objects.hpp:64
virtual const string & GetLabel() const
Definition: ui_object.cpp:124
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
virtual bool Send(CEvent *evt, EDispatch disp_how=eDispatch_Default, int pool_name=ePool_Default)
Sends an event synchronously.
@ eEvent_Message
message from one class to another
Definition: event.hpp:99
virtual const CTypeInfo * GetThisTypeInfo(void) const =0
void GetAllTSEs(TTSE_Handles &tses, enum ETSEKind kind=eManualTSEs)
Definition: scope.cpp:295
vector< CSeq_entry_Handle > TTSE_Handles
Definition: scope.hpp:645
CSeq_entry_Handle GetTopLevelEntry(void) const
Get top level Seq-entry handle.
CConstRef< CSeq_entry > GetCompleteSeq_entry(void) const
Complete and get const reference to the seq-entry.
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
TObjectType & GetObject(void) const
Get object.
Definition: ncbiobj.hpp:1697
#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 NcbiEmptyString
Definition: ncbistr.hpp:122
const string & GetName(void) const
Get name of this type.
Definition: typeinfo.cpp:249
wxWindow *(* FWindowFactory)(wxWindow *)
Definition: gui_widget.hpp:45
#define wxT(x)
Definition: muParser.cpp:41
const char * command
@ eAnyObjectsAccepted
USING_SCOPE(objects)
#define _ASSERT
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Tue Apr 23 07:36:57 2024 by modify_doxy.py rev. 669887