Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
berryIntroPart.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 "berryIntroPart.h"
14 
15 #include <berrySafeRunner.h>
16 #include <berryObjects.h>
17 #include <berryIContributor.h>
20 
21 #include "util/berrySafeRunnable.h"
22 #include "internal/berryWorkbenchRegistryConstants.h"
23 
24 namespace berry
25 {
26 
27 class PropChangedRunnable: public SafeRunnable
28 {
29 public:
30 
31  berryObjectMacro(PropChangedRunnable);
32 
33  IPropertyChangeListener::Events::EventType::AbstractDelegate* delegate;
34 
35  PropChangedRunnable(PropertyChangeEvent::Pointer event) :
36  event(event)
37  {
38  }
39 
40  void Run() override
41  {
42  delegate->Execute(event);
43  }
44 
45 private:
46 
48 };
49 
50 QString IntroPart::GetDefaultTitle() const
51 {
52  return "Welcome";
53 }
54 
55 void IntroPart::FirePropertyChange(int propertyId)
56 {
57  ObjectInt::Pointer val(new ObjectInt(propertyId));
58  Object::Pointer source(this);
59 
62  typedef IPropertyChangeListener::Events::EventType::ListenerList ListenerList;
63  PropChangedRunnable::Pointer runnable(new PropChangedRunnable(event));
64 
65  const ListenerList& listeners =
66  propChangeEvents.propertyChange.GetListeners();
67  for (auto iter = listeners.begin(); iter
68  != listeners.end(); ++iter)
69  {
70  runnable->delegate = *iter;
71  SafeRunner::Run(runnable);
72  }
73 
74 }
75 
77 {
78  return configElement;
79 }
80 
82 {
83  return QIcon();
84 }
85 
87 {
88  this->partSite = site;
89 }
90 
91 void IntroPart::SetTitleImage(const QIcon& titleImage)
92 {
93  //Do not send changes if they are the same
94  if (this->imageDescriptor.cacheKey() == titleImage.cacheKey())
95  {
96  return;
97  }
98  this->imageDescriptor = titleImage;
99  FirePropertyChange(IWorkbenchPartConstants::PROP_TITLE);
100 }
101 
102 void IntroPart::SetTitle(const QString& titleLabel)
103 {
104  if (this->titleLabel == titleLabel)
105  return;
106  this->titleLabel = titleLabel;
107  FirePropertyChange(IWorkbenchPartConstants::PROP_TITLE);
108 }
109 
111 {
112  propChangeEvents.AddListener(l);
113 }
114 
116 {
117 
118 }
119 
121 {
122  return partSite;
123 }
124 
126 {
127  if (!this->imageDescriptor.isNull())
128  {
129  return this->imageDescriptor;
130  }
131  return GetDefaultImage();
132 }
133 
134 QString IntroPart::GetPartName() const
135 {
136  if (!titleLabel.isEmpty())
137  {
138  return titleLabel;
139  }
140  return GetDefaultTitle();
141 }
142 
144 {
145  SetSite(site);
146 }
147 
149 {
150  propChangeEvents.RemoveListener(l);
151 }
152 
154 {
155  //no-op
156 }
157 
159  const QString& /*propertyName*/, const Object::Pointer& /*data*/)
160 {
161 
162  // Save config element.
163  configElement = cfig;
164 
165  titleLabel = cfig->GetAttribute(WorkbenchRegistryConstants::ATT_LABEL);
166 
167  // Icon.
168  QString strIcon = cfig->GetAttribute(WorkbenchRegistryConstants::ATT_ICON);
169  if (strIcon.isEmpty())
170  {
171  return;
172  }
173 
175  configElement->GetContributor()->GetName(), strIcon);
176 
177 }
178 
179 }
void SetTitle(const QString &titleLabel)
IIntroSite::Pointer GetIntroSite() const override
void FirePropertyChange(int propertyId)
static void Run(ISafeRunnable::Pointer code)
void RemovePropertyListener(IPropertyChangeListener *l) override
void AddPropertyListener(IPropertyChangeListener *l) override
IConfigurationElement::Pointer GetConfigurationElement()
void SetSite(IIntroSite::Pointer site)
QIcon GetTitleImage() const override
berry::SmartPointer< Self > Pointer
Definition: berryObject.h:82
#define berryObjectMacro(...)
Definition: berryMacros.h:33
void SaveState(IMemento::Pointer memento) override
void Init(IIntroSite::Pointer site, IMemento::Pointer memento) override
QString GetPartName() const override
void SetInitializationData(const IConfigurationElement::Pointer &cfig, const QString &propertyName, const Object::Pointer &data) override
static QIcon ImageDescriptorFromPlugin(const QString &pluginId, const QString &imageFilePath)
QIcon GetDefaultImage() const
void Run(berry::IWorkbenchPartSite::Pointer workbenchPartSite, mitk::DataStorage::Pointer dataStorage)
void SetTitleImage(const QIcon &titleImage)