Medical Imaging Interaction Toolkit  2018.4.99-3e3f1a6e
Medical Imaging Interaction Toolkit
QmitkFunctionalityCoordinator.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 
14 #include "QmitkFunctionality.h"
16 #include <berryPlatformUI.h>
17 #include <berryIWorkbenchPage.h>
18 
19 #include <mitkIZombieViewPart.h>
20 
22  : m_StandaloneFuntionality(nullptr)
23 {
24 }
25 
27 {
29  QList<berry::IWorkbenchWindow::Pointer> wnds(berry::PlatformUI::GetWorkbench()->GetWorkbenchWindows());
30  for (auto i = wnds.begin(); i != wnds.end(); ++i)
31  {
32  (*i)->GetPartService()->AddPartListener(this);
33  }
34 }
35 
37 {
39 
41  QList<berry::IWorkbenchWindow::Pointer> wnds(berry::PlatformUI::GetWorkbench()->GetWorkbenchWindows());
42  for (auto i = wnds.begin(); i != wnds.end(); ++i)
43  {
44  (*i)->GetPartService()->RemovePartListener(this);
45  }
46 }
47 
49 {
50 }
51 
52 berry::IPartListener::Events::Types QmitkFunctionalityCoordinator::GetPartEventTypes() const
53 {
57 }
58 
60 {
61  // change the active standalone functionality
63 }
64 
66 {
67  // nothing to do here: see PartActivated()
68 }
69 
71 {
72  // check for multiwidget and inform views that it is available now
73  if ( partRef->GetId() == QmitkStdMultiWidgetEditor::EDITOR_ID )
74  {
75  for (std::set<QmitkFunctionality*>::iterator it = m_Functionalities.begin()
76  ; it != m_Functionalities.end(); it++)
77  {
78  (*it)->MultiWidgetAvailable(*(partRef
79  ->GetPart(false).Cast<QmitkStdMultiWidgetEditor>()->GetMultiWidget()));
80  }
81  }
82  else
83  {
84  // Check for QmitkFunctionality
85  QmitkFunctionality::Pointer _QmitkFunctionality = partRef->GetPart(false).Cast<QmitkFunctionality>();
86  if(_QmitkFunctionality.IsNotNull())
87  {
88  m_Functionalities.insert(_QmitkFunctionality.GetPointer()); // save as opened functionality
89  }
90  }
91 }
92 
94 {
95  // check for multiwidget and inform views that it not available any more
96  if ( partRef->GetId() == QmitkStdMultiWidgetEditor::EDITOR_ID )
97  {
98 
99  QmitkStdMultiWidgetEditor::Pointer stdMultiWidgetEditor = partRef->GetPart(false).Cast<QmitkStdMultiWidgetEditor>();
100  for (std::set<QmitkFunctionality*>::iterator it = m_Functionalities.begin()
101  ; it != m_Functionalities.end(); it++)
102  {
103  (*it)->MultiWidgetClosed(*(stdMultiWidgetEditor->GetMultiWidget()));
104  (*it)->MultiWidgetNotAvailable(); // deprecated call, provided for consistence
105  }
106  }
107  else
108  {
109  // check for functionality
110  QmitkFunctionality::Pointer _QmitkFunctionality = partRef->GetPart(false).Cast<QmitkFunctionality>();
111  if(_QmitkFunctionality.IsNotNull())
112  {
113  // deactivate on close ( the standalone functionality may still be activated )
114  this->DeactivateStandaloneFunctionality(partRef.GetPointer(), nullptr);
115 
116  // and set pointer to 0
117  if(m_StandaloneFuntionality == partRef.GetPointer())
118  m_StandaloneFuntionality = nullptr;
119 
120  m_Functionalities.erase(_QmitkFunctionality.GetPointer()); // remove as opened functionality
121 
122  // call PartClosed on the QmitkFunctionality
123  _QmitkFunctionality->ClosePartProxy();
124  //m_VisibleStandaloneFunctionalities.erase(_QmitkFunctionality.GetPointer()); // remove if necessary (should be done before in PartHidden()
125  }
126  }
127 }
128 
130 {
131  // Check for QmitkFunctionality
132  QmitkFunctionality::Pointer _QmitkFunctionality = partRef->GetPart(false).Cast<QmitkFunctionality>();
133  if(_QmitkFunctionality != 0)
134  {
135  _QmitkFunctionality->SetVisible(false);
136  _QmitkFunctionality->Hidden();
137 
138  // tracking of Visible Standalone Functionalities
140 
141  // activate Functionality if just one Standalone Functionality is visible
142  if( m_VisibleStandaloneFunctionalities.size() == 1 )
144  }
145 }
146 
148 {
149  // Check for QmitkFunctionality
150  QmitkFunctionality::Pointer _QmitkFunctionality = partRef->GetPart(false).Cast<QmitkFunctionality>();
151  if(_QmitkFunctionality.IsNotNull())
152  {
153  _QmitkFunctionality->SetVisible(true);
154  _QmitkFunctionality->Visible();
155 
156  // tracking of Visible Standalone Functionalities
157  if( _QmitkFunctionality->IsExclusiveFunctionality() )
158  {
160 
161  // activate Functionality if just one Standalone Functionality is visible
162  if( m_VisibleStandaloneFunctionalities.size() == 1 )
164  }
165  }
166 }
167 
169 {
170  QmitkFunctionality* functionality = dynamic_cast<QmitkFunctionality*>(partRef->GetPart(false).GetPointer());
171  if( functionality && !functionality->IsActivated() && functionality->IsExclusiveFunctionality() )
172  {
173  MITK_INFO << "**** Activating legacy standalone functionality";
174  // deactivate old one if necessary
176  m_StandaloneFuntionality = partRef;
177 
178  MITK_INFO << "setting active flag";
179  // call activated on this functionality
180  functionality->SetActivated(true);
181  functionality->Activated();
182  }
183  else if (dynamic_cast<mitk::IZombieViewPart*>(partRef->GetPart(false).GetPointer()) &&
184  m_StandaloneFuntionality != partRef)
185  {
187  m_StandaloneFuntionality = partRef;
188  }
189 }
190 
193 {
194  if (partRef == nullptr) return;
195 
196  QmitkFunctionality* functionality = dynamic_cast<QmitkFunctionality*>(partRef->GetPart(false).GetPointer());
197  if(functionality && functionality->IsActivated())
198  {
199  functionality->SetActivated(false);
200  functionality->Deactivated();
201  }
202  else if (mitk::IZombieViewPart* zombie = dynamic_cast<mitk::IZombieViewPart*>(partRef->GetPart(false).GetPointer()))
203  {
204  zombie->ActivatedZombieView(berry::IWorkbenchPartReference::Pointer(newRef));
205  }
206 }
207 
209 {
210 
211 }
212 
214 {
215  window->GetPartService()->AddPartListener(this);
216 }
#define MITK_INFO
Definition: mitkLogMacros.h:18
berry::IPartListener::Events::Types GetPartEventTypes() const override
void DeactivateStandaloneFunctionality(berry::IWorkbenchPartReference *functionality, berry::IWorkbenchPartReference *newRef)
SmartPointer< Other > Cast() const
virtual SmartPointer< IWorkbenchPart > GetPart(bool restore)=0
void SetActivated(bool activated)
void PartClosed(const berry::IWorkbenchPartReference::Pointer &partRef) override
virtual void RemoveWindowListener(IWindowListener *listener)=0
std::set< berry::IWorkbenchPartReference * > m_VisibleStandaloneFunctionalities
virtual void Deactivated()
void PartOpened(const berry::IWorkbenchPartReference::Pointer &partRef) override
void ActivateStandaloneFunctionality(berry::IWorkbenchPartReference *partRef)
void WindowOpened(const berry::IWorkbenchWindow::Pointer &) override
static IWorkbench * GetWorkbench()
void PartDeactivated(const berry::IWorkbenchPartReference::Pointer &) override
void PartVisible(const berry::IWorkbenchPartReference::Pointer &partRef) override
Interface for MITK Workbench Views with special Zombie state handling.
static bool IsWorkbenchRunning()
The base class of all MITK related blueberry views (~ in the old version of MITK, this was called "Fu...
virtual void AddWindowListener(IWindowListener *listener)=0
void PartActivated(const berry::IWorkbenchPartReference::Pointer &partRef) override
berry::IWorkbenchPartReference * m_StandaloneFuntionality
void WindowClosed(const berry::IWorkbenchWindow::Pointer &window) override
void PartHidden(const berry::IWorkbenchPartReference::Pointer &partRef) override
virtual bool IsExclusiveFunctionality() const
std::set< QmitkFunctionality * > m_Functionalities
ObjectType * GetPointer() const