Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
berryIntroPart.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 "berryIntroPart.h"
18 
19 #include <berrySafeRunner.h>
20 #include <berryObjects.h>
21 #include <berryIContributor.h>
24 
25 #include "util/berrySafeRunnable.h"
26 #include "internal/berryWorkbenchRegistryConstants.h"
27 
28 namespace berry
29 {
30 
31 class PropChangedRunnable: public SafeRunnable
32 {
33 public:
34 
35  berryObjectMacro(PropChangedRunnable)
36 
37  IPropertyChangeListener::Events::EventType::AbstractDelegate* delegate;
38 
39  PropChangedRunnable(PropertyChangeEvent::Pointer event) :
40  event(event)
41  {
42  }
43 
44  void Run() override
45  {
46  delegate->Execute(event);
47  }
48 
49 private:
50 
52 };
53 
54 QString IntroPart::GetDefaultTitle() const
55 {
56  return "Welcome";
57 }
58 
59 void IntroPart::FirePropertyChange(int propertyId)
60 {
61  ObjectInt::Pointer val(new ObjectInt(propertyId));
62  Object::Pointer source(this);
63 
67  PropChangedRunnable::Pointer runnable(new PropChangedRunnable(event));
68 
69  const ListenerList& listeners =
70  propChangeEvents.propertyChange.GetListeners();
71  for (auto iter = listeners.begin(); iter
72  != listeners.end(); ++iter)
73  {
74  runnable->delegate = *iter;
75  SafeRunner::Run(runnable);
76  }
77 
78 }
79 
81 {
82  return configElement;
83 }
84 
86 {
87  return QIcon();
88 }
89 
91 {
92  this->partSite = site;
93 }
94 
95 void IntroPart::SetTitleImage(const QIcon& titleImage)
96 {
97  //Do not send changes if they are the same
98  if (this->imageDescriptor.cacheKey() == titleImage.cacheKey())
99  {
100  return;
101  }
102  this->imageDescriptor = titleImage;
104 }
105 
106 void IntroPart::SetTitle(const QString& titleLabel)
107 {
108  if (this->titleLabel == titleLabel)
109  return;
110  this->titleLabel = titleLabel;
112 }
113 
115 {
116  propChangeEvents.AddListener(l);
117 }
118 
120 {
121 
122 }
123 
125 {
126  return partSite;
127 }
128 
130 {
131  if (!this->imageDescriptor.isNull())
132  {
133  return this->imageDescriptor;
134  }
135  return GetDefaultImage();
136 }
137 
138 QString IntroPart::GetPartName() const
139 {
140  if (!titleLabel.isEmpty())
141  {
142  return titleLabel;
143  }
144  return GetDefaultTitle();
145 }
146 
148  throw (PartInitException)
149 {
150  SetSite(site);
151 }
152 
154 {
155  propChangeEvents.RemoveListener(l);
156 }
157 
159 {
160  //no-op
161 }
162 
164  const QString& /*propertyName*/, const Object::Pointer& /*data*/)
165 {
166 
167  // Save config element.
168  configElement = cfig;
169 
170  titleLabel = cfig->GetAttribute(WorkbenchRegistryConstants::ATT_LABEL);
171 
172  // Icon.
173  QString strIcon = cfig->GetAttribute(WorkbenchRegistryConstants::ATT_ICON);
174  if (strIcon.isEmpty())
175  {
176  return;
177  }
178 
180  configElement->GetContributor()->GetName(), strIcon);
181 
182 }
183 
184 }
void RemoveListener(IPropertyChangeListener *listener)
DelegateList< AbstractDelegate >::ListType ListenerList
Definition: berryMessage.h:797
itk::SmartPointer< Self > Pointer
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:88
#define berryObjectMacro(...)
Definition: berryMacros.h:37
void SaveState(IMemento::Pointer memento) override
void AddListener(IPropertyChangeListener *listener)
ListenerList GetListeners() const
Definition: berryMessage.h:839
static void Run(ISafeRunnable::Pointer runnable)
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 SetTitleImage(const QIcon &titleImage)