Mantid
Loading...
Searching...
No Matches
ADSAdapter.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
10
11using namespace Mantid::API;
12using namespace MantidQt::MantidWidgets;
13
15
17 : m_addObserver(*this, &ADSAdapter::handleAddWorkspace),
18 m_replaceObserver(*this, &ADSAdapter::handleReplaceWorkspace),
19 m_deleteObserver(*this, &ADSAdapter::handleDeleteWorkspace),
20 m_clearADSObserver(*this, &ADSAdapter::handleClearADS),
21 m_renameObserver(*this, &ADSAdapter::handleRenameWorkspace),
22 m_groupworkspacesObserver(*this, &ADSAdapter::handleGroupWorkspaces),
23 m_ungroupworkspaceObserver(*this, &ADSAdapter::handleUnGroupWorkspace),
24 m_workspaceGroupUpdateObserver(*this, &ADSAdapter::handleWorkspaceGroupUpdate) {
25 // Register all observers.
26 auto &nc = AnalysisDataService::Instance().notificationCenter;
27 nc.addObserver(m_addObserver);
28 nc.addObserver(m_replaceObserver);
29 nc.addObserver(m_deleteObserver);
30 nc.addObserver(m_clearADSObserver);
31 nc.addObserver(m_renameObserver);
32 nc.addObserver(m_groupworkspacesObserver);
33 nc.addObserver(m_ungroupworkspaceObserver);
34 nc.addObserver(m_workspaceGroupUpdateObserver);
35}
36
38 // remove all observers
39 auto &nc = AnalysisDataService::Instance().notificationCenter;
40 nc.removeObserver(m_addObserver);
41 nc.removeObserver(m_replaceObserver);
42 nc.removeObserver(m_deleteObserver);
43 nc.removeObserver(m_clearADSObserver);
44 nc.removeObserver(m_renameObserver);
45 nc.removeObserver(m_groupworkspacesObserver);
46 nc.removeObserver(m_ungroupworkspaceObserver);
47 nc.removeObserver(m_workspaceGroupUpdateObserver);
48}
49
50void ADSAdapter::registerPresenter(Presenter_wptr presenter) { m_presenter = std::move(presenter); }
51
52bool ADSAdapter::doesWorkspaceExist(const std::string &wsname) const {
53 return AnalysisDataService::Instance().doesExist(wsname);
54}
55
56std::map<std::string, Mantid::API::Workspace_sptr> ADSAdapter::topLevelItems() const {
57 return AnalysisDataService::Instance().topLevelItems();
58}
59
62 auto psptr = m_presenter.lock();
63
64 if (psptr == nullptr)
65 throw std::runtime_error("Unable to obtain reference to presenter");
66
67 return psptr;
68}
69
70std::string ADSAdapter::getOldName() const { return m_oldName; }
71std::string ADSAdapter::getNewName() const { return m_newName; }
72
73// ADS Observation methods
75 auto presenter = lockPresenter();
76 presenter->notifyFromWorkspaceProvider(WorkspaceProviderNotifiable::Flag::WorkspaceLoaded);
77}
78
80 auto presenter = lockPresenter();
81 presenter->notifyFromWorkspaceProvider(WorkspaceProviderNotifiable::Flag::GenericUpdateNotification);
82}
83
85 auto presenter = lockPresenter();
86 presenter->notifyFromWorkspaceProvider(WorkspaceProviderNotifiable::Flag::WorkspaceDeleted);
87}
88
90 auto presenter = lockPresenter();
91 presenter->notifyFromWorkspaceProvider(WorkspaceProviderNotifiable::Flag::WorkspacesCleared);
92}
93
95 // store old and new names when workspace rename occurs.
96 m_oldName = pNf->objectName();
97 m_newName = pNf->newObjectName();
98 auto presenter = lockPresenter();
99 presenter->notifyFromWorkspaceProvider(WorkspaceProviderNotifiable::Flag::WorkspaceRenamed);
100}
101
103 auto presenter = lockPresenter();
104 presenter->notifyFromWorkspaceProvider(WorkspaceProviderNotifiable::Flag::WorkspacesGrouped);
105}
106
108 auto presenter = lockPresenter();
109 presenter->notifyFromWorkspaceProvider(WorkspaceProviderNotifiable::Flag::WorkspacesUngrouped);
110}
111
113 auto presenter = lockPresenter();
114 presenter->notifyFromWorkspaceProvider(WorkspaceProviderNotifiable::Flag::WorkspaceGroupUpdated);
115}
116
117} // namespace MantidQt::MantidWidgets
void handleUnGroupWorkspace(Mantid::API::WorkspaceUnGroupingNotification_ptr pNf)
Definition: ADSAdapter.cpp:107
void handleWorkspaceGroupUpdate(Mantid::API::GroupUpdatedNotification_ptr pNf)
Definition: ADSAdapter.cpp:112
bool doesWorkspaceExist(const std::string &wsname) const override
Definition: ADSAdapter.cpp:52
void handleReplaceWorkspace(Mantid::API::WorkspaceAfterReplaceNotification_ptr pNf)
Definition: ADSAdapter.cpp:79
void handleAddWorkspace(Mantid::API::WorkspaceAddNotification_ptr pNf)
Definition: ADSAdapter.cpp:74
std::string getOldName() const override
Definition: ADSAdapter.cpp:70
Poco::NObserver< ADSAdapter, Mantid::API::GroupUpdatedNotification > m_workspaceGroupUpdateObserver
Definition: ADSAdapter.h:65
Presenter_sptr lockPresenter()
Locks the presenter as shared_ptr for use internally.
Definition: ADSAdapter.cpp:61
Poco::NObserver< ADSAdapter, Mantid::API::WorkspacePostDeleteNotification > m_deleteObserver
Definition: ADSAdapter.h:50
void handleClearADS(Mantid::API::ClearADSNotification_ptr pNf)
Definition: ADSAdapter.cpp:89
Poco::NObserver< ADSAdapter, Mantid::API::WorkspacesGroupedNotification > m_groupworkspacesObserver
Definition: ADSAdapter.h:59
void handleRenameWorkspace(Mantid::API::WorkspaceRenameNotification_ptr pNf)
Definition: ADSAdapter.cpp:94
Poco::NObserver< ADSAdapter, Mantid::API::WorkspaceUnGroupingNotification > m_ungroupworkspaceObserver
Definition: ADSAdapter.h:62
void handleDeleteWorkspace(Mantid::API::WorkspacePostDeleteNotification_ptr pNf)
Definition: ADSAdapter.cpp:84
Poco::NObserver< ADSAdapter, Mantid::API::WorkspaceRenameNotification > m_renameObserver
Definition: ADSAdapter.h:56
Poco::NObserver< ADSAdapter, Mantid::API::WorkspaceAfterReplaceNotification > m_replaceObserver
Definition: ADSAdapter.h:47
Poco::NObserver< ADSAdapter, Mantid::API::ClearADSNotification > m_clearADSObserver
Definition: ADSAdapter.h:53
std::map< std::string, Mantid::API::Workspace_sptr > topLevelItems() const override
Definition: ADSAdapter.cpp:56
void handleGroupWorkspaces(Mantid::API::WorkspacesGroupedNotification_ptr pNf)
Definition: ADSAdapter.cpp:102
void registerPresenter(Presenter_wptr presenter) override
Definition: ADSAdapter.cpp:50
Poco::NObserver< ADSAdapter, Mantid::API::WorkspaceAddNotification > m_addObserver
Definition: ADSAdapter.h:44
std::string getNewName() const override
Definition: ADSAdapter.cpp:71
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< WorkspaceProviderNotifiable > Presenter_sptr
std::weak_ptr< WorkspaceProviderNotifiable > Presenter_wptr
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::AfterReplaceNotification > & WorkspaceAfterReplaceNotification_ptr
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::ClearNotification > & ClearADSNotification_ptr
const Poco::AutoPtr< AnalysisDataServiceImpl::GroupUpdatedNotification > & GroupUpdatedNotification_ptr
const Poco::AutoPtr< AnalysisDataServiceImpl::GroupWorkspacesNotification > & WorkspacesGroupedNotification_ptr
const Poco::AutoPtr< AnalysisDataServiceImpl::UnGroupingWorkspaceNotification > & WorkspaceUnGroupingNotification_ptr
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::RenameNotification > & WorkspaceRenameNotification_ptr
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::AddNotification > & WorkspaceAddNotification_ptr
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::PostDeleteNotification > & WorkspacePostDeleteNotification_ptr