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

Go to the SVN repository for this file.

1 /* $Id: table_view.cpp 40262 2018-01-18 20:27:56Z 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  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 #include <gui/core/table_view.hpp>
35 
37 
39 #include <gui/core/document.hpp>
40 
43 
49 
53 
55 
56 #include <wx/app.h>
57 
60 
62  "Generic Table View", // type name
63  "table_view", // icon alias
64  "Create an interactive table representation of data.",
65  "The Generic Table View shows Seq-table object",
66  "TABLE_VIEW", // help ID
67  "Generic", // category
68  false, // not a singleton
69  "Seq-table",
71 );
72 
74  : CProjectView()
75  , m_Window(0)
76 {
77 }
78 
81  &CTableView::x_OnUrlHover)
83  &CTableView::x_QueryStatusChange)
85  &CTableView::x_OnRowDClick)
87 
88 wxWindow* CTableView::GetWindow()
89 {
90  _ASSERT(m_Window);
91  return m_Window;
92 }
93 
95 {
97  _ASSERT(grid);
98  return grid->GetEventHandler();
99 }
100 
101 // override function to suppress Navigation toolbar
103 {
105 }
106 
107 
108 bool CTableView::InitView(TConstScopedObjects& objects, const objects::CUser_object* params)
109 {
111 
113 
114  if (tableData) {
115  CIRef<ITableSelection> tableSelection;
116  if (objects.size() == 1)
117  tableSelection.Reset(CreateObjectInterface<ITableSelection>(objects[0], NULL));
118 
119  CGridWidget* widget = (CGridWidget*)m_Window;
120 
121  if (tableSelection) widget->SetTableSelection(tableSelection);
122 
124  _ASSERT(srv);
125 
126  CRef<CGBWorkspace> ws = srv->GetGBWorkspace();
127  if (!ws) return false;
128 
129  CGBDocument* doc = dynamic_cast<CGBDocument*>(ws->GetProjectFromScope(*objects[0].scope));
130  _ASSERT(doc);
131  if (doc) {
132  widget->Init(*tableData, &doc->GetUndoManager());
133 
134  x_AttachToProject(*doc);
136  return true;
137  }
138  return false;
139  }
140 
141  // cannot represent the data
143  return false;
144 }
145 
147 {
149  //CGridWidget* grid = (CGridWidget*)m_Window;
150  }
151  else if (evt.GetSubtype() == CProjectViewEvent::eData ||
154  grid->Refresh();
155  }
156 }
157 
158 void CTableView::CreateViewWindow(wxWindow* parent)
159 {
160  _ASSERT(!m_Window);
161 
162  CGridWidget* widget = new CGridWidget(parent, wxID_ANY, wxDefaultPosition, wxSize(0, 0), wxBORDER_NONE);
163  m_Window = widget;
164  widget->AddListener(this, ePool_Parent);
165 }
166 
167 
169 {
170  if (m_Window) {
171  m_Window->Reparent(wxTheApp->GetTopWindow()); // prevents double destruction of CQueryParsePanel in AsyncCall
172  m_Window->Destroy();
173  m_Window = 0;
174  }
175 }
176 
177 
179 {
180  return s_TableViewTypeDescr;
181 }
182 
184 {
185  if (m_Window && x_HasProject()) {
187  grid->GetSelection(evt);
188  }
189 }
190 
192 {
193  if (m_Window && x_HasProject()) {
195  grid->SetSelection(evt);
196  }
197 }
198 
200 {
201  if (m_Window && x_HasProject()) {
203  grid->GetSelectedObjects (objs);
204  }
205 }
206 
208 {
209  if (m_Window && x_HasProject()) {
210  /*CGridWidget* grid = (CGridWidget*)m_Window;*/
211 
212  if(m_OrigObjects.size() > 0) {
213  const SConstScopedObject& ScopedObject(m_OrigObjects[0]);
214  const CObject* object = ScopedObject.object.GetPointer();
215  if (object) {
216  CScope* scope(const_cast<CScope*>(ScopedObject.scope.GetPointer()));
217  objs.push_back(SConstScopedObject(object, scope));
218  }
219  }
220  }
221 }
222 
223 
225 {
226  CGridWidgetEvent* gridEvt = dynamic_cast<CGridWidgetEvent*>(evt);
227  if (!gridEvt) return;
228 
230  sb_srv->SetStatusMessage(ToStdString(gridEvt->GetURL()));
231 }
232 
234 {
235  CQueryPanelEvent* queryEvt = dynamic_cast<CQueryPanelEvent*>(evt);
236  if (!queryEvt) return;
237 
239  sb_srv->SetStatusMessage(queryEvt->GetStatus());
240 }
241 
243 {
245  Send(&evt, ePool_Parent);
246 }
247 
248 static const string sTextViewType("Text View");
249 
251 {
252  if(m_OrigObjects.size() > 0) {
253  return m_OrigObjects[0].object.GetPointer();
254  }
255 
256  return NULL;
257 }
258 
260 {
261  CIRef<ITableData> table_data;
262 
263  if (objects.size() == 1) {
264  table_data.Reset(CreateObjectInterface<ITableData>(objects[0], NULL));
265  }
266 
267  return table_data;
268 }
269 
270 void CTableView::SetRegistryPath(const string& reg_path)
271 {
272  IRegSettings* reg_set = dynamic_cast<IRegSettings*>(m_Window);
273  if (reg_set)
274  reg_set->SetRegistryPath(reg_path);
275 }
276 
278 {
279  IRegSettings* reg_set = dynamic_cast<IRegSettings*>(m_Window);
280  if (reg_set)
281  reg_set->LoadSettings();
282 }
283 
284 
286 {
287  IRegSettings* reg_set = dynamic_cast<IRegSettings*>(m_Window);
288  if (reg_set)
289  reg_set->SaveSettings();
290 }
291 
292 
293 
294 ///////////////////////////////////////////////////////////////////////////////
295 /// CTableViewFactory
297 {
298  static string sid("table_view_factory");
299  return sid;
300 }
301 
302 
304 {
305  static string slabel("Table View Factory");
306  return slabel;
307 }
308 
309 
311 {
312  string alias = GetViewTypeDescriptor().GetIconAlias();
313  provider.RegisterFileAlias(ToWxString(alias), wxT("text_view.png"));
314 }
315 
316 
318 {
319  return s_TableViewTypeDescr;
320 }
321 
322 
324 {
325  return new CTableView();
326 }
327 
328 
330 {
331  return NULL;
332 }
333 
334 
336 {
337  bool found_good = false;
338  bool found_bad = false;
339 
340  for( size_t i = 0; i < objects.size(); i++) {
341  if (ObjectHasInterface<ITableData>(objects[i]))
342  found_good = true;
343  else
344  found_bad = true;
345  }
346 
347  if (found_good)
348  return fCanShowSeparated | (found_bad ? fCanShowSome : fCanShowAll);
349 
350  return 0; // can show nothing
351 }
352 
354  "Project Table View", // type name
355  "project_table_view", // icon alias
356  "Create an interactive table representation of data.",
357  "The Project Table View shows Genome Workbench project",
358  "PROJECT_TABLE_VIEW", // help ID
359  "Generic", // category
360  false, // not a singleton
361  "GBProject-ver2",
363 );
364 
365 ///////////////////////////////////////////////////////////////////////////////
366 /// CProjectTableView
368 {
369 public:
371 
372  /// @name IView implementation
373  /// @(
374  virtual const CViewTypeDescriptor& GetTypeDescriptor() const
375  {
377  }
378  /// @}
379 
380  /// @name IProjectView implementation
381  /// @{
382  virtual void OnProjectChanged(CProjectViewEvent& evt);
383  /// @}
384 };
385 
387 {
388  CGridWidget* widget = (CGridWidget*)GetWindow();
389 
390  if (evt.GetSubtype() == CProjectViewEvent::eNone ||
392  widget->Refresh();
393  }
394  else if (evt.GetSubtype() == CProjectViewEvent::eData ||
398 
399  CIRef<ITableData> table_data;
400  if (objects.size() > 0) {
401  table_data.Reset(CreateObjectInterface<ITableData>(objects[0], NULL));
402  }
403  if (!table_data)
404  return;
405 
406  widget->Init(*table_data, x_GetUndoManager());
407  }
408 }
409 
410 /// CProjectTableViewFactory
412 {
413  static string sid("project_table_view_factory");
414  return sid;
415 }
416 
417 
419 {
420  static string slabel("Project Table View Factory");
421  return slabel;
422 }
423 
424 
426 {
427 }
428 
429 
431 {
433 }
434 
435 
437 {
438  return new CProjectTableView();
439 }
440 
441 
442 bool CProjectTableViewFactory::IsCompatibleWith(const CObject& object, objects::CScope& scope)
443 {
444  const type_info& type = typeid(object);
445  if( typeid(CGBProject_ver2) == type) {
446  return true;
447  }
448  return false;
449 }
450 
452 {
453  return NULL;
454 }
455 
456 
458 {
459  bool found_good = false;
460  bool found_bad = false;
461 
462  for( size_t i = 0; i < objects.size(); i++) {
463  if (IsCompatibleWith(*objects[i].object, *objects[i].scope)) {
464  found_good = true;
465  }
466 
467  found_bad = true;
468  }
469 
470  if (found_good)
471  return fCanShowSeparated | (found_bad ? fCanShowSome : fCanShowAll);
472 
473  return 0; // can show nothing
474 }
475 
User-defined methods of the data storage class.
CEvent - generic event implementation TODO TODO - Attachments.
Definition: event.hpp:86
CGBDocument.
Definition: document.hpp:113
CUndoManager & GetUndoManager()
Definition: document.hpp:158
const wxString & GetURL() const
Definition: grid_event.hpp:70
void Init(ITableData &table_data, ICommandProccessor *cmdProccessor)
void SetTableSelection(ITableSelection *tableSelection)
CObject –.
Definition: ncbiobj.hpp:180
CProjectService - a service providing API for operations with Workspaces and Projects.
CProjectTableView.
Definition: table_view.cpp:368
virtual const CViewTypeDescriptor & GetTypeDescriptor() const
return an object providing meta information about thei view type
Definition: table_view.cpp:374
virtual void x_ReportInvalidInputData(TConstScopedObjects &objects)
use this function to report incompatible data in InitView()
virtual void OnProjectChanged()
virtual void x_UpdateContentLabel()
virtual void x_AttachToProject(CGBDocument &doc)
virtual bool x_HasProject() const
CProjectViewEvent.
Definition: document.hpp:62
EEventSubtype GetSubtype() const
Definition: document.hpp:96
CProjectViewTypeDescriptor - holds description of a project view type.
CProjectView.
virtual CUndoManager * x_GetUndoManager()
gets undo manager
const string & GetStatus() const
CRef –.
Definition: ncbiobj.hpp:618
CScope –.
Definition: scope.hpp:92
CSelectionEvent CSelectionEvent is used for broadcasting selection between views.
Definition: obj_event.hpp:68
CTableView.
Definition: table_view.hpp:54
@ eWidgetItemActivated
Definition: view_event.hpp:65
CViewTypeDescriptor - holds description of a view type.
Definition: view.hpp:98
virtual const CViewTypeDescriptor & GetViewTypeDescriptor() const
returns a Descriptor for the View Type supported by the Factory
IRegSettings An interface for objects that save / restore settings using CGuiRegistry.
virtual void SaveSettings() const =0
virtual void LoadSettings()=0
virtual void SetRegistryPath(const string &path)=0
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
virtual void RegisterFileAlias(const wxArtID &anId, const wxArtClient &aClient, const wxSize &aSize, const wxString &aName, long aType=wxBITMAP_TYPE_ANY, int anIndex=-1)
static const struct name_t names[]
static int type
Definition: getdata.c:31
virtual void GetCompatibleToolBars(vector< string > &names)
returns the names of toolbars compatible with this class (toolbars that are relevant and useful in th...
Definition: table_view.cpp:102
virtual const CObject * x_GetOrigObject() const
Definition: table_view.cpp:250
#define NULL
Definition: ncbistd.hpp:225
void x_QueryStatusChange(CEvent *evt)
Definition: table_view.cpp:233
virtual bool InitView(TConstScopedObjects &objects, const objects::CUser_object *params)
initialize view with data, inside this function the view must call CProjectService::AttachView to con...
Definition: table_view.cpp:108
virtual IView * CreateInstanceByFingerprint(const TFingerprint &fingerprint) const
if fingerprint is recognized - creates and returns a new instance
Definition: table_view.cpp:451
virtual IView * CreateInstance() const
creates a view instance
Definition: table_view.cpp:436
virtual int TestInputObjects(TConstScopedObjects &objects)
tests input objects (probably using object conversion, or not) and returns a combination of ETestResu...
Definition: table_view.cpp:457
virtual void SetRegistryPath(const string &reg_path)
Definition: table_view.cpp:270
virtual void GetMainObject(TConstScopedObjects &objs) const
Adds the main data objects represented by the client to "objects".
Definition: table_view.cpp:207
virtual void DestroyViewWindow()
destroy Window corresponding to the view
Definition: table_view.cpp:168
TConstScopedObjects m_OrigObjects
Definition: table_view.hpp:108
virtual CIRef< ITableData > x_CreateTableData(TConstScopedObjects &objects)
Definition: table_view.cpp:259
virtual const CProjectViewTypeDescriptor & GetProjectViewTypeDescriptor() const
returns a Descriptor for the View Type supported by the Factory
Definition: table_view.cpp:317
void x_OnRowDClick(CEvent *evt)
Definition: table_view.cpp:242
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
Definition: table_view.cpp:303
virtual void RegisterIconAliases(wxFileArtProvider &provider)
called by the framework to give Factory a chance to register images used by view
Definition: table_view.cpp:310
virtual const CViewTypeDescriptor & GetTypeDescriptor() const
return an object providing meta information about thei view type
Definition: table_view.cpp:178
virtual void RegisterIconAliases(wxFileArtProvider &provider)
called by the framework to give Factory a chance to register images used by view
Definition: table_view.cpp:425
virtual void LoadSettings()
Definition: table_view.cpp:277
virtual string GetExtensionIdentifier() const
CProjectTableViewFactory.
Definition: table_view.cpp:411
virtual void CreateViewWindow(wxWindow *parent)
create Window corresponding to the view
Definition: table_view.cpp:158
virtual IView * CreateInstanceByFingerprint(const TFingerprint &fingerprint) const
if fingerprint is recognized - creates and returns a new instance
Definition: table_view.cpp:329
void x_OnUrlHover(CEvent *evt)
Definition: table_view.cpp:224
virtual void SaveSettings() const
Definition: table_view.cpp:285
virtual IView * CreateInstance() const
creates a view instance
Definition: table_view.cpp:323
virtual wxWindow * GetWindow()
returns a pointer to the wxWindow representing the client
virtual void x_OnSetSelection(CSelectionEvent &evt)
override in derived classes in order to handle selection broadcast
Definition: table_view.cpp:191
virtual wxEvtHandler * GetCommandHandler()
IWMClient implementation.
Definition: table_view.cpp:94
virtual const CProjectViewTypeDescriptor & GetProjectViewTypeDescriptor() const
returns a Descriptor for the View Type supported by the Factory
Definition: table_view.cpp:430
virtual bool IsCompatibleWith(const CObject &object, objects::CScope &scope)
Definition: table_view.cpp:442
virtual int TestInputObjects(TConstScopedObjects &objects)
tests input objects (probably using object conversion, or not) and returns a combination of ETestResu...
Definition: table_view.cpp:335
virtual void GetSelection(CSelectionEvent &evt) const
get selection for broadcasting
Definition: table_view.cpp:183
wxWindow * m_Window
Definition: table_view.hpp:110
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
Definition: table_view.cpp:418
virtual string GetExtensionIdentifier() const
CTableViewFactory.
Definition: table_view.cpp:296
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
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.
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
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: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
int i
#define wxT(x)
Definition: muParser.cpp:41
@ eOneObjectAccepted
static static static wxID_ANY
Definition: type.c:6
USING_SCOPE(objects)
CProjectViewTypeDescriptor s_ProjectTableViewTypeDescr("Project Table View", "project_table_view", "Create an interactive table representation of data.", "The Project Table View shows Genome Workbench project", "PROJECT_TABLE_VIEW", "Generic", false, "GBProject-ver2", eOneObjectAccepted)
CProjectViewTypeDescriptor s_TableViewTypeDescr("Generic Table View", "table_view", "Create an interactive table representation of data.", "The Generic Table View shows Seq-table object", "TABLE_VIEW", "Generic", false, "Seq-table", eOneObjectAccepted)
ON_EVENT(CGridWidgetEvent, CGridWidgetEvent::eUrlHover, &CTableView::x_OnUrlHover) ON_EVENT(CQueryPanelEvent
static const string sTextViewType("Text View")
#define _ASSERT
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Sat May 25 14:16:54 2024 by modify_doxy.py rev. 669887