void QmitkFunctionalityCoordinator::WindowClosed( berry::IWorkbenchWindow::Pointer window ) { if(window.IsNotNull()) { window->GetWorkbench()->RemoveWindowListener(berry::IWindowListener::Pointer(this)); window->GetPartService()->RemovePartListener(berry::IPartListener::Pointer(this)); } }
void QmitkFunctionalityCoordinator::SetWindow( berry::IWorkbenchWindow::Pointer window ) { m_Window = window; if(window.IsNotNull()) { window->GetWorkbench()->AddWindowListener(berry::IWindowListener::Pointer(this)); window->GetPartService()->AddPartListener(berry::IPartListener::Pointer(this)); } }
// //! [UtilLoadFiles] void WorkbenchUtil::LoadFiles(const QStringList &fileNames, berry::IWorkbenchWindow::Pointer window, bool openEditor) // //! [UtilLoadFiles] { if (fileNames.empty()) return; mitk::IDataStorageReference::Pointer dataStorageRef; { ctkPluginContext* context = mitk::PluginActivator::GetContext(); mitk::IDataStorageService* dss = 0; ctkServiceReference dsRef = context->getServiceReference<mitk::IDataStorageService>(); if (dsRef) { dss = context->getService<mitk::IDataStorageService>(dsRef); } if (!dss) { QString msg = "IDataStorageService service not available. Unable to open files."; MITK_WARN << msg.toStdString(); QMessageBox::warning(QApplication::activeWindow(), "Unable to open files", msg); return; } // Get the active data storage (or the default one, if none is active) dataStorageRef = dss->GetDataStorage(); context->ungetService(dsRef); } mitk::DataStorage::Pointer dataStorage = dataStorageRef->GetDataStorage(); // Do the actual work of loading the data into the data storage std::vector<std::string> fileNames2; // Correct conversion for File names.(BUG 12252) fileNames2.resize(fileNames.size()); for (int i = 0; i< fileNames.size(); i++) fileNames2[i] = std::string(QFile::encodeName(fileNames[i]).data()); // Old conversion which returns wrong encoded Non-Latin-Characters. //ctk::qListToSTLVector(fileNames, fileNames2); // Turn off ASSERT #if defined(_MSC_VER) && !defined(NDEBUG) && defined(_DEBUG) && defined(_CRT_ERROR) int lastCrtReportType = _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_DEBUG ); #endif const bool dsmodified = mitk::IOUtil::LoadFiles(fileNames2, *dataStorage); // Set ASSERT status back to previous status. #if defined(_MSC_VER) && !defined(NDEBUG) && defined(_DEBUG) && defined(_CRT_ERROR) if (lastCrtReportType) _CrtSetReportMode( _CRT_ASSERT, lastCrtReportType ); #endif // Check if there is an open perspective. If not, open the default perspective. if (window->GetActivePage().IsNull()) { std::string defaultPerspId = window->GetWorkbench()->GetPerspectiveRegistry()->GetDefaultPerspective(); window->GetWorkbench()->ShowPerspective(defaultPerspId, window); } bool globalReinitOnNodeAdded = true; berry::IPreferencesService::Pointer prefService = berry::Platform::GetServiceRegistry().GetServiceById<berry::IPreferencesService>(berry::IPreferencesService::ID); if (prefService.IsNotNull()) { berry::IBerryPreferences::Pointer prefs = (prefService->GetSystemPreferences()->Node("org.mitk.views.datamanager")).Cast<berry::IBerryPreferences>(); if(prefs.IsNotNull()) globalReinitOnNodeAdded = prefs->GetBool("Call global reinit if node is added", true); } if (openEditor && globalReinitOnNodeAdded) { try { // Activate the editor using the same data storage or open the default editor mitk::DataStorageEditorInput::Pointer input(new mitk::DataStorageEditorInput(dataStorageRef)); berry::IEditorPart::Pointer editor = mitk::WorkbenchUtil::OpenEditor(window->GetActivePage(), input, true); mitk::IRenderWindowPart* renderEditor = dynamic_cast<mitk::IRenderWindowPart*>(editor.GetPointer()); mitk::IRenderingManager* renderingManager = renderEditor == 0 ? 0 : renderEditor->GetRenderingManager(); if(dsmodified && renderingManager) { mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(dataStorage); } } catch (const berry::PartInitException& e) { QString msg = "An error occurred when displaying the file(s): %1"; QMessageBox::warning(QApplication::activeWindow(), "Error displaying file", msg.arg(QString::fromStdString(e.message()))); } } }