Add extension point to be able to configure which validation rules are
run on launch

Change-Id: I0196dc4f76711d19e88a743ab84d660a15201be2
Signed-off-by: Pauline DEVILLE <pauline.deville@cea.fr>
diff --git a/plugins/org.eclipse.papyrus.moka.kernel/META-INF/MANIFEST.MF b/plugins/org.eclipse.papyrus.moka.kernel/META-INF/MANIFEST.MF
index 7da678c..aa203d1 100644
--- a/plugins/org.eclipse.papyrus.moka.kernel/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.papyrus.moka.kernel/META-INF/MANIFEST.MF
@@ -11,7 +11,8 @@
 Export-Package: org.eclipse.papyrus.moka.kernel,
  org.eclipse.papyrus.moka.kernel.engine,
  org.eclipse.papyrus.moka.kernel.process,
- org.eclipse.papyrus.moka.kernel.service
+ org.eclipse.papyrus.moka.kernel.service,
+ org.eclipse.papyrus.moka.kernel.validation
 Bundle-Vendor: Eclipse Modeling Project
 Bundle-Version: 4.0.0.qualifier
 Bundle-Name: org.eclipse.papyrus.moka.kernel
diff --git a/plugins/org.eclipse.papyrus.moka.kernel/plugin.xml b/plugins/org.eclipse.papyrus.moka.kernel/plugin.xml
index 7893b2b..923d786 100644
--- a/plugins/org.eclipse.papyrus.moka.kernel/plugin.xml
+++ b/plugins/org.eclipse.papyrus.moka.kernel/plugin.xml
@@ -3,6 +3,7 @@
 <plugin>
    <extension-point id="engine" name="ExecutionEngine" schema="schema/engine.exsd"/>
    <extension-point id="service" name="service" schema="schema/service.exsd"/>
+   <extension-point id="validation" name="Validation" schema="schema/validation.exsd"/>
    <extension
          point="org.eclipse.ui.startup">
       <startup
diff --git a/plugins/org.eclipse.papyrus.moka.kernel/schema/validation.exsd b/plugins/org.eclipse.papyrus.moka.kernel/schema/validation.exsd
new file mode 100644
index 0000000..f460046
--- /dev/null
+++ b/plugins/org.eclipse.papyrus.moka.kernel/schema/validation.exsd
@@ -0,0 +1,179 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.papyrus.moka.kernel" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+      <appinfo>
+         <meta.schema plugin="org.eclipse.papyrus.moka.kernel" id="validation" name="Validation"/>
+      </appinfo>
+      <documentation>
+         Contributing to this extension point enables to register category of validation rules that must be run on launch of the simulation.
+      </documentation>
+   </annotation>
+
+   <element name="extension">
+      <annotation>
+         <appinfo>
+            <meta.element />
+         </appinfo>
+      </annotation>
+      <complexType>
+         <sequence minOccurs="1" maxOccurs="unbounded">
+            <element ref="validation" minOccurs="1" maxOccurs="unbounded"/>
+         </sequence>
+         <attribute name="point" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="id" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="name" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appinfo>
+                  <meta.attribute translatable="true"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="category">
+      <complexType>
+         <sequence minOccurs="0" maxOccurs="unbounded">
+            <element ref="excludeConstraint" minOccurs="0" maxOccurs="unbounded"/>
+            <element ref="excludeCategory" minOccurs="0" maxOccurs="unbounded"/>
+         </sequence>
+         <attribute name="categoryID" type="string" use="required">
+            <annotation>
+               <documentation>
+                  The Id of the category
+               </documentation>
+               <appinfo>
+                  <meta.attribute kind="identifier" basedOn="org.eclipse.emf.validation.constraintProviders/category/@id"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="excludeConstraint">
+      <complexType>
+         <attribute name="constraintID" type="string" use="required">
+            <annotation>
+               <documentation>
+                  The Id of the constraint to exclude
+               </documentation>
+               <appinfo>
+                  <meta.attribute kind="identifier" basedOn="org.eclipse.emf.validation.constraintProviders/constraintProvider/constraints/constraint/@id"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="context">
+      <complexType>
+         <attribute name="engineID" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="excludeCategory">
+      <complexType>
+         <attribute name="categoryID" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appinfo>
+                  <meta.attribute kind="identifier" basedOn="org.eclipse.emf.validation.constraintProviders/category/@id"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="validation">
+      <complexType>
+         <sequence minOccurs="1" maxOccurs="unbounded">
+            <element ref="category" minOccurs="1" maxOccurs="unbounded"/>
+            <element ref="context" minOccurs="1" maxOccurs="unbounded"/>
+         </sequence>
+      </complexType>
+   </element>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="since"/>
+      </appinfo>
+      <documentation>
+         [Enter the first release in which this extension point appears.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="examples"/>
+      </appinfo>
+      <documentation>
+         [Enter extension point usage example here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="apiinfo"/>
+      </appinfo>
+      <documentation>
+         [Enter API information here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="implementation"/>
+      </appinfo>
+      <documentation>
+         [Enter information about supplied implementation of this extension point.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="copyright"/>
+      </appinfo>
+      <documentation>
+         /*****************************************************************************
+ * Copyright (c) 2019 CEA LIST.
+ *
+ *    
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ *  CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+      </documentation>
+   </annotation>
+
+</schema>
diff --git a/plugins/org.eclipse.papyrus.moka.kernel/src/org/eclipse/papyrus/moka/kernel/validation/ValidationDescriptor.java b/plugins/org.eclipse.papyrus.moka.kernel/src/org/eclipse/papyrus/moka/kernel/validation/ValidationDescriptor.java
new file mode 100644
index 0000000..811f5c4
--- /dev/null
+++ b/plugins/org.eclipse.papyrus.moka.kernel/src/org/eclipse/papyrus/moka/kernel/validation/ValidationDescriptor.java
@@ -0,0 +1,61 @@
+/*****************************************************************************
+ * Copyright (c) 2019 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ *  CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.kernel.validation;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class ValidationDescriptor {
+
+	protected String category = "";
+
+	protected Set<String> excludedConstrains = new HashSet<String>();
+
+	protected Set<String> excludedCategories = new HashSet<String>();
+
+	public ValidationDescriptor() {
+	}
+
+	public ValidationDescriptor(String category) {
+		super();
+		this.category = category;
+	}
+
+	public String getCategory() {
+		return category;
+	}
+
+	public void setCategory(String category) {
+		this.category = category;
+	}
+
+	public Set<String> getExcludedConstrains() {
+		return excludedConstrains;
+	}
+
+	public void addExcludedConstraint(String constraint) {
+		excludedConstrains.add(constraint);
+	}
+
+	public Set<String> getExcludedCategories() {
+		return excludedCategories;
+	}
+
+	public void addExcludedCategory(String category) {
+		excludedCategories.add(category);
+	}
+
+}
diff --git a/plugins/org.eclipse.papyrus.moka.kernel/src/org/eclipse/papyrus/moka/kernel/validation/ValidationRegistry.java b/plugins/org.eclipse.papyrus.moka.kernel/src/org/eclipse/papyrus/moka/kernel/validation/ValidationRegistry.java
new file mode 100644
index 0000000..db08810
--- /dev/null
+++ b/plugins/org.eclipse.papyrus.moka.kernel/src/org/eclipse/papyrus/moka/kernel/validation/ValidationRegistry.java
@@ -0,0 +1,146 @@
+/*****************************************************************************
+ * Copyright (c) 2019 CEA LIST and others.
+ * 
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ *   CEA LIST - Initial API and implementation
+ *   
+ *****************************************************************************/
+
+package org.eclipse.papyrus.moka.kernel.validation;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+
+public class ValidationRegistry {
+
+	/**
+	 * Validation extension point id
+	 */
+	protected final static String MOKA_VALIDATION_EXTENSION_POINT_ID = "org.eclipse.papyrus.moka.kernel.validation";
+
+	/**
+	 * Validation extension point category child
+	 */
+	protected final static String VALIDATION_MAIN_CHILD = "validation";
+
+	/**
+	 * Validation extension point category child
+	 */
+	protected final static String VALIDATION_CATEGORY_CHILD = "category";
+
+	/**
+	 * Validation extension point excludeConstraint child
+	 */
+	protected final static String VALIDATION_CONTEXT_CHILD = "context";
+
+	/**
+	 * Validation extension point excludeConstraint child
+	 */
+	protected final static String VALIDATION_EXCLUDE_CONSTRAINT_CHILD = "excludeConstraint";
+
+	/**
+	 * Validation extension point excludeConstraint child
+	 */
+	protected final static String VALIDATION_EXCLUDE_CATEGORY_CHILD = "excludeCategory";
+
+	/**
+	 * Validation category id property name
+	 */
+	protected final static String VALIDATION_CATEGORY_ID_ATTRIBUTE = "categoryID";
+
+	/**
+	 * Validation extension point category child
+	 */
+	protected final static String VALIDATION_CONTEXT_ID_ATTRIBUTE = "engineID";
+
+	/**
+	 * Validation extension point category child
+	 */
+	protected final static String VALIDATION_EXCLUDE_CONSTRAINT_ID_ATTRIBUTE = "constraintID";
+
+	/**
+	 * Map associating engine ID to the ValidationRule
+	 */
+	protected Map<String, Set<ValidationDescriptor>> registry;
+
+	/**
+	 * The service registry is a singleton
+	 */
+	private static ValidationRegistry INSTANCE;
+
+	private ValidationRegistry() {
+		this.registry = new HashMap<String, Set<ValidationDescriptor>>();
+		loadValidations();
+	}
+
+	public static ValidationRegistry getInstance() {
+		if (INSTANCE == null) {
+			INSTANCE = new ValidationRegistry();
+		}
+		return INSTANCE;
+	}
+
+	protected void loadValidations() {
+		// Instantiate registered validation extension point
+		IExtensionRegistry registry = Platform.getExtensionRegistry();
+		IConfigurationElement[] configurations = registry
+				.getConfigurationElementsFor(MOKA_VALIDATION_EXTENSION_POINT_ID);
+		for (int i = 0; i < configurations.length; i++) {
+			IConfigurationElement config = configurations[i];
+			IConfigurationElement[] contexts = config.getChildren(VALIDATION_CONTEXT_CHILD);
+			IConfigurationElement[] categories = config.getChildren(VALIDATION_CATEGORY_CHILD);
+			for (int j = 0; j < categories.length; j++) {
+				String category = categories[j].getAttribute(VALIDATION_CATEGORY_ID_ATTRIBUTE); 
+				ValidationDescriptor validationDescriptor = new ValidationDescriptor(category);
+				IConfigurationElement[] excludeConstraints = categories[j].getChildren(VALIDATION_EXCLUDE_CONSTRAINT_CHILD);
+				for (int k = 0; k < excludeConstraints.length; k++) {
+					String constraint = excludeConstraints[k].getAttribute(VALIDATION_EXCLUDE_CONSTRAINT_ID_ATTRIBUTE);
+					validationDescriptor.addExcludedConstraint(constraint);
+				}
+				IConfigurationElement[] excludeCategories = categories[j].getChildren(VALIDATION_EXCLUDE_CATEGORY_CHILD);
+				for (int k = 0; k < excludeCategories.length; k++) {
+					String excludeCategory = excludeCategories[k].getAttribute(VALIDATION_CATEGORY_ID_ATTRIBUTE);	
+					validationDescriptor.addExcludedCategory(excludeCategory);
+				}
+				
+				for (int k = 0; k < contexts.length; k++) {
+					String contextID = contexts[k].getAttribute(VALIDATION_CONTEXT_ID_ATTRIBUTE);
+					addToRegistry(contextID, validationDescriptor);
+				}
+			}
+		}
+	}
+	
+	public Set<ValidationDescriptor> getValidationDescriptors(String engineID) {
+		return registry.get(engineID);
+	}
+
+	private void addToRegistry(String contextID, ValidationDescriptor validationDescriptor) {
+		Set<ValidationDescriptor> descriptors = registry.get(contextID);
+		if(registry.get(contextID) == null) {
+			descriptors = new HashSet<ValidationDescriptor>();
+			descriptors.add(validationDescriptor);
+			registry.put(contextID, descriptors);
+		} else {
+			descriptors.add(validationDescriptor);
+		}
+	}
+
+	public void clear() {
+		registry.clear();
+	}
+
+}
diff --git a/plugins/org.eclipse.papyrus.moka.pssm.validation/src/org/eclipse/papyrus/moka/pssm/validation/constraints/PssmExpressionOnlyForElseConstraint.java b/plugins/org.eclipse.papyrus.moka.pssm.validation/src/org/eclipse/papyrus/moka/pssm/validation/constraints/PssmExpressionOnlyForElseConstraint.java
index 830d978..236496c 100644
--- a/plugins/org.eclipse.papyrus.moka.pssm.validation/src/org/eclipse/papyrus/moka/pssm/validation/constraints/PssmExpressionOnlyForElseConstraint.java
+++ b/plugins/org.eclipse.papyrus.moka.pssm.validation/src/org/eclipse/papyrus/moka/pssm/validation/constraints/PssmExpressionOnlyForElseConstraint.java
@@ -16,25 +16,29 @@
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.emf.validation.AbstractModelConstraint;
 import org.eclipse.emf.validation.IValidationContext;
+import org.eclipse.uml2.uml.Constraint;
 import org.eclipse.uml2.uml.Expression;
+import org.eclipse.uml2.uml.Transition;
 
 /**
  * pssm_expression_only_for_else
  * 
- * The Expression must have no operands and its symbol must be “else”.
- * context UML::Values::Expression inv:
- * self.symbol = 'else' and self.operand->isEmpty()
+ * The Expression must have no operands and its symbol must be “else”. context
+ * UML::Values::Expression inv: self.symbol = 'else' and self.operand->isEmpty()
  */
 public class PssmExpressionOnlyForElseConstraint extends AbstractModelConstraint {
 
 	@Override
 	public IStatus validate(IValidationContext ctx) {
 		Expression target = (Expression) ctx.getTarget();
-		Boolean expression = target.getSymbol().equals("else") 
-				&& target.getOperands().isEmpty();
-		if (!expression) {
-			return ctx.createFailureStatus("Expression - The Expression must have no operands and its symbol must be “else”.");
+		if (target.getOwner() instanceof Constraint && target.getOwner().getOwner() instanceof Transition) { // ADD from original constraint
+			Boolean expression = "else".equals(target.getSymbol()) && target.getOperands().isEmpty();
+			if (!expression) {
+				return ctx.createFailureStatus(
+						"Expression - The Expression must have no operands and its symbol must be “else”.");
+			}
 		}
 		return ctx.createSuccessStatus();
 	}
+	
 }
\ No newline at end of file
diff --git a/plugins/org.eclipse.papyrus.moka.ui/plugin.xml b/plugins/org.eclipse.papyrus.moka.ui/plugin.xml
index 886e299..e1a8a15 100644
--- a/plugins/org.eclipse.papyrus.moka.ui/plugin.xml
+++ b/plugins/org.eclipse.papyrus.moka.ui/plugin.xml
@@ -286,5 +286,28 @@
             name="Moka Debug Perspective">
       </perspective>
    </extension>
+   <extension
+         point="org.eclipse.papyrus.moka.kernel.validation">
+      <validation>
+	      <context
+	            engineID="org.eclipse.papyrus.moka.engine.uml">
+	      </context>
+	      <context
+	            engineID="org.eclipse.papyrus.moka.engine.uml.time">
+	      </context>
+	      <category
+	            categoryID="org.eclipse.papyrus.moka.fuml.validation.nonnormative">
+	      </category>
+	      <category
+	            categoryID="org.eclipse.papyrus.moka.fuml.validation.normative">
+	      </category>
+	      <category
+	            categoryID="org.eclipse.papyrus.moka.pscs.validation.normative">
+	      </category>
+	      <category
+	            categoryID="org.eclipse.papyrus.moka.pssm.validation.normative">
+	      </category>
+      </validation>
+   </extension>
 
 </plugin>
diff --git a/plugins/org.eclipse.papyrus.moka.ui/src/org/eclipse/papyrus/moka/launch/ExecutionEngineLaunchDelegate.java b/plugins/org.eclipse.papyrus.moka.ui/src/org/eclipse/papyrus/moka/launch/ExecutionEngineLaunchDelegate.java
index 59a26c6..452f0b8 100644
--- a/plugins/org.eclipse.papyrus.moka.ui/src/org/eclipse/papyrus/moka/launch/ExecutionEngineLaunchDelegate.java
+++ b/plugins/org.eclipse.papyrus.moka.ui/src/org/eclipse/papyrus/moka/launch/ExecutionEngineLaunchDelegate.java
@@ -91,7 +91,7 @@
 		return canRunServer;
 	}
 
-	private boolean isValidationOk(EngineConfiguration engineConfiguration, IProgressMonitor monitor) {
+	private boolean isValidationOk(EngineConfiguration engineConfiguration, IProgressMonitor monitor, String engineID) {
 		// If the preference allow to run model validation before the launch, the
 		// validation is run. If there are errors, the system ask the user if he/she
 		// still wants to run the simulation.
@@ -101,7 +101,7 @@
 		boolean mustValidate = store.getBoolean(MODEL_VALIDATION_ON_LAUNCH);
 		boolean continueSimulation = true;
 		if (mustValidate) {
-			continueSimulation = ValidationUtil.validateModel(engineConfiguration, monitor);
+			continueSimulation = ValidationUtil.validateModel(engineConfiguration, monitor, engineID);
 		}
 		return continueSimulation;
 	}
@@ -130,7 +130,7 @@
 					modelSet = initializeModelingEnvironment(cr, progressMonitor.split(2));
 					if (modelSet != null) {
 						engineConfiguration = createConfiguration(cr, modelSet);
-						if (isValidationOk(engineConfiguration, progressMonitor)) {
+						if (isValidationOk(engineConfiguration, progressMonitor, reader.getExecutionEngineID())) {
 							prechecks = true;
 						}
 					} else {
diff --git a/plugins/org.eclipse.papyrus.moka.ui/src/org/eclipse/papyrus/moka/ui/validation/ValidationUtil.java b/plugins/org.eclipse.papyrus.moka.ui/src/org/eclipse/papyrus/moka/ui/validation/ValidationUtil.java
index 970ee2e..d3dd200 100644
--- a/plugins/org.eclipse.papyrus.moka.ui/src/org/eclipse/papyrus/moka/ui/validation/ValidationUtil.java
+++ b/plugins/org.eclipse.papyrus.moka.ui/src/org/eclipse/papyrus/moka/ui/validation/ValidationUtil.java
@@ -15,11 +15,16 @@
  *****************************************************************************/
 package org.eclipse.papyrus.moka.ui.validation;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Set;
 import java.util.SortedSet;
+import java.util.stream.Collectors;
 
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
@@ -40,6 +45,7 @@
 import org.eclipse.papyrus.infra.services.validation.IPapyrusDiagnostician;
 import org.eclipse.papyrus.infra.services.validation.internal.ValidationRegistry;
 import org.eclipse.papyrus.moka.kernel.engine.EngineConfiguration;
+import org.eclipse.papyrus.moka.kernel.validation.ValidationDescriptor;
 import org.eclipse.swt.widgets.Display;
 
 @SuppressWarnings("restriction")
@@ -49,23 +55,35 @@
 
 	private static Map<String, Boolean> storePreferenceValue = new HashMap<>();
 
+	private static Set<String> valideRules = new HashSet<>();
+
 	static {
 		// Make sure that every constraint are load in preferences to be able to
 		// deactivate none moka constraint
 		ModelValidationService.getInstance().loadXmlConstraintDeclarations();
 	}
 
-	public static boolean validateModel(EngineConfiguration engineConfiguration, IProgressMonitor monitor) {
+	public static boolean validateModel(EngineConfiguration engineConfiguration, IProgressMonitor monitor,
+			String engineID) {
 		// This method run the validation and should return true if the validation
 		// should continue of false otherwise.
+		// (from the validation result we remove rules which are mandatory according to
+		// the EMF framework)
 		// According to the validation result :
 		// 1] there is no error in the model, then the simulation should continue
 		// 2] there are errors in the model, then a dialog is display to show errors,
 		// the user can still decide to continue the simulation :
 		// 2.1] the user cancel, then the simulation is stopped
 		// 2.2] the user click on the user button the validation continue
-		Diagnostic diagnostic = validate(monitor, engineConfiguration.getExecutionSource().getModel());
-		boolean isThereErrors = diagnostic.getChildren().stream().anyMatch(d -> d.getSeverity() == Diagnostic.ERROR);
+		Diagnostic diagnostic = validate(monitor, engineConfiguration.getExecutionSource().getModel(), engineID);
+
+		List<Diagnostic> filteredConstraints = new ArrayList<>(diagnostic.getChildren());
+		filteredConstraints = filteredConstraints.stream().filter(d -> valideRules.contains(d.getSource()))
+				.collect(Collectors.toList());
+		Diagnostic filteredDiagnostics = new BasicDiagnostic(diagnostic.getSource(), diagnostic.getCode(),
+				filteredConstraints, diagnostic.getMessage(), diagnostic.getData().toArray());
+		boolean isThereErrors = filteredDiagnostics.getChildren().stream()
+				.anyMatch(d -> d.getSeverity() == Diagnostic.ERROR);
 		dialogResult = true;
 		if (isThereErrors) {
 			Display.getDefault().syncExec(new Runnable() {
@@ -73,8 +91,8 @@
 				public void run() {
 					ValidationDiagnosticDialog dialog = new ValidationDiagnosticDialog(
 							Display.getCurrent().getActiveShell(), "Moka Validation",
-							"The moka validation detect errors on the model. Do you  still want to launch the simulation ?",
-							diagnostic, IStatus.ERROR);
+							"The moka validation detect errors on the model. Do you still want to launch the simulation ?",
+							filteredDiagnostics, IStatus.ERROR);
 					if (dialog.open() == Window.OK) {
 						ValidationUtil.dialogResult = true;
 					} else {
@@ -86,12 +104,13 @@
 		return dialogResult;
 	}
 
-	protected static Diagnostic validate(IProgressMonitor progressMonitor, EObject validateElement) {
+	protected static Diagnostic validate(IProgressMonitor progressMonitor, EObject validateElement, String engineID) {
 		// ValidateThe model according to moka validation rules
 		// 1] disable non moka validation rules in preferences (save old preferences)
 		// 2] validate
 		// 3] restore validation preference
-		removeNonMokaValidationRulesFromPreferences();
+		clear();
+		setValidationPreferencesForMokaSimulation(engineID);
 		int validationSteps = 0;
 		for (Iterator<?> i = validateElement.eAllContents(); i.hasNext(); i.next()) {
 			++validationSteps;
@@ -119,37 +138,86 @@
 		return diagnostic;
 	}
 
-	protected static void removeNonMokaValidationRulesFromPreferences() {
+	protected static void setValidationPreferencesForMokaSimulation(String engineID) {
 		// Since we should run only moka validation then we have to modified preferences
-		// to keep only moka constraints, at the same time the odl values of preferences
+		// to keep only moka constraints, at the same time the old values of preferences
 		// are store to be reused later
-		storePreferenceValue.clear();
 		SortedSet<Category> categories = CategoryManager.getInstance().getTopLevelCategories();
+		Set<ValidationDescriptor> validationDescriptors = org.eclipse.papyrus.moka.kernel.validation.ValidationRegistry
+				.getInstance().getValidationDescriptors(engineID);
 		Iterator<Category> categoryIter = categories.iterator();
 		while (categoryIter.hasNext()) {
 			Category category = (Category) categoryIter.next();
-			removeNonMokaValidationRulesFromPreferences(category);
+			checkCategory(category, validationDescriptors);
 		}
 	}
 
-	protected static void removeNonMokaValidationRulesFromPreferences(Category category) {
-		String categoryId = category.getId();
-		if (false == categoryId.startsWith("org.eclipse.papyrus.moka")) {
-			// Manage constraints
-			Iterator<IConstraintDescriptor> constraintsIter = category.getConstraints().iterator();
-			while (constraintsIter.hasNext()) {
-				IConstraintDescriptor constraint = constraintsIter.next();
-				storePreferenceValue.put(constraint.getId(),
-						EMFModelValidationPreferences.isConstraintDisabled(constraint.getId()));
-				EMFModelValidationPreferences.setConstraintDisabled(constraint.getId(), true);
-			}
-			// Manage sub categories
-			Iterator<Category> categoryiesIter = category.getChildren().iterator();
-			while (categoryiesIter.hasNext()) {
-				Category subCategory = (Category) categoryiesIter.next();
-				removeNonMokaValidationRulesFromPreferences(subCategory);
+	protected static void checkCategory(Category category, Set<ValidationDescriptor> validDescriptors) {
+		// Set preferences for every constraints which are not in accepted category or
+		// which are excluded
+		boolean categoryFound = false;
+		for (Iterator<ValidationDescriptor> iterator = validDescriptors.iterator(); iterator.hasNext();) {
+			ValidationDescriptor validationDescriptor = (ValidationDescriptor) iterator.next();
+			if (validationDescriptor.getCategory().equals(category.getId())) { // accepted category
+				for (Iterator<IConstraintDescriptor> constrainIter = category.getConstraints().iterator(); constrainIter
+						.hasNext();) {
+					IConstraintDescriptor constraintDescriptor = (IConstraintDescriptor) constrainIter.next();
+					checkConstraint(constraintDescriptor, validationDescriptor);
+				}
+				// Sub category
+				for (Iterator<Category> categoryIter = category.getChildren().iterator(); categoryIter.hasNext();) {
+					Category subCategory = (Category) categoryIter.next();
+					if (shouldExcludeSubCategory(subCategory, validationDescriptor)) {
+						excludeCategory(subCategory);
+					}
+				}
+				categoryFound = true;
 			}
 		}
+		if(false == categoryFound) {
+			excludeCategory(category);
+		}
+	}
+
+	protected static boolean shouldExcludeSubCategory(Category subCategory, ValidationDescriptor validationDescriptor) {
+		// Check is the category is exclude according to the validationDescriptor
+		for (Iterator<String> iterator = validationDescriptor.getExcludedCategories().iterator(); iterator.hasNext();) {
+			String categoryID = (String) iterator.next();
+			if (categoryID.equals(subCategory.getId())) {
+				return true;
+			}
+		}
+		return false;
+	}
+
+	protected static void excludeCategory(Category category) {
+		// Exclude every constraint directly or not owned by this category  
+		// 1] Disable every constraints
+		for (Iterator<IConstraintDescriptor> constrainIter = category.getConstraints().iterator(); constrainIter
+				.hasNext();) {
+			IConstraintDescriptor constraintDescriptor = (IConstraintDescriptor) constrainIter.next();
+			excludeConstraint(constraintDescriptor);
+		}
+		// 2] Exclude sub category
+		for (Iterator<Category> iterator = category.getChildren().iterator(); iterator.hasNext();) {
+			Category subCategory = (Category) iterator.next();
+			excludeCategory(subCategory);
+		}
+	}
+
+	protected static void checkConstraint(IConstraintDescriptor constraintDescriptor,
+			ValidationDescriptor validationDescriptor) {
+		// Set preference if the constraint is exclude in the validationDescriptor
+		if (validationDescriptor.getExcludedConstrains().contains(constraintDescriptor.getId())) {
+			excludeConstraint(constraintDescriptor);
+		} else {
+			valideRules.add(constraintDescriptor.getId());
+		}
+	}
+
+	protected static void excludeConstraint(IConstraintDescriptor constraintDescriptor) {
+		storePreferenceValue.put(constraintDescriptor.getId(), EMFModelValidationPreferences.isConstraintDisabled(constraintDescriptor.getId()));
+		EMFModelValidationPreferences.setConstraintDisabled(constraintDescriptor.getId(), true);
 	}
 
 	protected static void restoreOldPreferences() {
@@ -160,5 +228,10 @@
 			EMFModelValidationPreferences.setConstraintDisabled(entry.getKey(), entry.getValue());
 		}
 	}
+	
+	protected static void clear() {
+		storePreferenceValue.clear();
+		valideRules.clear();
+	}
 
 }