Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
berryContributionItemFactory.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 
15 
16 #include <berryIContributionItem.h>
17 #include <berryIWorkbenchWindow.h>
18 
19 #include "internal/berryChangeToPerspectiveMenu.h"
20 #include "internal/berryShowViewMenu.h"
21 #include "internal/berryReopenEditorMenu.h"
22 #include "internal/berrySwitchToWindowMenu.h"
23 
24 namespace berry {
25 
26 ContributionItemFactory::ContributionItemFactory(const QString& contributionItemId)
27  : contributionItemId(contributionItemId)
28 {}
29 
31 {
32  return contributionItemId;
33 }
34 
35 class OpenWindowsFactory : public ContributionItemFactory
36 {
37 public:
38 
39  OpenWindowsFactory()
40  : ContributionItemFactory("openWindows")
41  {}
42 
44  {
45  if (window == nullptr)
46  {
47  throw ctkInvalidArgumentException("window must not be null");
48  }
49  IContributionItem::Pointer item(new SwitchToWindowMenu(window, GetId(), true));
50  return item;
51  }
52 };
53 
54 const QScopedPointer<ContributionItemFactory>
55 ContributionItemFactory::OPEN_WINDOWS(new OpenWindowsFactory());
56 
57 class ViewsShortlistFactory : public ContributionItemFactory
58 {
59 public:
60 
61  ViewsShortlistFactory()
62  : ContributionItemFactory("viewsShortlist")
63  {}
64 
66  {
67  if (window == nullptr)
68  {
69  throw ctkInvalidArgumentException("window must not be null");
70  }
71  IContributionItem::Pointer item(new ShowViewMenu(window, GetId()));
72  return item;
73  }
74 };
75 
76 const QScopedPointer<ContributionItemFactory>
77 ContributionItemFactory::VIEWS_SHORTLIST(new ViewsShortlistFactory());
78 
79 class ReopenEditorsFactory : public ContributionItemFactory
80 {
81 public:
82 
83  ReopenEditorsFactory()
84  : ContributionItemFactory("reopenEditors")
85  {}
86 
88  {
89  if (window == nullptr)
90  {
91  throw ctkInvalidArgumentException("window must not be null");
92  }
93  IContributionItem::Pointer item(new ReopenEditorMenu(window, GetId(), true));
94  return item;
95  }
96 };
97 
98 const QScopedPointer<ContributionItemFactory>
99 ContributionItemFactory::REOPEN_EDITORS(new ReopenEditorsFactory());
100 
101 class PerspectivesShortlistFactory : public ContributionItemFactory
102 {
103 public:
104 
105  PerspectivesShortlistFactory()
106  : ContributionItemFactory("perspectivesShortlist")
107  {}
108 
110  {
111  if (window == nullptr)
112  {
113  throw ctkInvalidArgumentException("window must not be null");
114  }
115  IContributionItem::Pointer item(new ChangeToPerspectiveMenu(window, GetId()));
116  return item;
117  }
118 };
119 
120 const QScopedPointer<ContributionItemFactory>
121 ContributionItemFactory::PERSPECTIVES_SHORTLIST(new PerspectivesShortlistFactory());
122 
123 }
static const QScopedPointer< ContributionItemFactory > REOPEN_EDITORS
static const QScopedPointer< ContributionItemFactory > PERSPECTIVES_SHORTLIST
ContributionItemFactory(const QString &contributionItemId)
static const QScopedPointer< ContributionItemFactory > VIEWS_SHORTLIST
virtual SmartPointer< IContributionItem > Create(IWorkbenchWindow *window)=0
static const QScopedPointer< ContributionItemFactory > OPEN_WINDOWS