Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
berryWorkbenchPart.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 BlueBerry Platform
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "berryWorkbenchPart.h"
18 
20 #include <berryIContributor.h>
21 #include <berrySafeRunner.h>
22 #include <util/berrySafeRunnable.h>
23 
24 #include "internal/berryWorkbenchPlugin.h"
25 
26 #include <berryObjectString.h>
27 #include <berryObjects.h>
28 
29 namespace berry
30 {
31 
32 class PropChangedRunnable : public SafeRunnable
33 {
34 public:
35 
36  berryObjectMacro(PropChangedRunnable)
37 
38  IPropertyChangeListener::Events::EventType::AbstractDelegate* delegate;
39 
40  PropChangedRunnable(PropertyChangeEvent::Pointer event)
41  : event(event)
42  {}
43 
44  void Run() override
45  {
46  delegate->Execute(event);
47  }
48 
49 private:
50 
52 };
53 
54 WorkbenchPart::~WorkbenchPart()
55 {
56 }
57 
59 :m_Title(""),
60  m_ToolTip(""),
61  m_PartName(""),
62  m_ContentDescription("")
63 {
64 
65 }
66 
67 void WorkbenchPart::InternalSetContentDescription(
68  const QString& description)
69 {
70  //assert(description != 0)
71 
72  //Do not send changes if they are the same
73  if (this->m_ContentDescription == description)
74  {
75  return;
76  }
77  this->m_ContentDescription = description;
78 
80 }
81 
82 void WorkbenchPart::InternalSetPartName(const QString& partName)
83 {
84  //partName = Util.safeString(partName);
85 
86  //assert(partName != 0);
87 
88  //Do not send changes if they are the same
89  if (this->m_PartName == partName)
90  {
91  return;
92  }
93  this->m_PartName = partName;
94 
96 
97 }
98 
99 // IConfigurationElement* GetConfigurationElement()
100 // {
101 // return m_ConfigElement;
102 // }
103 
104 
105 // protected Image getDefaultImage() {
106 // return PlatformUI.getWorkbench().getSharedImages().getImage(
107 // ISharedImages.IMG_DEF_VIEW);
108 // }
109 
111 {
112  this->CheckSite(site);
113  this->m_PartSite = site;
114 }
115 
117 {
118  // do nothing
119 }
120 
121 void WorkbenchPart::SetTitleImage(const QIcon& titleImage)
122 {
123  //assert(titleImage == 0 || !titleImage.isDisposed());
124  //Do not send changes if they are the same
125  if (this->m_TitleImage.cacheKey() == titleImage.cacheKey())
126  {
127  return;
128  }
129  this->m_TitleImage = titleImage;
131 }
132 
133 void WorkbenchPart::SetTitleToolTip(const QString& toolTip)
134 {
135  //toolTip = Util.safeString(toolTip);
136  //Do not send changes if they are the same
137  if (this->m_ToolTip == toolTip)
138  {
139  return;
140  }
141  this->m_ToolTip = toolTip;
143 }
144 
145 void WorkbenchPart::SetPartName(const QString& partName)
146 {
147 
148  InternalSetPartName(partName);
149 
150  //setDefaultTitle();
151 }
152 
153 void WorkbenchPart::SetContentDescription(const QString& description)
154 {
155  InternalSetContentDescription(description);
156 
157  //setDefaultTitle();
158 }
159 
160 void WorkbenchPart::FirePropertyChanged(const QString& key,
161  const QString& oldValue, const QString& newValue)
162 {
163  ObjectString::Pointer objOldVal(new ObjectString(oldValue));
164  ObjectString::Pointer objNewVal(new ObjectString(newValue));
165  Object::Pointer source(this);
167  new PropertyChangeEvent(source, key, objOldVal, objNewVal));
169  PropChangedRunnable::Pointer runnable(new PropChangedRunnable(event));
170 
171  const ListenerList& listeners =
172  partChangeEvents.propertyChange.GetListeners();
173  for (auto iter = listeners.begin(); iter
174  != listeners.end(); ++iter)
175  {
176  runnable->delegate = *iter;
177  SafeRunner::Run(runnable);
178  }
179 }
180 
182 {
183  ObjectInt::Pointer val(new ObjectInt(propertyId));
184  Object::Pointer source(this);
185 
189  PropChangedRunnable::Pointer runnable(new PropChangedRunnable(event));
190 
191  const ListenerList& listeners =
192  partChangeEvents.propertyChange.GetListeners();
193  for (auto iter = listeners.begin(); iter
194  != listeners.end(); ++iter)
195  {
196  runnable->delegate = *iter;
197  SafeRunner::Run(runnable);
198  }
199 }
200 
202 {
203  partChangeEvents.AddListener(l);
204 }
205 
207 {
208  partChangeEvents.RemoveListener(l);
209 }
210 
211 void WorkbenchPart::SetPartProperty(const QString& key,
212  const QString& value)
213 {
214  QHash<QString, QString>::iterator iter = partProperties.find(key);
215  QString oldValue;
216  if (iter != partProperties.end())
217  oldValue = iter.value();
218 
219  if (value == "")
220  {
221  partProperties.remove(key);
222  }
223  else
224  {
225  partProperties.insert(key, value);
226  }
227  this->FirePropertyChanged(key, oldValue, value);
228 }
229 
230 QString WorkbenchPart::GetPartProperty(const QString& key) const
231 {
232  QHash<QString, QString>::const_iterator itr = partProperties.find(key);
233  if (itr == partProperties.end()) return "";
234 
235  return itr.value();
236 }
237 
238 const QHash<QString, QString> &WorkbenchPart::GetPartProperties() const
239 {
240  return partProperties;
241 }
242 
244 {
245  return this->m_PartSite;
246 }
247 
249 {
250  return this->m_PartName;
251 }
252 
254 {
255  return this->m_ContentDescription;
256 }
257 
259 {
260  return this->m_TitleImage;
261  //return GetDefaultImage();
262 }
263 
265 {
266  return this->m_ToolTip;
267 }
268 
270  const QString& /*propertyName*/, const Object::Pointer& /*data*/)
271 {
272  // Save config element.
273  m_ConfigElement = cfig;
274 
275  // Part name and title.
276  m_PartName = cfig->GetAttribute("name");
277  m_Title = m_PartName;
278 
279  // Icon.
280  QString strIcon = cfig->GetAttribute("icon");
281  if (strIcon.isEmpty())
282  {
283  return;
284  }
285 
287  m_ConfigElement->GetContributor()->GetName(), strIcon);
288 }
289 
290 } // namespace berry
void RemoveListener(IPropertyChangeListener *listener)
DelegateList< AbstractDelegate >::ListType ListenerList
Definition: berryMessage.h:797
itk::SmartPointer< Self > Pointer
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:88
QIcon GetTitleImage() const override
#define berryObjectMacro(...)
Definition: berryMacros.h:37
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)
ListenerList GetListeners() const
Definition: berryMessage.h:839
virtual void SetContentDescription(const QString &description)
void FirePropertyChange(int propertyId)
static void Run(ISafeRunnable::Pointer runnable)
void RemovePropertyListener(IPropertyChangeListener *l) override
QString GetContentDescription() const override
virtual void SetTitleImage(const QIcon &titleImage)
static QIcon ImageDescriptorFromPlugin(const QString &pluginId, const QString &imageFilePath)
QString GetTitleToolTip() const override
QString GetPartProperty(const QString &key) const override
IWorkbenchPartSite::Pointer GetSite() const override