Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 #include "QmitkFunctionality.h"
20 #include <berryPlatformUI.h>
21 #include <berryIWorkbenchPage.h>
22 
23 #include <mitkIZombieViewPart.h>
24 
26  : m_StandaloneFuntionality(0)
27 {
28 }
29 
31 {
33  QList<berry::IWorkbenchWindow::Pointer> wnds(berry::PlatformUI::GetWorkbench()->GetWorkbenchWindows());
34  for (auto i = wnds.begin(); i != wnds.end(); ++i)
35  {
36  (*i)->GetPartService()->AddPartListener(this);
37  }
38 }
39 
41 {
43 
45  QList<berry::IWorkbenchWindow::Pointer> wnds(berry::PlatformUI::GetWorkbench()->GetWorkbenchWindows());
46  for (auto i = wnds.begin(); i != wnds.end(); ++i)
47  {
48  (*i)->GetPartService()->RemovePartListener(this);
49  }
50 }
51 
53 {
54 }
55 
56 berry::IPartListener::Events::Types QmitkFunctionalityCoordinator::GetPartEventTypes() const
57 {
61 }
62 
64 {
65  // change the active standalone functionality
67 }
68 
70 {
71  // nothing to do here: see PartActivated()
72 }
73 
75 {
76  // check for multiwidget and inform views that it is available now
77  if ( partRef->GetId() == QmitkStdMultiWidgetEditor::EDITOR_ID )
78  {
79  for (std::set<QmitkFunctionality*>::iterator it = m_Functionalities.begin()
80  ; it != m_Functionalities.end(); it++)
81  {
82  (*it)->StdMultiWidgetAvailable(*(partRef
83  ->GetPart(false).Cast<QmitkStdMultiWidgetEditor>()->GetStdMultiWidget()));
84  }
85  }
86  else
87  {
88  // Check for QmitkFunctionality
89  QmitkFunctionality::Pointer _QmitkFunctionality = partRef->GetPart(false).Cast<QmitkFunctionality>();
90  if(_QmitkFunctionality.IsNotNull())
91  {
92  m_Functionalities.insert(_QmitkFunctionality.GetPointer()); // save as opened functionality
93  }
94  }
95 }
96 
98 {
99  // check for multiwidget and inform views that it not available any more
100  if ( partRef->GetId() == QmitkStdMultiWidgetEditor::EDITOR_ID )
101  {
102 
103  QmitkStdMultiWidgetEditor::Pointer stdMultiWidgetEditor = partRef->GetPart(false).Cast<QmitkStdMultiWidgetEditor>();
104  for (std::set<QmitkFunctionality*>::iterator it = m_Functionalities.begin()
105  ; it != m_Functionalities.end(); it++)
106  {
107  (*it)->StdMultiWidgetClosed(*(stdMultiWidgetEditor->GetStdMultiWidget()));
108  (*it)->StdMultiWidgetNotAvailable(); // deprecated call, provided for consistence
109  }
110  }
111  else
112  {
113  // check for functionality
114  QmitkFunctionality::Pointer _QmitkFunctionality = partRef->GetPart(false).Cast<QmitkFunctionality>();
115  if(_QmitkFunctionality.IsNotNull())
116  {
117  // deactivate on close ( the standalone functionality may still be activated )
118  this->DeactivateStandaloneFunctionality(partRef.GetPointer(), 0);
119 
120  // and set pointer to 0
121  if(m_StandaloneFuntionality == partRef.GetPointer())
123 
124  m_Functionalities.erase(_QmitkFunctionality.GetPointer()); // remove as opened functionality
125 
126  // call PartClosed on the QmitkFunctionality
127  _QmitkFunctionality->ClosePartProxy();
128  //m_VisibleStandaloneFunctionalities.erase(_QmitkFunctionality.GetPointer()); // remove if necessary (should be done before in PartHidden()
129  }
130  }
131 }
132 
134 {
135  // Check for QmitkFunctionality
136  QmitkFunctionality::Pointer _QmitkFunctionality = partRef->GetPart(false).Cast<QmitkFunctionality>();
137  if(_QmitkFunctionality != 0)
138  {
139  _QmitkFunctionality->SetVisible(false);
140  _QmitkFunctionality->Hidden();
141 
142  // tracking of Visible Standalone Functionalities
144 
145  // activate Functionality if just one Standalone Functionality is visible
146  if( m_VisibleStandaloneFunctionalities.size() == 1 )
148  }
149 }
150 
152 {
153  // Check for QmitkFunctionality
154  QmitkFunctionality::Pointer _QmitkFunctionality = partRef->GetPart(false).Cast<QmitkFunctionality>();
155  if(_QmitkFunctionality.IsNotNull())
156  {
157  _QmitkFunctionality->SetVisible(true);
158  _QmitkFunctionality->Visible();
159 
160  // tracking of Visible Standalone Functionalities
161  if( _QmitkFunctionality->IsExclusiveFunctionality() )
162  {
164 
165  // activate Functionality if just one Standalone Functionality is visible
166  if( m_VisibleStandaloneFunctionalities.size() == 1 )
168  }
169  }
170 }
171 
173 {
174  QmitkFunctionality* functionality = dynamic_cast<QmitkFunctionality*>(partRef->GetPart(false).GetPointer());
175  if( functionality && !functionality->IsActivated() && functionality->IsExclusiveFunctionality() )
176  {
177  MITK_INFO << "**** Activating legacy standalone functionality";
178  // deactivate old one if necessary
180  m_StandaloneFuntionality = partRef;
181 
182  MITK_INFO << "setting active flag";
183  // call activated on this functionality
184  functionality->SetActivated(true);
185  functionality->Activated();
186  }
187  else if (dynamic_cast<mitk::IZombieViewPart*>(partRef->GetPart(false).GetPointer()) &&
188  m_StandaloneFuntionality != partRef)
189  {
191  m_StandaloneFuntionality = partRef;
192  }
193 }
194 
197 {
198  if (partRef == 0) return;
199 
200  QmitkFunctionality* functionality = dynamic_cast<QmitkFunctionality*>(partRef->GetPart(false).GetPointer());
201  if(functionality && functionality->IsActivated())
202  {
203  functionality->SetActivated(false);
204  functionality->Deactivated();
205  }
206  else if (mitk::IZombieViewPart* zombie = dynamic_cast<mitk::IZombieViewPart*>(partRef->GetPart(false).GetPointer()))
207  {
208  zombie->ActivatedZombieView(berry::IWorkbenchPartReference::Pointer(newRef));
209  }
210 }
211 
213 {
214 
215 }
216 
218 {
219  window->GetPartService()->AddPartListener(this);
220 }
#define MITK_INFO
Definition: mitkLogMacros.h:22
berry::IPartListener::Events::Types GetPartEventTypes() const override
void DeactivateStandaloneFunctionality(berry::IWorkbenchPartReference *functionality, berry::IWorkbenchPartReference *newRef)
virtual SmartPointer< IWorkbenchPart > GetPart(bool restore)=0
void SetActivated(bool activated)
virtual void PartClosed(const berry::IWorkbenchPartReference::Pointer &partRef) override
virtual void RemoveWindowListener(IWindowListener *listener)=0
std::set< berry::IWorkbenchPartReference * > m_VisibleStandaloneFunctionalities
virtual void Deactivated()
virtual bool IsExclusiveFunctionality() const
virtual void PartOpened(const berry::IWorkbenchPartReference::Pointer &partRef) override
void ActivateStandaloneFunctionality(berry::IWorkbenchPartReference *partRef)
virtual void WindowOpened(const berry::IWorkbenchWindow::Pointer &) override
static IWorkbench * GetWorkbench()
virtual void PartDeactivated(const berry::IWorkbenchPartReference::Pointer &) override
virtual 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
ObjectType * GetPointer() const
virtual void PartActivated(const berry::IWorkbenchPartReference::Pointer &partRef) override
berry::IWorkbenchPartReference * m_StandaloneFuntionality
virtual void WindowClosed(const berry::IWorkbenchWindow::Pointer &window) override
virtual void PartHidden(const berry::IWorkbenchPartReference::Pointer &partRef) override
SmartPointer< Other > Cast() const
std::set< QmitkFunctionality * > m_Functionalities