diff --git a/Gui/DataView/CMakeLists.txt b/Gui/DataView/CMakeLists.txt
index ff3f6228152769d49f57dc89e4c449b547f40c22..0e2f4e04e9c6dfac8f20b43d67ae133d2b2b2a8a 100644
--- a/Gui/DataView/CMakeLists.txt
+++ b/Gui/DataView/CMakeLists.txt
@@ -17,6 +17,7 @@ set( SOURCES
 	LinearEditDialog.cpp
 	LineEditDialog.cpp
 	ListPropertiesDialog.cpp
+	MeshValueEditDialog.cpp
 	ModellingTabWidget.cpp
 	ModelTreeItem.cpp
 	MshEditDialog.cpp
@@ -54,6 +55,7 @@ set( MOC_HEADERS
 	LinearEditDialog.h
 	LineEditDialog.h
 	ListPropertiesDialog.h
+	MeshValueEditDialog.h
 	ModellingTabWidget.h
 	MshEditDialog.h
 	MshModel.h
@@ -96,6 +98,7 @@ set( UIS
 	License.ui
 	LinearEdit.ui
 	LineEdit.ui
+	MeshValueEdit.ui
 	ModellingTabWidgetBase.ui
 	MshEdit.ui
 	MshQualitySelection.ui
diff --git a/Gui/DataView/MeshValueEdit.ui b/Gui/DataView/MeshValueEdit.ui
new file mode 100644
index 0000000000000000000000000000000000000000..15ab51f7328a25a36e806a57baca86d2ccda4ca1
--- /dev/null
+++ b/Gui/DataView/MeshValueEdit.ui
@@ -0,0 +1,269 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MeshValueEdit</class>
+ <widget class="QDialog" name="MeshValueEdit">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>431</width>
+    <height>206</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QRadioButton" name="condenseButton">
+     <property name="text">
+      <string>Condense material groups to smallest possible range</string>
+     </property>
+     <property name="checked">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <layout class="QGridLayout" name="gridLayout_2">
+     <item row="0" column="1">
+      <widget class="QLabel" name="label_example">
+       <property name="text">
+        <string>(e.g. [0,2,27] will become [0,1,2]; [3,4,6,7,9] will become [0,1,2,3,4])</string>
+       </property>
+      </widget>
+     </item>
+     <item row="0" column="0">
+      <spacer name="horizontalSpacer_5">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeType">
+        <enum>QSizePolicy::Fixed</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>10</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item row="0" column="2">
+      <spacer name="horizontalSpacer_6">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QRadioButton" name="replaceButton">
+     <property name="text">
+      <string>Replace material group value:</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <layout class="QGridLayout" name="gridLayout">
+     <item row="1" column="2">
+      <widget class="QLineEdit" name="edit_new_value">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="minimumSize">
+        <size>
+         <width>0</width>
+         <height>0</height>
+        </size>
+       </property>
+       <property name="maximumSize">
+        <size>
+         <width>40</width>
+         <height>16777215</height>
+        </size>
+       </property>
+       <property name="baseSize">
+        <size>
+         <width>0</width>
+         <height>0</height>
+        </size>
+       </property>
+       <property name="maxLength">
+        <number>5</number>
+       </property>
+      </widget>
+     </item>
+     <item row="0" column="3">
+      <spacer name="horizontalSpacer">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item row="0" column="0">
+      <spacer name="horizontalSpacer_3">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeType">
+        <enum>QSizePolicy::Fixed</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>10</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item row="1" column="0">
+      <spacer name="horizontalSpacer_4">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeType">
+        <enum>QSizePolicy::Fixed</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>10</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item row="1" column="3">
+      <spacer name="horizontalSpacer_2">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item row="1" column="1">
+      <widget class="QLabel" name="label_new_value">
+       <property name="text">
+        <string>New value:</string>
+       </property>
+      </widget>
+     </item>
+     <item row="0" column="2">
+      <widget class="QLineEdit" name="edit_old_value">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="minimumSize">
+        <size>
+         <width>0</width>
+         <height>0</height>
+        </size>
+       </property>
+       <property name="maximumSize">
+        <size>
+         <width>40</width>
+         <height>16777215</height>
+        </size>
+       </property>
+       <property name="maxLength">
+        <number>5</number>
+       </property>
+      </widget>
+     </item>
+     <item row="0" column="1">
+      <widget class="QLabel" name="label_old_value">
+       <property name="maximumSize">
+        <size>
+         <width>16777215</width>
+         <height>16777215</height>
+        </size>
+       </property>
+       <property name="text">
+        <string>Current value:</string>
+       </property>
+      </widget>
+     </item>
+     <item row="2" column="1" colspan="3">
+      <widget class="QCheckBox" name="replaceCheckBox">
+       <property name="text">
+        <string>Do not replace if material group already exists</string>
+       </property>
+       <property name="checked">
+        <bool>true</bool>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>MeshValueEdit</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>MeshValueEdit</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
diff --git a/Gui/DataView/MeshValueEditDialog.cpp b/Gui/DataView/MeshValueEditDialog.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..384ef06e30acf91f87f0cad52859cc14f53da99e
--- /dev/null
+++ b/Gui/DataView/MeshValueEditDialog.cpp
@@ -0,0 +1,76 @@
+/**
+ * \file
+ * \author Karsten Rink
+ * \date   2013-03-27
+ * \brief  Implementation of the MeshValueEditDialog class.
+ *
+ * \copyright
+ * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
+ *            Distributed under a Modified BSD License.
+ *              See accompanying file LICENSE.txt or
+ *              http://www.opengeosys.org/project/license
+ *
+ */
+
+#include "MeshValueEditDialog.h"
+#include "MshEditor.h"
+#include "OGSError.h"
+
+
+MeshValueEditDialog::MeshValueEditDialog(MeshLib::Mesh* mesh, QDialog* parent)
+	: QDialog(parent), _mesh(mesh)
+{
+	setupUi(this);
+	this->edit_old_value->setEnabled(false);
+	this->edit_new_value->setEnabled(false);
+	this->replaceCheckBox->setEnabled(false);
+}
+
+MeshValueEditDialog::~MeshValueEditDialog(void)
+{
+}
+
+void MeshValueEditDialog::accept()
+{
+	if (this->condenseButton->isChecked())
+		MeshLib::MshEditor::condenseElementValues(*_mesh);
+	else
+	{
+		if (this->edit_old_value->text().isEmpty())
+		{
+			OGSError::box("Please input which material you want to replace.");
+			return;
+		}
+		unsigned old_value = static_cast<unsigned>(atoi(this->edit_old_value->text().toStdString().c_str()));
+		if (this->edit_new_value->text().isEmpty())
+		{
+			OGSError::box("Please input the new material to replace group " + this->edit_old_value->text() + ".");
+			return;
+		}
+		unsigned new_value = static_cast<unsigned>(atoi(this->edit_new_value->text().toStdString().c_str()));
+		bool do_not_replace = this->replaceCheckBox->isChecked();
+		bool result = MeshLib::MshEditor::replaceElementValue(*_mesh, old_value, new_value, !do_not_replace);
+		if (!result && do_not_replace)
+		{
+			OGSError::box("The new material group already exists.");
+			return;
+		}
+	}
+		
+	emit valueEditFinished(_mesh);
+	this->done(QDialog::Accepted);
+}
+
+void MeshValueEditDialog::reject()
+{
+	this->done(QDialog::Rejected);
+}
+
+void MeshValueEditDialog::on_replaceButton_toggled(bool isSelected)
+{
+	this->edit_old_value->setEnabled(isSelected);
+	this->edit_new_value->setEnabled(isSelected);
+	this->replaceCheckBox->setEnabled(isSelected);
+}
+
+
diff --git a/Gui/DataView/MeshValueEditDialog.h b/Gui/DataView/MeshValueEditDialog.h
new file mode 100644
index 0000000000000000000000000000000000000000..1801cf18a9c1f4825168b889830f3de5eb55191e
--- /dev/null
+++ b/Gui/DataView/MeshValueEditDialog.h
@@ -0,0 +1,56 @@
+/**
+ * \file
+ * \author Karsten Rink
+ * \date   2013-03-27
+ * \brief  Definition of the MeshValueEditDialog class.
+ *
+ * \copyright
+ * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
+ *            Distributed under a Modified BSD License.
+ *              See accompanying file LICENSE.txt or
+ *              http://www.opengeosys.org/project/license
+ *
+ */
+
+#ifndef MESHVALUEEDITDIALOG_H
+#define MESHVALUEEDITDIALOG_H
+
+#include "ui_MeshValueEdit.h"
+#include "FEMCondition.h"
+
+#include <QDialog>
+
+namespace MeshLib {
+	class Mesh;
+}
+
+/**
+ * \brief A dialog window for changing the MaterialID for mesh elements
+ */
+class MeshValueEditDialog : public QDialog, private Ui_MeshValueEdit
+{
+	Q_OBJECT
+
+public:
+	/// Constructor for creating a new FEM condition.
+	MeshValueEditDialog(MeshLib::Mesh* mesh, QDialog* parent = 0);
+
+	~MeshValueEditDialog(void);
+
+private:
+	MeshLib::Mesh* _mesh;
+
+private slots:
+	/// Instructions if the OK-Button has been pressed.
+	void accept();
+
+	/// Instructions if the Cancel-Button has been pressed.
+	void reject();
+
+	void on_replaceButton_toggled(bool isSelected);
+
+signals:
+	void valueEditFinished(MeshLib::Mesh*);
+};
+
+#endif //MESHVALUEEDITDIALOG_H
diff --git a/Gui/DataView/MshModel.cpp b/Gui/DataView/MshModel.cpp
index 23b39fd012e4e16988b701164065634db8667a74..a2cd3d2f732be0aa7c991582119268fd170e125f 100644
--- a/Gui/DataView/MshModel.cpp
+++ b/Gui/DataView/MshModel.cpp
@@ -153,6 +153,19 @@ bool MshModel::removeMesh(const std::string &name)
 	return false;
 }
 
+void MshModel::updateMesh(MeshLib::Mesh* mesh)
+{
+	for (int i = 0; i < _rootItem->childCount(); i++)
+	{
+		if (dynamic_cast<MshItem*>(this->_rootItem->child(i))->getMesh() == mesh)
+		{
+			emit meshRemoved(this, this->index(i, 0, QModelIndex()));
+			_rootItem->removeChildren(i,1);
+		}
+	}
+	this->addMeshObject(mesh);
+}
+
 void MshModel::updateModel()
 {
 	const std::vector<MeshLib::Mesh*> msh_vec = _project.getMeshObjects();
diff --git a/Gui/DataView/MshModel.h b/Gui/DataView/MshModel.h
index 671625c8ce5e53bdeeb1b5f7d301c1c409668b4f..0b72e1cbbfd82d1ca291f4041739831d41adecce 100644
--- a/Gui/DataView/MshModel.h
+++ b/Gui/DataView/MshModel.h
@@ -49,6 +49,8 @@ public slots:
 	bool removeMesh(const QModelIndex &idx);
 	/// Removes the mesh with the given name.
 	bool removeMesh(const std::string &name);
+	/// Updates the model/view for a mesh.
+	void updateMesh(MeshLib::Mesh*);
 	/// Updates the model based on the ProjectData-object
 	void updateModel();
 	/// Returns the VTK source item for the mesh with the given index.
diff --git a/Gui/DataView/MshView.cpp b/Gui/DataView/MshView.cpp
index 0fd3ae090aedb4f74b6f35e268898adc1c4e8c95..3c23273740016f061c04d2aef56605d6a06d28f8 100644
--- a/Gui/DataView/MshView.cpp
+++ b/Gui/DataView/MshView.cpp
@@ -15,6 +15,7 @@
 #include "MshView.h"
 #include "Mesh.h"
 #include "MshEditDialog.h"
+#include "MeshValueEditDialog.h"
 #include "MshItem.h"
 #include "MshModel.h"
 #include "OGSError.h"
@@ -107,6 +108,7 @@ void MshView::contextMenuEvent( QContextMenuEvent* event )
 	{
 		QMenu menu;
 		QAction* editMeshAction   = menu.addAction("Edit mesh...");
+		QAction* editValuesAction  = menu.addAction("Edit material groups...");
 		QAction* checkMeshAction  = menu.addAction("Check mesh quality...");
 		QAction* surfaceMeshAction (NULL);
 		if (is_3D_mesh)
@@ -119,6 +121,7 @@ void MshView::contextMenuEvent( QContextMenuEvent* event )
 		QAction* loadDirectAction = direct_cond_menu.addAction("Load...");
 		//menu.addSeparator();
 		connect(editMeshAction, SIGNAL(triggered()), this, SLOT(openMshEditDialog()));
+		connect(editValuesAction, SIGNAL(triggered()), this, SLOT(openValuesEditDialog()));
 		connect(checkMeshAction, SIGNAL(triggered()), this, SLOT(checkMeshQuality()));
 		if (is_3D_mesh)
 			connect(surfaceMeshAction, SIGNAL(triggered()), this, SLOT(extractSurfaceMesh()));
@@ -141,6 +144,18 @@ void MshView::openMshEditDialog()
 	meshEdit.exec();
 }
 
+void MshView::openValuesEditDialog()
+{
+	MshModel* model = static_cast<MshModel*>(this->model());
+	QModelIndex index = this->selectionModel()->currentIndex();
+	MeshLib::Mesh* mesh = const_cast<MeshLib::Mesh*>(static_cast<MshModel*>(this->model())->getMesh(index));
+
+	MeshValueEditDialog valueEdit(mesh);
+	connect(&valueEdit, SIGNAL(valueEditFinished(MeshLib::Mesh*)),
+		    model, SLOT(updateMesh(MeshLib::Mesh*)));
+	valueEdit.exec();
+}
+
 void MshView::extractSurfaceMesh()
 {
 	QModelIndex index = this->selectionModel()->currentIndex();
diff --git a/Gui/DataView/MshView.h b/Gui/DataView/MshView.h
index 436a56b5047c8252adba12efd5cdd20b7c6b34a2..02efdfeb23bc66c22f603cd4ea8e0090d1c95b6f 100644
--- a/Gui/DataView/MshView.h
+++ b/Gui/DataView/MshView.h
@@ -59,9 +59,12 @@ private:
 	void contextMenuEvent( QContextMenuEvent* event );
 
 private slots:
-	/// Open a dialog for editing meshes.
+	/// Opens a dialog for editing meshes.
 	void openMshEditDialog();
 
+	/// Opens a dialog for editing material groups.
+	void openValuesEditDialog();
+
 	/// Adds a new mesh.
 	void addMesh();
 
diff --git a/MeshLib/MshEditor.cpp b/MeshLib/MshEditor.cpp
index 4990088c261135453bc47206e5b798f72c3a42d4..d834525b5b16d6e9b01d94be57a1dc782681469b 100644
--- a/MeshLib/MshEditor.cpp
+++ b/MeshLib/MshEditor.cpp
@@ -295,16 +295,20 @@ std::vector<unsigned> MshEditor::getMeshValues(const MeshLib::Mesh &mesh)
 	return value_mapping;
 }
 
-bool MshEditor::replaceElementValue(MeshLib::Mesh &mesh, unsigned old_value, unsigned new_value)
+bool MshEditor::replaceElementValue(MeshLib::Mesh &mesh, unsigned old_value, unsigned new_value, bool replace_if_exists)
 {
 	std::vector<unsigned> value_mapping (MshEditor::getMeshValues(mesh));
-	const unsigned nValues (value_mapping.size());
-	for (unsigned j=0; j<nValues; ++j)
+
+	if (!replace_if_exists)
 	{
-		if (new_value == value_mapping[j])
+		const unsigned nValues (value_mapping.size());
+		for (unsigned j=0; j<nValues; ++j)
 		{
-			ERR ("Error in MshEditor::replaceElementValue() - Replacement value is already take.");
-			return false;
+			if (new_value == value_mapping[j])
+			{
+				ERR ("Error in MshEditor::replaceElementValue() - Replacement value is already taken.");
+				return false;
+			}
 		}
 	}
 	const std::size_t nElements (mesh.getNElements());
@@ -317,17 +321,16 @@ bool MshEditor::replaceElementValue(MeshLib::Mesh &mesh, unsigned old_value, uns
 	return true;
 }
 
-unsigned MshEditor::compressElementValues(MeshLib::Mesh &mesh)
+unsigned MshEditor::condenseElementValues(MeshLib::Mesh &mesh)
 {
-	const std::size_t nElements (mesh.getNElements());
-	std::vector<MeshLib::Element*> elements (mesh.getElements());
 	std::vector<unsigned> value_mapping (MshEditor::getMeshValues(mesh));
-
-	std::vector<unsigned> reverse_mapping(value_mapping.back(),0);
+	std::vector<unsigned> reverse_mapping(value_mapping.back()+1, 0);
 	const unsigned nValues (value_mapping.size());
-	for (unsigned i=0; i<nElements; ++i)
+	for (unsigned i=0; i<nValues; ++i)
 		reverse_mapping[value_mapping[i]] = i;
 
+	const std::size_t nElements (mesh.getNElements());
+	std::vector<MeshLib::Element*> elements (mesh.getElements());
 	for (unsigned i=0; i<nElements; ++i)
 		elements[i]->setValue(reverse_mapping[elements[i]->getValue()]);
 
diff --git a/MeshLib/MshEditor.h b/MeshLib/MshEditor.h
index 8ace52e55fcddcf422221b87be8847372c9c959e..2a4bf4e666c0b1b8f23a8067bfe8614bb47b37fb 100644
--- a/MeshLib/MshEditor.h
+++ b/MeshLib/MshEditor.h
@@ -50,11 +50,11 @@ public:
 
 	/// Reduces the values assigned the elements of mesh to the smallest possible range.
 	/// Returns the number of different values.
-	static unsigned compressElementValues(MeshLib::Mesh &mesh);
+	static unsigned condenseElementValues(MeshLib::Mesh &mesh);
 
 	/// Replaces for all elements of mesh with the value old_value with new_value if possible.
 	/// Returns true if successful or false if the value is already taken.
-	static bool replaceElementValue(MeshLib::Mesh &mesh, unsigned old_value, unsigned new_value);
+	static bool replaceElementValue(MeshLib::Mesh &mesh, unsigned old_value, unsigned new_value, bool replace_if_exists = false);
 
 private:
 	/// Functionality needed for getSurfaceNodes() and getMeshSurface()