00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date: 2009-07-14 19:11:20 +0200 (Tue, 14 Jul 2009) $ 00006 Version: $Revision: 18127 $ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #include "QmitkFunctionalityCoordinator.h" 00019 #include "QmitkFunctionality.h" 00020 #include <QmitkStdMultiWidgetEditor.h> 00021 #include <berryPlatformUI.h> 00022 #include <berryIWorkbenchPage.h> 00023 00024 QmitkFunctionalityCoordinator::QmitkFunctionalityCoordinator() 00025 : m_StandaloneFuntionality(NULL) 00026 { 00027 } 00028 00029 void QmitkFunctionalityCoordinator::SetWindow( berry::IWorkbenchWindow::Pointer window ) 00030 { 00031 m_Window = window; 00032 if(window.IsNotNull()) 00033 { 00034 window->GetWorkbench()->AddWindowListener(berry::IWindowListener::Pointer(this)); 00035 window->GetPartService()->AddPartListener(berry::IPartListener::Pointer(this)); 00036 } 00037 } 00038 00039 QmitkFunctionalityCoordinator::~QmitkFunctionalityCoordinator() 00040 { 00041 } 00042 00043 berry::IPartListener::Events::Types QmitkFunctionalityCoordinator::GetPartEventTypes() const 00044 { 00045 return berry::IPartListener::Events::ACTIVATED | berry::IPartListener::Events::DEACTIVATED 00046 | berry::IPartListener::Events::CLOSED | berry::IPartListener::Events::HIDDEN 00047 | berry::IPartListener::Events::VISIBLE | berry::IPartListener::Events::OPENED; 00048 } 00049 00050 void QmitkFunctionalityCoordinator::PartActivated( berry::IWorkbenchPartReference::Pointer partRef ) 00051 { 00052 // Check for QmitkFunctionality 00053 QmitkFunctionality::Pointer _QmitkFunctionality = partRef->GetPart(false).Cast<QmitkFunctionality>(); 00054 // change the active standalone functionality 00055 this->ActivateStandaloneFunctionality(_QmitkFunctionality.GetPointer()); 00056 } 00057 00058 void QmitkFunctionalityCoordinator::PartDeactivated( berry::IWorkbenchPartReference::Pointer /*partRef*/ ) 00059 { 00060 // nothing to do here: see PartActivated() 00061 } 00062 00063 void QmitkFunctionalityCoordinator::PartOpened( berry::IWorkbenchPartReference::Pointer partRef ) 00064 { 00065 // check for multiwidget and inform views that it is available now 00066 if ( partRef->GetId() == QmitkStdMultiWidgetEditor::EDITOR_ID ) 00067 { 00068 for (std::set<QmitkFunctionality*>::iterator it = m_Functionalities.begin() 00069 ; it != m_Functionalities.end(); it++) 00070 { 00071 (*it)->StdMultiWidgetAvailable(*(partRef 00072 ->GetPart(false).Cast<QmitkStdMultiWidgetEditor>()->GetStdMultiWidget())); 00073 } 00074 } 00075 else 00076 { 00077 // Check for QmitkFunctionality 00078 QmitkFunctionality::Pointer _QmitkFunctionality = partRef->GetPart(false).Cast<QmitkFunctionality>(); 00079 if(_QmitkFunctionality.IsNotNull()) 00080 { 00081 m_Functionalities.insert(_QmitkFunctionality.GetPointer()); // save as opened functionality 00082 } 00083 } 00084 } 00085 00086 void QmitkFunctionalityCoordinator::PartClosed( berry::IWorkbenchPartReference::Pointer partRef ) 00087 { 00088 // check for multiwidget and inform views that it not available any more 00089 if ( partRef->GetId() == QmitkStdMultiWidgetEditor::EDITOR_ID ) 00090 { 00091 00092 QmitkStdMultiWidgetEditor::Pointer stdMultiWidgetEditor = partRef->GetPart(false).Cast<QmitkStdMultiWidgetEditor>(); 00093 for (std::set<QmitkFunctionality*>::iterator it = m_Functionalities.begin() 00094 ; it != m_Functionalities.end(); it++) 00095 { 00096 (*it)->StdMultiWidgetClosed(*(stdMultiWidgetEditor->GetStdMultiWidget())); 00097 (*it)->StdMultiWidgetNotAvailable(); // deprecated call, provided for consistence 00098 } 00099 } 00100 else 00101 { 00102 // check for functionality 00103 QmitkFunctionality::Pointer _QmitkFunctionality = partRef->GetPart(false).Cast<QmitkFunctionality>(); 00104 if(_QmitkFunctionality.IsNotNull()) 00105 { 00106 // deactivate on close ( the standalone functionality may still be activated ) 00107 this->DeactivateStandaloneFunctionality(_QmitkFunctionality.GetPointer()); 00108 00109 // and set pointer to 0 00110 if(m_StandaloneFuntionality == _QmitkFunctionality.GetPointer()) 00111 m_StandaloneFuntionality = 0; 00112 00113 m_Functionalities.erase(_QmitkFunctionality.GetPointer()); // remove as opened functionality 00114 // call PartClosed on the QmitkFunctionality 00115 _QmitkFunctionality->ClosePartProxy(); 00116 //m_VisibleStandaloneFunctionalities.erase(_QmitkFunctionality.GetPointer()); // remove if necessary (should be done before in PartHidden() 00117 } 00118 } 00119 } 00120 00121 void QmitkFunctionalityCoordinator::PartHidden( berry::IWorkbenchPartReference::Pointer partRef ) 00122 { 00123 // Check for QmitkFunctionality 00124 QmitkFunctionality::Pointer _QmitkFunctionality = partRef->GetPart(false).Cast<QmitkFunctionality>(); 00125 if(_QmitkFunctionality != 0) 00126 { 00127 _QmitkFunctionality->SetVisible(false); 00128 _QmitkFunctionality->Hidden(); 00129 // try to deactivate on hide (if is activated) 00130 this->DeactivateStandaloneFunctionality(_QmitkFunctionality.GetPointer()); 00131 00132 // tracking of Visible Standalone Functionalities 00133 m_VisibleStandaloneFunctionalities.erase(_QmitkFunctionality.GetPointer()); 00134 // activate Functionality if just one Standalone Functionality is visible (old one gets deactivated) 00135 if(m_VisibleStandaloneFunctionalities.size() == 1) 00136 this->ActivateStandaloneFunctionality(_QmitkFunctionality.GetPointer()); 00137 } 00138 } 00139 00140 void QmitkFunctionalityCoordinator::PartVisible( berry::IWorkbenchPartReference::Pointer partRef ) 00141 { 00142 // Check for QmitkFunctionality 00143 QmitkFunctionality::Pointer _QmitkFunctionality = partRef->GetPart(false).Cast<QmitkFunctionality>(); 00144 if(_QmitkFunctionality.IsNotNull()) 00145 { 00146 _QmitkFunctionality->SetVisible(true); 00147 _QmitkFunctionality->Visible(); 00148 00149 // tracking of Visible Standalone Functionalities 00150 m_VisibleStandaloneFunctionalities.insert(_QmitkFunctionality.GetPointer()); 00151 // activate Functionality if just one Standalone Functionality is visible 00152 if(m_VisibleStandaloneFunctionalities.size() == 1) 00153 this->ActivateStandaloneFunctionality(_QmitkFunctionality.GetPointer()); 00154 } 00155 } 00156 00157 void QmitkFunctionalityCoordinator::ActivateStandaloneFunctionality( QmitkFunctionality* functionality ) 00158 { 00159 if(functionality && !functionality->IsActivated() && functionality->IsExclusiveFunctionality()) 00160 { 00161 // deactivate old one if necessary 00162 this->DeactivateStandaloneFunctionality(m_StandaloneFuntionality); 00163 m_StandaloneFuntionality = functionality; 00164 00165 // call activated on this functionality 00166 m_StandaloneFuntionality->SetActivated(true); 00167 m_StandaloneFuntionality->Activated(); 00168 } 00169 } 00170 00171 void QmitkFunctionalityCoordinator::DeactivateStandaloneFunctionality(QmitkFunctionality* functionality) 00172 { 00173 if(functionality && functionality->IsActivated()) 00174 { 00175 functionality->SetActivated(false); 00176 functionality->Deactivated(); 00177 } 00178 } 00179 00180 void QmitkFunctionalityCoordinator::WindowClosed( berry::IWorkbenchWindow::Pointer window ) 00181 { 00182 if(window.IsNotNull()) 00183 { 00184 window->GetWorkbench()->RemoveWindowListener(berry::IWindowListener::Pointer(this)); 00185 window->GetPartService()->RemovePartListener(berry::IPartListener::Pointer(this)); 00186 } 00187 } 00188 00189 void QmitkFunctionalityCoordinator::WindowOpened( berry::IWorkbenchWindow::Pointer /*window*/ ) 00190 { 00191 00192 }