Medical Imaging Interaction Toolkit  2018.4.99-c7ee88da
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 
252  IPresentationFactory* GetPresentationFactory();
253 
254 
255 private:
256 
267  template<class C>
268  C* CreateExtension(const QString& extensionPointId, const QString& elementName,
269  const QString& targetID)
270  {
272  ->GetExtensionPoint(PlatformUI::PLUGIN_ID() + "." + extensionPointId);
273  if (extensionPoint == 0)
274  {
275  WorkbenchPlugin::Log("Unable to find extension. Extension point: " +
276  extensionPointId + " not found");
277  return nullptr;
278  }
279 
280  // Loop through the config elements.
281  IConfigurationElement::Pointer targetElement(nullptr);
282  QList<IConfigurationElement::Pointer> elements(
283  Platform::GetExtensionRegistry()->GetConfigurationElementsFor(PlatformUI::PLUGIN_ID() + "." + extensionPointId));
284  for (int j = 0; j < elements.size(); j++)
285  {
286  if (elementName == "" || elementName == elements[j]->GetName())
287  {
288  QString strID = elements[j]->GetAttribute("id");
289  if (targetID == strID)
290  {
291  targetElement = elements[j];
292  break;
293  }
294  }
295  }
296  if (targetElement.IsNull())
297  {
298  // log it since we cannot safely display a dialog.
299  WorkbenchPlugin::Log("Unable to find extension: " + targetID
300  + " in extension point: " + extensionPointId);
301  return nullptr;
302  }
303 
304  // Create the extension.
305  try
306  {
307  return targetElement->CreateExecutableExtension<C>("class");
308  }
309  catch (const CoreException& /*e*/)
310  {
311  // log it since we cannot safely display a dialog.
312  WorkbenchPlugin::Log("Unable to create extension: " + targetID
313  + " in extension point: " + extensionPointId);
314  }
315  return nullptr;
316  }
317 
318 
319 public:
320 
325  IPerspectiveRegistry* GetPerspectiveRegistry();
326 
327 
333  IIntroRegistry* GetIntroRegistry();
334 
335  /*
336  * Get the preference manager.
337  * @return PreferenceManager the preference manager for
338  * the receiver.
339  */
340  //PreferenceManager getPreferenceManager();
341 
347  IViewRegistry* GetViewRegistry();
348 
349 
363  static void Log(const QString &message);
364 
369  static void Log(const ctkException& exc);
370 
371 
385  static void Log(const QString &message, const ctkException& t);
386 
402  static void Log(const QString &clazz, const QString &methodName, const ctkException& t);
403 
416  static void Log(const QString& message, const SmartPointer<IStatus>& status);
417 
422  static void Log(const SmartPointer<IStatus>& status);
423 
424  /*
425  * (non-Javadoc)
426  * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
427  */
428  void start(ctkPluginContext* context) override;
429 
430 
431  /*
432  * Return an array of all bundles contained in this workbench.
433  *
434  * @return an array of bundles in the workbench or an empty array if none
435  */
436  //const QList<IBundle::Pointer> GetBundles();
437 
443  ctkPluginContext* GetPluginContext();
444 
445 
446  /* (non-Javadoc)
447  * @see org.blueberry.ui.plugin.AbstractUICTKPlugin#stop(org.osgi.framework.BundleContext)
448  */
449  void stop(ctkPluginContext* context) override;
450 
451 
464  QString GetDataLocation() const;
465 
466 };
467 
468 }
469 
470 #endif /*BERRYWORKBENCHPLUGIN_H_*/
static void Log(const QString &message)
virtual SmartPointer< IExtensionPoint > GetExtensionPoint(const QString &extensionPointId) const =0
static char PREFERENCE_PAGE_CATEGORY_SEPARATOR
static QString PLUGIN_ID()
static IExtensionRegistry * GetExtensionRegistry()
static std::string GetName(std::string fileName, std::string suffix)
#define BERRY_UI_QT