Medical Imaging Interaction Toolkit  2024.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 
59 {
60 
61  Q_OBJECT
62  Q_PLUGIN_METADATA(IID "org_blueberry_ui_qt")
63  Q_INTERFACES(ctkPluginActivator)
64 
65 private:
66 
67  //static const QString UI_BUNDLE_ACTIVATOR = "org.blueberry.ui.internal.UIPlugin"; //$NON-NLS-1$
68 
69  // Default instance of the receiver
70  static WorkbenchPlugin* inst;
71 
72  // The presentation factory
73  IPresentationFactory* presentationFactory;
74 
75  // Manager that maps resources to descriptors of editors to use
76  EditorRegistry* editorRegistry;
77 
78  // The context within which this plugin was started.
79  ctkPluginContext* bundleContext;
80 
81  // Other data.
82  //WorkbenchPreferenceManager preferenceManager;
83 
84  ViewRegistry* viewRegistry;
85 
86  PerspectiveRegistry* perspRegistry;
87 
88  IntroRegistry* introRegistry;
89 
90  //SharedImages sharedImages;
91 
92  QScopedPointer<QtStyleManager> styleManager;
93 
94 
95 public:
96 
101  static bool DEBUG;
102 
107 
108 
114  WorkbenchPlugin();
115 
116  ~WorkbenchPlugin() override;
117 
118 
119  /*
120  * Creates an extension. If the extension plugin has not
121  * been loaded a busy cursor will be activated during the duration of
122  * the load.
123  *
124  * @param element the config element defining the extension
125  * @param classAttribute the name of the attribute carrying the class
126  * @return the extension object
127  * @throws CoreException if the extension cannot be created
128  */
129 // template<class E>
130 // static E* CreateExtension(IConfigurationElement::ConstPointer element,
131 // const QString& classAttribute) {
132 // try {
133 // // If plugin has been loaded create extension.
134 // // Otherwise, show busy cursor then create extension.
135 // if (BundleUtility.isActivated(element.getDeclaringExtension()
136 // .getNamespace())) {
137 // return element.createExecutableExtension(classAttribute);
138 // }
139 // final Object[] ret = new Object[1];
140 // final CoreException[] exc = new CoreException[1];
141 // BusyIndicator.showWhile(null, new Runnable() {
142 // public void run() {
143 // try {
144 // ret[0] = element
145 // .createExecutableExtension(classAttribute);
146 // } catch (CoreException e) {
147 // exc[0] = e;
148 // }
149 // }
150 // });
151 // if (exc[0] != null) {
152 // throw exc[0];
153 // }
154 // return ret[0];
155 //
156 // } catch (CoreException core) {
157 // throw core;
158 // } catch (Exception e) {
159 // throw new CoreException(new Status(IStatus.ERR, PI_WORKBENCH,
160 // IStatus.ERR, WorkbenchMessages.WorkbenchPlugin_extension,e));
161 // }
162 // }
163 
175  static bool HasExecutableExtension(const IConfigurationElement::Pointer& element,
176  const QString& extensionName);
177 
197  static bool IsBundleLoadedForExecutableExtension(
198  const IConfigurationElement::Pointer& element, const QString& extensionName);
199 
218  static QSharedPointer<ctkPlugin> GetBundleForExecutableExtension(
219  const IConfigurationElement::Pointer& element, const QString& extensionName);
220 
221 
227  static WorkbenchPlugin* GetDefault();
228 
229  std::size_t GetBundleCount();
230 
237  IEditorRegistry* GetEditorRegistry();
238 
244  IElementFactory* GetElementFactory(const QString& targetID) const;
245 
251  IPresentationFactory* GetPresentationFactory();
252 
253 
254 private:
255 
266  template<class C>
267  C* CreateExtension(const QString& extensionPointId, const QString& elementName,
268  const QString& targetID)
269  {
271  ->GetExtensionPoint(PlatformUI::PLUGIN_ID() + "." + extensionPointId);
272  if (extensionPoint == 0)
273  {
274  WorkbenchPlugin::Log("Unable to find extension. Extension point: " +
275  extensionPointId + " not found");
276  return nullptr;
277  }
278 
279  // Loop through the config elements.
280  IConfigurationElement::Pointer targetElement(nullptr);
281  QList<IConfigurationElement::Pointer> elements(
282  Platform::GetExtensionRegistry()->GetConfigurationElementsFor(PlatformUI::PLUGIN_ID() + "." + extensionPointId));
283  for (int j = 0; j < elements.size(); j++)
284  {
285  if (elementName == "" || elementName == elements[j]->GetName())
286  {
287  QString strID = elements[j]->GetAttribute("id");
288  if (targetID == strID)
289  {
290  targetElement = elements[j];
291  break;
292  }
293  }
294  }
295  if (targetElement.IsNull())
296  {
297  // log it since we cannot safely display a dialog.
298  WorkbenchPlugin::Log("Unable to find extension: " + targetID
299  + " in extension point: " + extensionPointId);
300  return nullptr;
301  }
302 
303  // Create the extension.
304  try
305  {
306  return targetElement->CreateExecutableExtension<C>("class");
307  }
308  catch (const CoreException& /*e*/)
309  {
310  // log it since we cannot safely display a dialog.
311  WorkbenchPlugin::Log("Unable to create extension: " + targetID
312  + " in extension point: " + extensionPointId);
313  }
314  return nullptr;
315  }
316 
317 
318 public:
319 
324  IPerspectiveRegistry* GetPerspectiveRegistry();
325 
326 
332  IIntroRegistry* GetIntroRegistry();
333 
334  /*
335  * Get the preference manager.
336  * @return PreferenceManager the preference manager for
337  * the receiver.
338  */
339  //PreferenceManager getPreferenceManager();
340 
346  IViewRegistry* GetViewRegistry();
347 
348 
362  static void Log(const QString &message);
363 
368  static void Log(const ctkException& exc);
369 
370 
384  static void Log(const QString &message, const ctkException& t);
385 
401  static void Log(const QString &clazz, const QString &methodName, const ctkException& t);
402 
415  static void Log(const QString& message, const SmartPointer<IStatus>& status);
416 
421  static void Log(const SmartPointer<IStatus>& status);
422 
423  /*
424  * (non-Javadoc)
425  * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
426  */
427  void start(ctkPluginContext* context) override;
428 
429 
430  /*
431  * Return an array of all bundles contained in this workbench.
432  *
433  * @return an array of bundles in the workbench or an empty array if none
434  */
435  //const QList<IBundle::Pointer> GetBundles();
436 
442  ctkPluginContext* GetPluginContext();
443 
444 
445  /* (non-Javadoc)
446  * @see org.blueberry.ui.plugin.AbstractUICTKPlugin#stop(org.osgi.framework.BundleContext)
447  */
448  void stop(ctkPluginContext* context) override;
449 
450 
463  QString GetDataLocation() const;
464 
465 };
466 
467 }
468 
469 #endif /*BERRYWORKBENCHPLUGIN_H_*/
berry::WorkbenchPlugin::Log
static void Log(const QString &message)
berryIExtensionRegistry.h
berry::WorkbenchPlugin::PREFERENCE_PAGE_CATEGORY_SEPARATOR
static char PREFERENCE_PAGE_CATEGORY_SEPARATOR
Definition: berryWorkbenchPlugin.h:106
berry::IPresentationFactory
Definition: berryIPresentationFactory.h:32
berryCoreException.h
berryAbstractUICTKPlugin.h
berry::IExtensionRegistry::GetExtensionPoint
virtual SmartPointer< IExtensionPoint > GetExtensionPoint(const QString &extensionPointId) const =0
berry::SmartPointer
Implements transparent reference counting.
Definition: berryICommandCategoryListener.h:21
berryPlatform.h
berryIPresentationFactory.h
berry::Platform::GetExtensionRegistry
static IExtensionRegistry * GetExtensionRegistry()
berry::PlatformUI::PLUGIN_ID
static QString PLUGIN_ID()
berry::WorkbenchPlugin::DEBUG
static bool DEBUG
Definition: berryWorkbenchPlugin.h:101
QSharedPointer
Definition: berryILog.h:16
BERRY_UI_QT
#define BERRY_UI_QT
Definition: org_blueberry_ui_qt_Export.h:26
berry::WorkbenchPlugin
Definition: berryWorkbenchPlugin.h:58
berryPlatformUI.h
berryIExtensionPoint.h
berry::IEditorRegistry
Definition: berryIEditorRegistry.h:47
berry::IElementFactory
Definition: berryIElementFactory.h:44
berry
Definition: QmitkPropertyItemModel.h:24
berry::AbstractUICTKPlugin
Definition: berryAbstractUICTKPlugin.h:72