Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "QmitkCloseProjectAction.h"
00019
00020 #include <mitkCoreObjectFactory.h>
00021 #include <mitkDataStorageEditorInput.h>
00022 #include <mitkNodePredicateNot.h>
00023 #include <mitkNodePredicateProperty.h>
00024 #include <berryIEditorPart.h>
00025 #include <berryIWorkbenchPage.h>
00026 #include "QmitkStdMultiWidgetEditor.h"
00027
00028 #include <QMessageBox>
00029
00030 QmitkCloseProjectAction::QmitkCloseProjectAction(berry::IWorkbenchWindow::Pointer window)
00031 : QAction(0)
00032 {
00033 this->init(window);
00034 }
00035
00036 QmitkCloseProjectAction::QmitkCloseProjectAction(const QIcon & icon, berry::IWorkbenchWindow::Pointer window)
00037 : QAction(0)
00038 {
00039 this->setIcon(icon);
00040 this->init(window);
00041 }
00042
00043 void QmitkCloseProjectAction::init(berry::IWorkbenchWindow::Pointer window)
00044 {
00045 m_Window = window;
00046 this->setParent(static_cast<QWidget*>(m_Window->GetShell()->GetControl()));
00047 this->setText("&Close Project...");
00048 this->setToolTip("Close Project will remove all data objects from the application. This will free up the memory that is used by the data.");
00049 m_Window = window;
00050 this->connect(this, SIGNAL(triggered(bool)), this, SLOT(Run()));
00051 }
00052
00053 void QmitkCloseProjectAction::Run()
00054 {
00055
00056
00057 try
00058 {
00059
00060 mitk::DataStorageEditorInput::Pointer editorInput;
00061 mitk::DataStorage::Pointer storage;
00062 QmitkStdMultiWidgetEditor::Pointer multiWidgetEditor;
00063 berry::IEditorPart::Pointer editor = m_Window->GetActivePage()->GetActiveEditor();
00064 if (editor.Cast<QmitkStdMultiWidgetEditor>().IsNull())
00065 {
00066 editorInput = new mitk::DataStorageEditorInput();
00067 storage = editorInput->GetDataStorageReference()->GetDataStorage();
00068 }
00069 else
00070 {
00071 multiWidgetEditor = editor.Cast<QmitkStdMultiWidgetEditor>();
00072 storage = multiWidgetEditor->GetEditorInput().Cast<mitk::DataStorageEditorInput>()->GetDataStorageReference()->GetDataStorage();
00073 }
00074
00075
00076 if(storage->GetSubset(mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("helper object", mitk::BoolProperty::New(true))))->empty())
00077 return;
00078
00079 if (QMessageBox::question(NULL, "Remove all data?", "Are you sure that you want to close the current project? This will remove all data objects?", QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
00080 return;
00081
00082
00083 mitk::DataStorage::SetOfObjects::ConstPointer nodesToRemove = storage->GetAll();
00084 storage->Remove(nodesToRemove);
00085
00086 if (multiWidgetEditor.IsNotNull())
00087 multiWidgetEditor->GetStdMultiWidget()->AddPlanesToDataStorage();
00088 }
00089 catch (std::exception& e)
00090 {
00091 MITK_ERROR << "Exception caught during scene saving: " << e.what();
00092 QMessageBox::warning(NULL, "Error", QString("An error occurred during Close Project: %1").arg(e.what()));
00093 }
00094 }