Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
berryWorkbenchPart.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "berryWorkbenchPart.h"
14 
16 #include <berryIContributor.h>
17 #include <berrySafeRunner.h>
18 #include <util/berrySafeRunnable.h>
19 
20 #include "berryWorkbenchPlugin.h"
21 
22 #include <berryObjectString.h>
23 #include <berryObjects.h>
24 
25 namespace berry
26 {
27 
28 class PropChangedRunnable : public SafeRunnable
29 {
30 public:
31 
32  berryObjectMacro(PropChangedRunnable)
33 
34  IPropertyChangeListener::Events::EventType::AbstractDelegate* delegate;
35 
36  PropChangedRunnable(PropertyChangeEvent::Pointer event)
37  : event(event)
38  {}
39 
40  void Run() override
41  {
42  delegate->Execute(event);
43  }
44 
45 private:
46 
48 };
49 
50 WorkbenchPart::~WorkbenchPart()
51 {
52 }
53 
55 :m_Title(""),
56  m_ToolTip(""),
57  m_PartName(""),
58  m_ContentDescription("")
59 {
60 
61 }
62 
63 void WorkbenchPart::InternalSetContentDescription(
64  const QString& description)
65 {
66  //assert(description != 0)
67 
68  //Do not send changes if they are the same
69  if (this->m_ContentDescription == description)
70  {
71  return;
72  }
73  this->m_ContentDescription = description;
74 
76 }
77 
78 void WorkbenchPart::InternalSetPartName(const QString& partName)
79 {
80  //partName = Util.safeString(partName);
81 
82  //assert(partName != 0);
83 
84  //Do not send changes if they are the same
85  if (this->m_PartName == partName)
86  {
87  return;
88  }
89  this->m_PartName = partName;
90 
92 
93 }
94 
95 // IConfigurationElement* GetConfigurationElement()
96 // {
97 // return m_ConfigElement;
98 // }
99 
100 
101 // protected Image getDefaultImage() {
102 // return PlatformUI.getWorkbench().getSharedImages().getImage(
103 // ISharedImages.IMG_DEF_VIEW);
104 // }
105 
107 {
108  this->CheckSite(site);
109  this->m_PartSite = site;
110 }
111 
113 {
114  // do nothing
115 }
116 
117 void WorkbenchPart::SetTitleImage(const QIcon& titleImage)
118 {
119  //assert(titleImage == 0 || !titleImage.isDisposed());
120  //Do not send changes if they are the same
121  if (this->m_TitleImage.cacheKey() == titleImage.cacheKey())
122  {
123  return;
124  }
125  this->m_TitleImage = titleImage;
127 }
128 
129 void WorkbenchPart::SetTitleToolTip(const QString& toolTip)
130 {
131  //toolTip = Util.safeString(toolTip);
132  //Do not send changes if they are the same
133  if (this->m_ToolTip == toolTip)
134  {
135  return;
136  }
137  this->m_ToolTip = toolTip;
139 }
140 
141 void WorkbenchPart::SetPartName(const QString& partName)
142 {
143 
144  InternalSetPartName(partName);
145 
146  //setDefaultTitle();
147 }
148 
149 void WorkbenchPart::SetContentDescription(const QString& description)
150 {
151  InternalSetContentDescription(description);
152 
153  //setDefaultTitle();
154 }
155 
156 void WorkbenchPart::FirePropertyChanged(const QString& key,
157  const QString& oldValue, const QString& newValue)
158 {
159  ObjectString::Pointer objOldVal(new ObjectString(oldValue));
160  ObjectString::Pointer objNewVal(new ObjectString(newValue));
161  Object::Pointer source(this);
163  new PropertyChangeEvent(source, key, objOldVal, objNewVal));
164  typedef IPropertyChangeListener::Events::EventType::ListenerList ListenerList;
165  PropChangedRunnable::Pointer runnable(new PropChangedRunnable(event));
166 
167  const ListenerList& listeners =
168  partChangeEvents.propertyChange.GetListeners();
169  for (auto iter = listeners.begin(); iter
170  != listeners.end(); ++iter)
171  {
172  runnable->delegate = *iter;
173  SafeRunner::Run(runnable);
174  }
175 }
176 
178 {
179  ObjectInt::Pointer val(new ObjectInt(propertyId));
180  Object::Pointer source(this);
181 
184  typedef IPropertyChangeListener::Events::EventType::ListenerList ListenerList;
185  PropChangedRunnable::Pointer runnable(new PropChangedRunnable(event));
186 
187  const ListenerList& listeners =
188  partChangeEvents.propertyChange.GetListeners();
189  for (auto iter = listeners.begin(); iter
190  != listeners.end(); ++iter)
191  {
192  runnable->delegate = *iter;
193  SafeRunner::Run(runnable);
194  }
195 }
196 
198 {
199  partChangeEvents.AddListener(l);
200 }
201 
203 {
204  partChangeEvents.RemoveListener(l);
205 }
206 
207 void WorkbenchPart::SetPartProperty(const QString& key,
208  const QString& value)
209 {
210  QHash<QString, QString>::iterator iter = partProperties.find(key);
211  QString oldValue;
212  if (iter != partProperties.end())
213  oldValue = iter.value();
214 
215  if (value == "")
216  {
217  partProperties.remove(key);
218  }
219  else
220  {
221  partProperties.insert(key, value);
222  }
223  this->FirePropertyChanged(key, oldValue, value);
224 }
225 
226 QString WorkbenchPart::GetPartProperty(const QString& key) const
227 {
228  QHash<QString, QString>::const_iterator itr = partProperties.find(key);
229  if (itr == partProperties.end()) return "";
230 
231  return itr.value();
232 }
233 
234 const QHash<QString, QString> &WorkbenchPart::GetPartProperties() const
235 {
236  return partProperties;
237 }
238 
240 {
241  return this->m_PartSite;
242 }
243 
245 {
246  return this->m_PartName;
247 }
248 
250 {
251  return this->m_ContentDescription;
252 }
253 
255 {
256  return this->m_TitleImage;
257  //return GetDefaultImage();
258 }
259 
261 {
262  return this->m_ToolTip;
263 }
264 
266  const QString& /*propertyName*/, const Object::Pointer& /*data*/)
267 {
268  // Save config element.
269  m_ConfigElement = cfig;
270 
271  // Part name and title.
272  m_PartName = cfig->GetAttribute("name");
273  m_Title = m_PartName;
274 
275  // Icon.
276  QString strIcon = cfig->GetAttribute("icon");
277  if (strIcon.isEmpty())
278  {
279  return;
280  }
281 
283  m_ConfigElement->GetContributor()->GetName(), strIcon);
284 }
285 
286 } // namespace berry
void RemoveListener(IPropertyChangeListener *listener)
static void Run(ISafeRunnable::Pointer code)
virtual void SetPartName(const QString &partName)
void SetInitializationData(const IConfigurationElement::Pointer &cfig, const QString &propertyName, const Object::Pointer &data) override
void SetSite(IWorkbenchPartSite::Pointer site)
void SetPartProperty(const QString &key, const QString &value) override
berry::SmartPointer< Self > Pointer
Definition: berryObject.h:82
QIcon GetTitleImage() const override
#define berryObjectMacro(...)
Definition: berryMacros.h:33
void AddPropertyListener(IPropertyChangeListener *l) override
const QHash< QString, QString > & GetPartProperties() const override
void FirePropertyChanged(const QString &key, const QString &oldValue, const QString &newValue)
virtual void CheckSite(IWorkbenchPartSite::Pointer site)
void AddListener(IPropertyChangeListener *listener)
QString GetPartName() const override
virtual void SetTitleToolTip(const QString &toolTip)
virtual void SetContentDescription(const QString &description)
void FirePropertyChange(int propertyId)
void RemovePropertyListener(IPropertyChangeListener *l) override
QString GetContentDescription() const override
virtual void SetTitleImage(const QIcon &titleImage)
static QIcon ImageDescriptorFromPlugin(const QString &pluginId, const QString &imageFilePath)
void Run(berry::IWorkbenchPartSite::Pointer workbenchPartSite, mitk::DataStorage::Pointer dataStorage)
QString GetTitleToolTip() const override
QString GetPartProperty(const QString &key) const override
IWorkbenchPartSite::Pointer GetSite() const override