Bug 507763: [CDO] CDOAwareModelSet adds invalidationListener multiple times

Change-Id: If81661520959c49fe10a301ace6e3232b7754146
Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
diff --git a/cdo/bundles/org.eclipse.papyrus.cdo.core/META-INF/MANIFEST.MF b/cdo/bundles/org.eclipse.papyrus.cdo.core/META-INF/MANIFEST.MF
index 3cebc62..b87f3bb 100755
--- a/cdo/bundles/org.eclipse.papyrus.cdo.core/META-INF/MANIFEST.MF
+++ b/cdo/bundles/org.eclipse.papyrus.cdo.core/META-INF/MANIFEST.MF
@@ -60,7 +60,7 @@
 Bundle-Vendor: %providerName
 Bundle-ActivationPolicy: lazy
 Bundle-ClassPath: .
-Bundle-Version: 2.0.0.qualifier
+Bundle-Version: 2.0.1.qualifier
 Bundle-Localization: plugin
 Bundle-Name: %pluginName
 Bundle-Activator: org.eclipse.papyrus.cdo.internal.core.Activator
diff --git a/cdo/bundles/org.eclipse.papyrus.cdo.core/pom.xml b/cdo/bundles/org.eclipse.papyrus.cdo.core/pom.xml
index d51e817..c6eea78 100755
--- a/cdo/bundles/org.eclipse.papyrus.cdo.core/pom.xml
+++ b/cdo/bundles/org.eclipse.papyrus.cdo.core/pom.xml
@@ -1,17 +1,18 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 	<modelVersion>4.0.0</modelVersion>
-	
+
 	<!-- Parent of this POM -->
 	<parent>
 		<groupId>org.eclipse.papyrus.cdo</groupId>
 		<artifactId>org.eclipse.papyrus.cdo-bundles</artifactId>
 		<version>1.2.0-SNAPSHOT</version>
 	</parent>
-	
+
 	<!-- Project POM -->
 	<artifactId>org.eclipse.papyrus.cdo.core</artifactId>
-	<version>2.0.0-SNAPSHOT</version>
+	<version>2.0.1-SNAPSHOT</version>
 	<packaging>eclipse-plugin</packaging>
 </project>
\ No newline at end of file
diff --git a/cdo/bundles/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/core/resource/CDOAwareModelSet.java b/cdo/bundles/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/core/resource/CDOAwareModelSet.java
index d72736b..6c277e4 100755
--- a/cdo/bundles/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/core/resource/CDOAwareModelSet.java
+++ b/cdo/bundles/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/core/resource/CDOAwareModelSet.java
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Copyright (c) 2013, 2017 CEA LIST, Christian W. Damus, and others.
+ * Copyright (c) 2013, 2017, 2019 CEA LIST, Christian W. Damus, and others.
  *
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -16,11 +16,12 @@
  *   Christian W. Damus - bug 436998
  *   Eike Stepper (CEA) - bug 466520
  *   Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905
- *
+ *   Vincent LORENZO (CEA) - bug 507763
  *****************************************************************************/
 package org.eclipse.papyrus.cdo.core.resource;
 
 import java.io.IOException;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.EnumSet;
@@ -223,8 +224,11 @@
 			view = cdoResource.cdoView();
 
 			if (view != null) {
-				view.addListener(getInvalidationListener());
-				checkout = CDOExplorerUtil.getCheckout(view);
+				final IListener invalidationListener = getInvalidationListener();
+				if (false == Arrays.asList(view.getListeners()).contains(invalidationListener)) {
+					view.addListener(getInvalidationListener());
+					checkout = CDOExplorerUtil.getCheckout(view);
+				}
 
 				// URI from = URI.createURI("cdo://" + view.getSession().getRepositoryInfo().getName() + "/");
 				// URI to = URI.createURI("cdo.checkout://" + checkout.getID() + "/" + checkout.getRepository().getID() + "/");
@@ -248,8 +252,7 @@
 			try {
 				super.unload();
 			} catch (Exception ex) {
-				if (logError)
-				{
+				if (logError) {
 					Activator.log.error(ex);
 				}
 			} finally {
@@ -270,18 +273,19 @@
 	}
 
 	protected IListener createInvalidationListener() {
-		return new IListener() {
+		return new InvalidationListener();
+	}
 
-			@Override
-			public void notifyEvent(IEvent event) {
-				if (event instanceof CDOViewInvalidationEvent) {
-					TransactionalEditingDomain domain = getTransactionalEditingDomain();
-					if (domain instanceof CDOAwareTransactionalEditingDomain) {
-						((CDOAwareTransactionalEditingDomain) domain).fireResourceSetChanged((CDOViewInvalidationEvent) event);
-					}
+	private class InvalidationListener implements IListener {
+		@Override
+		public void notifyEvent(IEvent event) {
+			if (event instanceof CDOViewInvalidationEvent) {
+				TransactionalEditingDomain domain = getTransactionalEditingDomain();
+				if (domain instanceof CDOAwareTransactionalEditingDomain) {
+					((CDOAwareTransactionalEditingDomain) domain).fireResourceSetChanged((CDOViewInvalidationEvent) event);
 				}
 			}
-		};
+		}
 	}
 
 	@Override
diff --git a/cdo/bundles/org.eclipse.papyrus.cdo.ui.customization.properties/pom.xml b/cdo/bundles/org.eclipse.papyrus.cdo.ui.customization.properties/pom.xml
index a9557dc..3cb856f 100755
--- a/cdo/bundles/org.eclipse.papyrus.cdo.ui.customization.properties/pom.xml
+++ b/cdo/bundles/org.eclipse.papyrus.cdo.ui.customization.properties/pom.xml
@@ -1,8 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 	<modelVersion>4.0.0</modelVersion>
-	
+
 	<!-- Parent of this POM -->
 	<parent>
 		<groupId>org.eclipse.papyrus.cdo</groupId>