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