Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkOpenXnatEditorAction.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 
19 #include <berryIEditorPart.h>
20 #include <berryIWorkbenchPage.h>
22 #include <berryIWorkbench.h>
23 #include <berryPlatform.h>
24 #include <berryFileEditorInput.h>
25 
27 : QAction(nullptr)
28 {
29  this->init(window);
30 }
31 
33 : QAction(nullptr)
34 {
35  this->setIcon(icon);
36 
37  this->init(window);
38 }
39 
40 void QmitkOpenXnatEditorAction::init(berry::IWorkbenchWindow::Pointer window)
41 {
42  m_Window = window;
43  this->setParent(static_cast<QWidget*>(m_Window->GetShell()->GetControl()));
44  this->setText("&XNAT");
45  this->setToolTip("Open XNAT tool");
46 
48 
49  m_GeneralPreferencesNode = prefService->GetSystemPreferences()->Node("/General");
50 
51  this->connect(this, SIGNAL(triggered(bool)), this, SLOT(Run()));
52 }
53 
55 {
56  // check if there is an open perspective, if not open the default perspective
57  if (m_Window->GetActivePage().IsNull())
58  {
59  QString defaultPerspId = m_Window->GetWorkbench()->GetPerspectiveRegistry()->GetDefaultPerspective();
60  m_Window->GetWorkbench()->ShowPerspective(defaultPerspId, m_Window);
61  }
62 
63  QList<berry::IEditorReference::Pointer> editors =
64  m_Window->GetActivePage()->FindEditors(berry::IEditorInput::Pointer(nullptr),
65  "org.mitk.editors.xnat.browser", berry::IWorkbenchPage::MATCH_ID);
66 
67  if (editors.empty())
68  {
69  // no XnatEditor is currently open, create a new one
70  berry::IEditorInput::Pointer editorInput(new berry::FileEditorInput(QString()));
71  m_Window->GetActivePage()->OpenEditor(editorInput, "org.mitk.editors.xnat.browser");
72  }
73  else
74  {
75  // reuse an existing editor
76  berry::IEditorPart::Pointer reuseEditor = editors.front()->GetEditor(true);
77  m_Window->GetActivePage()->Activate(reuseEditor);
78  }
79 }
virtual SmartPointer< IPreferences > GetSystemPreferences()=0
QmitkOpenXnatEditorAction(berry::IWorkbenchWindow::Pointer window)
static IPreferencesService * GetPreferencesService()