Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
berryWorkbenchPlugin.h
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 #ifndef BERRYWORKBENCHPLUGIN_H_
14 #define BERRYWORKBENCHPLUGIN_H_
15 
16 #include <Poco/Path.h>
17 
18 #include <berryIExtensionPoint.h>
20 #include <berryPlatform.h>
21 #include <berryCoreException.h>
22 
24 #include "berryPlatformUI.h"
26 
27 
28 #include "internal/berryViewRegistry.h"
29 #include "internal/berryEditorRegistry.h"
30 #include "internal/berryPerspectiveRegistry.h"
31 #include "internal/intro/berryIntroRegistry.h"
32 
33 namespace berry {
34 
35 class QtStyleManager;
36 
57 {
58 
59  Q_OBJECT
60  Q_PLUGIN_METADATA(IID "org_blueberry_ui_qt")
61  Q_INTERFACES(ctkPluginActivator)
62 
63 private:
64 
65  //static const QString UI_BUNDLE_ACTIVATOR = "org.blueberry.ui.internal.UIPlugin"; //$NON-NLS-1$
66 
67  // Default instance of the receiver
68  static WorkbenchPlugin* inst;
69 
70  // The presentation factory
71  IPresentationFactory* presentationFactory;
72 
73  // Manager that maps resources to descriptors of editors to use
74  EditorRegistry* editorRegistry;
75 
76  // The context within which this plugin was started.
77  ctkPluginContext* bundleContext;
78 
79  // Other data.
80  //WorkbenchPreferenceManager preferenceManager;
81 
82  ViewRegistry* viewRegistry;
83 
84  PerspectiveRegistry* perspRegistry;
85 
86  IntroRegistry* introRegistry;
87 
88  //SharedImages sharedImages;
89 
90  QScopedPointer<QtStyleManager> styleManager;
91 
92 
93 public:
94 
99  static bool DEBUG;
100 
105 
106 
113 
114  ~WorkbenchPlugin() override;
115 
116 
117  /*
118  * Creates an extension. If the extension plugin has not
119  * been loaded a busy cursor will be activated during the duration of
120  * the load.
121  *
122  * @param element the config element defining the extension
123  * @param classAttribute the name of the attribute carrying the class
124  * @return the extension object
125  * @throws CoreException if the extension cannot be created
126  */
127 // template<class E>
128 // static E* CreateExtension(IConfigurationElement::ConstPointer element,
129 // const QString& classAttribute) {
130 // try {
131 // // If plugin has been loaded create extension.
132 // // Otherwise, show busy cursor then create extension.
133 // if (BundleUtility.isActivated(element.getDeclaringExtension()
134 // .getNamespace())) {
135 // return element.createExecutableExtension(classAttribute);
136 // }
137 // final Object[] ret = new Object[1];
138 // final CoreException[] exc = new CoreException[1];
139 // BusyIndicator.showWhile(null, new Runnable() {
140 // public void run() {
141 // try {
142 // ret[0] = element
143 // .createExecutableExtension(classAttribute);
144 // } catch (CoreException e) {
145 // exc[0] = e;
146 // }
147 // }
148 // });
149 // if (exc[0] != null) {
150 // throw exc[0];
151 // }
152 // return ret[0];
153 //
154 // } catch (CoreException core) {
155 // throw core;
156 // } catch (Exception e) {
157 // throw new CoreException(new Status(IStatus.ERR, PI_WORKBENCH,
158 // IStatus.ERR, WorkbenchMessages.WorkbenchPlugin_extension,e));
159 // }
160 // }
161 
174  const QString& extensionName);
175 
196  const IConfigurationElement::Pointer& element, const QString& extensionName);
197 
217  const IConfigurationElement::Pointer& element, const QString& extensionName);
218 
219 
226 
227  std::size_t GetBundleCount();
228 
236 
242  IElementFactory* GetElementFactory(const QString& targetID) const;
243 
250 
251 
252 private:
253 
264  template<class C>
265  C* CreateExtension(const QString& extensionPointId, const QString& elementName,
266  const QString& targetID)
267  {
269  ->GetExtensionPoint(PlatformUI::PLUGIN_ID() + "." + extensionPointId);
270  if (extensionPoint == 0)
271  {
272  WorkbenchPlugin::Log("Unable to find extension. Extension point: " +
273  extensionPointId + " not found");
274  return nullptr;
275  }
276 
277  // Loop through the config elements.
278  IConfigurationElement::Pointer targetElement(nullptr);
279  QList<IConfigurationElement::Pointer> elements(
280  Platform::GetExtensionRegistry()->GetConfigurationElementsFor(PlatformUI::PLUGIN_ID() + "." + extensionPointId));
281  for (int j = 0; j < elements.size(); j++)
282  {
283  if (elementName == "" || elementName == elements[j]->GetName())
284  {
285  QString strID = elements[j]->GetAttribute("id");
286  if (targetID == strID)
287  {
288  targetElement = elements[j];
289  break;
290  }
291  }
292  }
293  if (targetElement.IsNull())
294  {
295  // log it since we cannot safely display a dialog.
296  WorkbenchPlugin::Log("Unable to find extension: " + targetID
297  + " in extension point: " + extensionPointId);
298  return nullptr;
299  }
300 
301  // Create the extension.
302  try
303  {
304  return targetElement->CreateExecutableExtension<C>("class");
305  }
306  catch (const CoreException& /*e*/)
307  {
308  // log it since we cannot safely display a dialog.
309  WorkbenchPlugin::Log("Unable to create extension: " + targetID
310  + " in extension point: " + extensionPointId);
311  }
312  return nullptr;
313  }
314 
315 
316 public:
317 
323 
324 
330  IIntroRegistry* GetIntroRegistry();
331 
332  /*
333  * Get the preference manager.
334  * @return PreferenceManager the preference manager for
335  * the receiver.
336  */
337  //PreferenceManager getPreferenceManager();
338 
345 
346 
360  static void Log(const QString &message);
361 
366  static void Log(const ctkException& exc);
367 
368 
382  static void Log(const QString &message, const ctkException& t);
383 
399  static void Log(const QString &clazz, const QString &methodName, const ctkException& t);
400 
413  static void Log(const QString& message, const SmartPointer<IStatus>& status);
414 
419  static void Log(const SmartPointer<IStatus>& status);
420 
421  /*
422  * (non-Javadoc)
423  * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
424  */
425  void start(ctkPluginContext* context) override;
426 
427 
428  /*
429  * Return an array of all bundles contained in this workbench.
430  *
431  * @return an array of bundles in the workbench or an empty array if none
432  */
433  //const QList<IBundle::Pointer> GetBundles();
434 
440  ctkPluginContext* GetPluginContext();
441 
442 
443  /* (non-Javadoc)
444  * @see org.blueberry.ui.plugin.AbstractUICTKPlugin#stop(org.osgi.framework.BundleContext)
445  */
446  void stop(ctkPluginContext* context) override;
447 
448 
461  QString GetDataLocation() const;
462 
463 };
464 
465 }
466 
467 #endif /*BERRYWORKBENCHPLUGIN_H_*/
static QString PLUGIN_ID()
static IExtensionRegistry * GetExtensionRegistry()
Implements transparent reference counting.
static bool HasExecutableExtension(const IConfigurationElement::Pointer &element, const QString &extensionName)
static void Log(const QString &message, const ctkException &t)
static void Log(const ctkException &exc)
IPerspectiveRegistry * GetPerspectiveRegistry()
static char PREFERENCE_PAGE_CATEGORY_SEPARATOR
static void Log(const QString &clazz, const QString &methodName, const ctkException &t)
static void Log(const QString &message, const SmartPointer< IStatus > &status)
static WorkbenchPlugin * GetDefault()
static QSharedPointer< ctkPlugin > GetBundleForExecutableExtension(const IConfigurationElement::Pointer &element, const QString &extensionName)
static bool IsBundleLoadedForExecutableExtension(const IConfigurationElement::Pointer &element, const QString &extensionName)
std::size_t GetBundleCount()
IElementFactory * GetElementFactory(const QString &targetID) const
IEditorRegistry * GetEditorRegistry()
IViewRegistry * GetViewRegistry()
static void Log(const QString &message)
IIntroRegistry * GetIntroRegistry()
~WorkbenchPlugin() override
void stop(ctkPluginContext *context) override
static void Log(const SmartPointer< IStatus > &status)
void start(ctkPluginContext *context) override
IPresentationFactory * GetPresentationFactory()
QString GetDataLocation() const
ctkPluginContext * GetPluginContext()
#define BERRY_UI_QT
virtual SmartPointer< IExtensionPoint > GetExtensionPoint(const QString &extensionPointId) const =0