diff --git a/GUI/coregui/Models/DetectorItems.cpp b/GUI/coregui/Models/DetectorItems.cpp
index f995b6722650234a21d774f759c7dc3ef34abbf4..a023ef6b96e760645697418cc46eccc75bb24d9f 100644
--- a/GUI/coregui/Models/DetectorItems.cpp
+++ b/GUI/coregui/Models/DetectorItems.cpp
@@ -26,6 +26,13 @@ DetectorItem::DetectorItem(ParameterizedItem *parent)
 {
     setItemName(Constants::DetectorType);
     registerGroupProperty(P_DETECTOR, Constants::DetectorGroup);
+
+    addToValidChildren(Constants::RectangleMaskType);
+    addToValidChildren(Constants::PolygonMaskType);
+    addToValidChildren(Constants::EllipseMaskType);
+    addToValidChildren(Constants::VerticalLineMaskType);
+    addToValidChildren(Constants::HorizontalLineMaskType);
+    addToValidChildren(Constants::MaskAllType);
 }
 
 // -------------------------------------------------------------------------- //
diff --git a/GUI/coregui/Views/InstrumentView.cpp b/GUI/coregui/Views/InstrumentView.cpp
index 55d88ac3577ac22f99616762cec8b24112073a11..e3682524dd409f7366980738c6cbaaf25712b684 100644
--- a/GUI/coregui/Views/InstrumentView.cpp
+++ b/GUI/coregui/Views/InstrumentView.cpp
@@ -166,9 +166,10 @@ void InstrumentView::onRowsAboutToBeRemoved(QModelIndex parent, int first, int /
     delete widget;
 }
 
-void InstrumentView::onExtendedDetectorEditorRequest(DetectorItem *)
+void InstrumentView::onExtendedDetectorEditorRequest(DetectorItem *detectorItem)
 {
     ExtendedDetectorDialog *dialog = new ExtendedDetectorDialog(this);
+    dialog->setDetectorItem(detectorItem);
     dialog->show();
 }
 
diff --git a/GUI/coregui/Views/InstrumentView.h b/GUI/coregui/Views/InstrumentView.h
index 3f93b576267db9d604746dfb60bacf1ac78d7331..76266479a1d600e7b155e948ac1495e95f4c072c 100644
--- a/GUI/coregui/Views/InstrumentView.h
+++ b/GUI/coregui/Views/InstrumentView.h
@@ -52,7 +52,7 @@ public slots:
     void onAddInstrument();
     void onRemoveInstrument();
     void onRowsAboutToBeRemoved(QModelIndex,int,int);
-    void onExtendedDetectorEditorRequest(DetectorItem *);
+    void onExtendedDetectorEditorRequest(DetectorItem *detectorItem);
 
 private:
     void setupConnections();
diff --git a/GUI/coregui/Views/InstrumentWidgets/DetectorMaskDelegate.cpp b/GUI/coregui/Views/InstrumentWidgets/DetectorMaskDelegate.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..842c81a01aa88d096691a37e25b52af2a9bc4417
--- /dev/null
+++ b/GUI/coregui/Views/InstrumentWidgets/DetectorMaskDelegate.cpp
@@ -0,0 +1,94 @@
+// ************************************************************************** //
+//
+//  BornAgain: simulate and fit scattering at grazing incidence
+//
+//! @file      coregui/Views/InstrumentWidgets/DetectorMaskDelegate.cpp
+//! @brief     Implements class DetectorMaskDelegate
+//!
+//! @homepage  http://www.bornagainproject.org
+//! @license   GNU General Public License v3 or higher (see COPYING)
+//! @copyright Forschungszentrum Jülich GmbH 2015
+//! @authors   Scientific Computing Group at MLZ Garching
+//! @authors   C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke
+//
+// ************************************************************************** //
+
+#include "DetectorMaskDelegate.h"
+#include "InstrumentModel.h"
+#include "MaskModel.h"
+#include "DetectorItems.h"
+#include "IntensityDataItem.h"
+#include "OutputData.h"
+#include "AxesItems.h"
+#include <QDebug>
+
+DetectorMaskDelegate::DetectorMaskDelegate(QObject *parent)
+    : QObject(parent)
+    , m_maskModel(0)
+    , m_detectorItem(0)
+{
+
+}
+
+void DetectorMaskDelegate::setDetectorItem(DetectorItem *detectorItem)
+{
+    m_detectorItem = detectorItem;
+    init_mask_model();
+}
+
+
+MaskModel *DetectorMaskDelegate::getMaskModel()
+{
+    return m_maskModel;
+}
+
+
+void DetectorMaskDelegate::init_mask_model()
+{
+    delete m_maskModel;
+    m_maskModel = new MaskModel(this);
+
+    IntensityDataItem *intensityItem = dynamic_cast<IntensityDataItem *>(
+        m_maskModel->insertNewItem(Constants::IntensityDataType));
+    Q_ASSERT(intensityItem);
+
+    intensityItem->setOutputData(createOutputData(m_detectorItem));
+}
+
+OutputData<double> *DetectorMaskDelegate::createOutputData(DetectorItem *detectorItem)
+{
+    OutputData<double> *result = new OutputData<double>;
+
+
+    auto subDetector = detectorItem->getSubItems()[DetectorItem::P_DETECTOR];
+    Q_ASSERT(subDetector);
+
+
+    Q_ASSERT(subDetector->modelType() == Constants::SphericalDetectorType);
+
+    auto x_axis = dynamic_cast<BasicAxisItem *>(
+         subDetector->getSubItems()[PhiAlphaDetectorItem::P_PHI_AXIS]);
+    Q_ASSERT(x_axis);
+    int n_x = x_axis->getRegisteredProperty(BasicAxisItem::P_NBINS).toInt();
+    double x_min
+        = Units::deg2rad(x_axis->getRegisteredProperty(BasicAxisItem::P_MIN).toDouble());
+    double x_max
+        = Units::deg2rad(x_axis->getRegisteredProperty(BasicAxisItem::P_MAX).toDouble());
+
+    auto y_axis = dynamic_cast<BasicAxisItem *>(
+        subDetector->getSubItems()[PhiAlphaDetectorItem::P_ALPHA_AXIS]);
+    Q_ASSERT(y_axis);
+    int n_y = y_axis->getRegisteredProperty(BasicAxisItem::P_NBINS).toInt();
+    double y_min
+        = Units::deg2rad(y_axis->getRegisteredProperty(BasicAxisItem::P_MIN).toDouble());
+    double y_max
+        = Units::deg2rad(y_axis->getRegisteredProperty(BasicAxisItem::P_MAX).toDouble());
+
+
+    result->addAxis("x", n_x, x_min, x_max);
+    result->addAxis("y", n_y, y_min, y_max);
+
+
+    return result;
+
+}
diff --git a/GUI/coregui/Views/InstrumentWidgets/DetectorMaskDelegate.h b/GUI/coregui/Views/InstrumentWidgets/DetectorMaskDelegate.h
new file mode 100644
index 0000000000000000000000000000000000000000..6a551bf9a209135f07aafd0991920faf4f8bed7d
--- /dev/null
+++ b/GUI/coregui/Views/InstrumentWidgets/DetectorMaskDelegate.h
@@ -0,0 +1,54 @@
+// ************************************************************************** //
+//
+//  BornAgain: simulate and fit scattering at grazing incidence
+//
+//! @file      coregui/Views/InstrumentWidgets/DetectorMaskDelegate.h
+//! @brief     Defines class DetectorMaskDelegate
+//!
+//! @homepage  http://www.bornagainproject.org
+//! @license   GNU General Public License v3 or higher (see COPYING)
+//! @copyright Forschungszentrum Jülich GmbH 2015
+//! @authors   Scientific Computing Group at MLZ Garching
+//! @authors   C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke
+//
+// ************************************************************************** //
+
+#ifndef DETECTORMASKDELEGATE_H
+#define DETECTORMASKDELEGATE_H
+
+#include "WinDllMacros.h"
+#include <QObject>
+#include <QModelIndex>
+
+template <class T> class OutputData;
+
+class MaskModel;
+class DetectorItem;
+
+//! The DetectorMaskDelegate class provides syncronization between DetectorItem (defined
+//! in InstrumentModel) and temporary IntensityDataItem (defined in temporary SessionModel).
+//! The later one is used by MaskEditor for mask drawing.
+
+class BA_CORE_API_ DetectorMaskDelegate : public QObject
+{
+    Q_OBJECT
+public:
+    DetectorMaskDelegate(QObject *parent);
+
+    void setDetectorItem(DetectorItem *detectorItem);
+
+    MaskModel *getMaskModel();
+
+private:
+    void init_mask_model();
+    OutputData<double> *createOutputData(DetectorItem *detectorItem);
+
+    MaskModel *m_maskModel;
+    QModelIndex m_intensityItemIndex;
+
+    DetectorItem *m_detectorItem;
+};
+
+
+#endif
+
diff --git a/GUI/coregui/Views/InstrumentWidgets/ExtendedDetectorDialog.cpp b/GUI/coregui/Views/InstrumentWidgets/ExtendedDetectorDialog.cpp
index 2b1eb4f095a3ab05ff7c7c4f0d80fca08244fb43..a4769fd69de420e3eeae50c22d8a419c5b529b62 100644
--- a/GUI/coregui/Views/InstrumentWidgets/ExtendedDetectorDialog.cpp
+++ b/GUI/coregui/Views/InstrumentWidgets/ExtendedDetectorDialog.cpp
@@ -15,13 +15,16 @@
 
 #include "ExtendedDetectorDialog.h"
 #include "MaskEditor.h"
-#include "SessionModel.h"
+#include "MaskModel.h"
+#include "DetectorMaskDelegate.h"
 #include <QPushButton>
+#include <QModelIndex>
 #include <QVBoxLayout>
 
 ExtendedDetectorDialog::ExtendedDetectorDialog(QWidget *parent)
     : QDialog(parent)
     , m_maskEditor(new MaskEditor)
+    , m_detectorMaskDelegate(new DetectorMaskDelegate(this))
 {
     setMinimumSize(256, 256);
     resize(800, 600);
@@ -46,11 +49,12 @@ ExtendedDetectorDialog::ExtendedDetectorDialog(QWidget *parent)
     layout->setContentsMargins(0, 0, 0, 0);
     setLayout(layout);
 
-    m_maskEditor->init_test_model();
+//    m_maskEditor->init_test_model();
 
 }
 
-void ExtendedDetectorDialog::setModel(SessionModel *model, const QModelIndex &rootIndex)
+void ExtendedDetectorDialog::setDetectorItem(DetectorItem *detectorItem)
 {
-    m_maskEditor->setModel(model, rootIndex);
+    m_detectorMaskDelegate->setDetectorItem(detectorItem);
+    m_maskEditor->setModel(m_detectorMaskDelegate->getMaskModel());
 }
diff --git a/GUI/coregui/Views/InstrumentWidgets/ExtendedDetectorDialog.h b/GUI/coregui/Views/InstrumentWidgets/ExtendedDetectorDialog.h
index 5d2655880ca5526f3e73ef17877b0291b1299e65..133d29362edd70426e21565485c3824cc6735eac 100644
--- a/GUI/coregui/Views/InstrumentWidgets/ExtendedDetectorDialog.h
+++ b/GUI/coregui/Views/InstrumentWidgets/ExtendedDetectorDialog.h
@@ -19,10 +19,11 @@
 #include <QDialog>
 
 class MaskEditor;
-class SetModel;
-class SessionModel;
+class DetectorItem;
+class DetectorMaskDelegate;
+
+//! The dialog which shows a MaskEditor
 
-//! The dialog which shows an editor to change parameters of DistributionItem
 class ExtendedDetectorDialog : public QDialog
 {
     Q_OBJECT
@@ -32,10 +33,11 @@ public:
     virtual ~ExtendedDetectorDialog(){}
 
 public slots:
-    void setModel(SessionModel *model, const QModelIndex &rootIndex);
+    void setDetectorItem(DetectorItem *detectorItem);
 
 private:
     MaskEditor *m_maskEditor;
+    DetectorMaskDelegate *m_detectorMaskDelegate;
 };
 
 #endif
diff --git a/GUI/coregui/Views/InstrumentWidgets/InstrumentSelectorWidget.cpp b/GUI/coregui/Views/InstrumentWidgets/InstrumentSelectorWidget.cpp
index a6bf9d778bc9ab85d878e3197ebbe207440c5e58..cf4cbda71816293090541686214fac51c7623c5f 100644
--- a/GUI/coregui/Views/InstrumentWidgets/InstrumentSelectorWidget.cpp
+++ b/GUI/coregui/Views/InstrumentWidgets/InstrumentSelectorWidget.cpp
@@ -71,9 +71,9 @@ void InstrumentSelectorWidget::setInstrumentModel(InstrumentModel *model)
             m_listView->setModel(model);
 
             connect(m_listView->selectionModel(),
-                    SIGNAL( selectionChanged(const QItemSelection&, const QItemSelection&) ),
+                    SIGNAL( selectionChanged(const QItemSelection&, const QItemSelection&)),
                     this,
-                    SIGNAL( selectionChanged(const QItemSelection&, const QItemSelection&) ),
+                    SIGNAL( selectionChanged(const QItemSelection&, const QItemSelection&)),
                     Qt::UniqueConnection
             );
         }
diff --git a/GUI/coregui/Views/MaskWidgets/MaskEditor.cpp b/GUI/coregui/Views/MaskWidgets/MaskEditor.cpp
index 7c49d08ec57b054233f39442ea91a25533494cab..f910924544b03b32d6821081ab7ec6f301f789b4 100644
--- a/GUI/coregui/Views/MaskWidgets/MaskEditor.cpp
+++ b/GUI/coregui/Views/MaskWidgets/MaskEditor.cpp
@@ -57,12 +57,20 @@ MaskEditor::MaskEditor(QWidget *parent)
 
 void MaskEditor::setModel(SessionModel *model, const QModelIndex &rootIndex)
 {
-    m_editorPropertyPanel->setModel(model, rootIndex);
+    QModelIndex intensityItemIndex = rootIndex;
+    if(!intensityItemIndex.isValid()) {
+        if(ParameterizedItem *intensityItem = model->getTopItem(Constants::IntensityDataType)) {
+            intensityItemIndex = model->indexOfItem(intensityItem);
+        }
+    }
+    Q_ASSERT(intensityItemIndex.isValid());
 
-    m_editorCanvas->setModel(model, rootIndex);
+    m_editorPropertyPanel->setModel(model, intensityItemIndex);
+
+    m_editorCanvas->setModel(model, intensityItemIndex);
     m_editorCanvas->setSelectionModel(m_editorPropertyPanel->selectionModel());
 
-    m_itemActions->setModel(model, rootIndex);
+    m_itemActions->setModel(model, intensityItemIndex);
     m_itemActions->setSelectionModel(m_editorPropertyPanel->selectionModel());
 }
 
@@ -135,7 +143,8 @@ void MaskEditor::init_test_model()
 
 //    MaskAllItem *rect = dynamic_cast<MaskAllItem *>(m_maskModel->insertNewItem(Constants::MaskAllType, m_maskModel->indexOfItem(item)));
 
-    setModel(maskModel, maskModel->indexOfItem(item));
+//    setModel(maskModel, maskModel->indexOfItem(item));
+    setModel(maskModel);
 }
 
 void MaskEditor::setup_connections()
diff --git a/GUI/coregui/Views/MaskWidgets/MaskEditor.h b/GUI/coregui/Views/MaskWidgets/MaskEditor.h
index 5081279f7ebf6e3ec8387fabd5c8cfa402fdd1ae..3b8f044f67d20f4f0281c99d858f2d211bc29c7d 100644
--- a/GUI/coregui/Views/MaskWidgets/MaskEditor.h
+++ b/GUI/coregui/Views/MaskWidgets/MaskEditor.h
@@ -19,6 +19,7 @@
 #include "WinDllMacros.h"
 #include <QWidget>
 #include <QMainWindow>
+#include <QModelIndex>
 
 class MaskEditorPropertyPanel;
 class MaskEditorActions;
@@ -36,7 +37,7 @@ public:
     MaskEditor(QWidget *parent = 0);
 
 public slots:
-    void setModel(SessionModel *model, const QModelIndex &rootIndex);
+    void setModel(SessionModel *model, const QModelIndex &rootIndex = QModelIndex());
     void onPropertyPanelRequest();
     void init_test_model();
 
diff --git a/GUI/coregui/Views/MaskWidgets/MaskResultsPresenter.cpp b/GUI/coregui/Views/MaskWidgets/MaskResultsPresenter.cpp
index 38c70b8b262c8bd23a6e517c12d3a9d74542b7a7..3405d59131f289b0d83ed0892c99855abf114fe8 100644
--- a/GUI/coregui/Views/MaskWidgets/MaskResultsPresenter.cpp
+++ b/GUI/coregui/Views/MaskWidgets/MaskResultsPresenter.cpp
@@ -116,6 +116,7 @@ OutputData<double> *MaskResultsPresenter::createMaskPresentation() const
     IntensityDataItem *origItem
         = dynamic_cast<IntensityDataItem *>(m_maskModel->itemForIndex(m_rootIndex));
     Q_ASSERT(origItem);
+    Q_ASSERT(origItem->getOutputData());
 
     OutputData<double> *result = origItem->getOutputData()->clone();