[549054] Add two system properties to allow to disable the optimizations

The activeParentLayers and uriFragment optimizations are enabled by
default.

But if a modeler needs to disable them this is now possible with the two
system properties added by this commit:
- "-Dorg.eclipse.sirius.common.enableUriFragmentOptimization=false"
- "-Dorg.eclipse.sirius.diagram.enableActiveParentLayerOptimization=false"

This commit also adds documentation about these two optimizations.

Bug: 549054
Change-Id: If77a4b41fd5184346f13c1fc7c07c1d6d566cabf
Signed-off-by: Maxime Porhel <maxime.porhel@obeo.fr>
diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/EqualityHelper.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/EqualityHelper.java
index 90a904f..80ed950 100644
--- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/EqualityHelper.java
+++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/EqualityHelper.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2018 THALES GLOBAL SERVICES.
+ * Copyright (c) 2009, 2019 THALES GLOBAL SERVICES.
  * 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
@@ -34,6 +34,8 @@
  */
 public final class EqualityHelper extends org.eclipse.emf.ecore.util.EcoreUtil.EqualityHelper {
 
+    private static final String ENABLE_URI_FRAGMENT_OPTIMIZATION_SYSTEM_PROPERTY = "org.eclipse.sirius.common.enableUriFragmentOptimization"; //$NON-NLS-1$
+
     private static boolean enableUriFragmentCache;
 
     private static final Map<EObject, Record> E_URI_FRAGMENT_CACHE = new ConcurrentHashMap<>();
@@ -156,11 +158,18 @@
      * Enable or disable the ability to cache the computed values. The cache is cleared when this method is called to
      * disable the cache.
      * 
+     * This method does nothing if the optimization has been disabled with the system property
+     * "org.eclipse.sirius.common.enableUriFragmentOptimization" set to false.
+     * 
      * @param enable
      *            <code>true</code> to allow this helper to put the computed values in a cache, <code>false</code>
      *            otherwise.
      */
     public static synchronized void setUriFragmentCacheEnabled(boolean enable) {
+        if (!Boolean.valueOf(System.getProperty(ENABLE_URI_FRAGMENT_OPTIMIZATION_SYSTEM_PROPERTY, "true"))) { //$NON-NLS-1$
+            return;
+        }
+
         enableUriFragmentCache = enable;
 
         if (!enable) {
diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/metamodel/helper/LayerHelper.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/metamodel/helper/LayerHelper.java
index a6e8152..9e16ad1 100644
--- a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/metamodel/helper/LayerHelper.java
+++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/metamodel/helper/LayerHelper.java
@@ -60,6 +60,8 @@
  */
 public final class LayerHelper {
 
+    private static final String ENABLE_ACTIVE_PARENT_LAYERS_OPTIMIZATION_SYSTEM_PROPERTY = "org.eclipse.sirius.diagram.enableActiveParentLayersOptimization"; //$NON-NLS-1$
+
     private static final Map<DiagramMappingsManager, Map<DiagramElementMapping, Collection<Layer>>> ACTIVE_PARENT_LAYER_CACHE = new ConcurrentHashMap<>();
 
     /**
@@ -345,6 +347,9 @@
      * Enable or disable the ability to cache the computed parent layers for the given DiagramMappingManager. The cache
      * is cleared when this method is called to disable the cache.
      * 
+     * This method does nothing if the optimization has been disabled with the system property
+     * "org.eclipse.sirius.diagram.enableActiveParentLayersOptimization" set to false.
+     * 
      * @param mappingsManager
      *            DiagramMappingsManager of the current diagram.
      * @param enable
@@ -352,6 +357,10 @@
      *            <code>false</code> otherwise.
      */
     public static synchronized void setActiveParentLayersCacheEnabled(DiagramMappingsManager mappingsManager, boolean enable) {
+        if (!Boolean.valueOf(System.getProperty(ENABLE_ACTIVE_PARENT_LAYERS_OPTIMIZATION_SYSTEM_PROPERTY, "true"))) { //$NON-NLS-1$
+            return;
+        }
+
         if (enable && !ACTIVE_PARENT_LAYER_CACHE.containsKey(mappingsManager)) {
             ACTIVE_PARENT_LAYER_CACHE.put(mappingsManager, new ConcurrentHashMap<>());
         }
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
index d0ead0e..dfa85e1 100644
--- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
+++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
@@ -66,7 +66,7 @@
 						<a href="#sirius6.1.1">Changes in Sirius 6.1.1</a>
 						<ol style="list-style: disc;">
 							<li>
-								<a href="#Changesinorg.eclipse.sirius.diagram3">Changes in  @org.eclipse.sirius.diagram@</a>
+								<a href="#Changesinorg.eclipse.sirius.diagram4">Changes in  @org.eclipse.sirius.diagram@</a>
 							</li>
 						</ol>
 					</li>
@@ -185,6 +185,30 @@
 				<code>DREPRESENTATION_DESCRIPTOR</code> has been removed because they are not available anymore in custom data.
 			</li>
 		</ul>
+		<h4 id="Changesinorg.eclipse.sirius.common">Changes in  
+			<code>org.eclipse.sirius.common</code>
+		</h4>
+		<ul>
+			<li><span class="label label-success">Added</span> A cache has been added to optimize the way the uri fragments are computed in 
+				<code>org.eclipse.sirius.common.tools.api.util.EqualityHelper</code>, it is managed with the 
+				<code>setUriFragmentCacheEnabled(boolean)</code> method. The cache is currently used in two locations: 
+				<code>org.eclipse.sirius.diagram.business.internal.sync.DDiagramSynchronizer.refreshOperation(IProgressMonitor)</code> and 
+				<code>org.eclipse.sirius.diagram.business.internal.helper.display.DisplayServiceImpl.refreshAllElementsVisibility(DDiagram)</code>. This optimization is enabled by default, it can be disabled by setting the system property 
+				<code>org.eclipse.sirius.common.enableUriFragmentOptimization</code> to 
+				<code>false</code>.
+			</li>
+		</ul>
+		<h4 id="Changesinorg.eclipse.sirius.diagram">Changes in  
+			<code>org.eclipse.sirius.diagram</code>
+		</h4>
+		<ul>
+			<li><span class="label label-success">Added</span> A cache has been added to optimize the way Sirius checks that a mapping is in the activated layers of a diagram. The cache is currently used in two locations: 
+				<code>org.eclipse.sirius.diagram.business.internal.sync.DDiagramSynchronizer.refreshOperation(IProgressMonitor)</code> and 
+				<code>org.eclipse.sirius.diagram.business.internal.helper.display.DisplayServiceImpl.refreshAllElementsVisibility(DDiagram)</code>.  This optimization is enabled by default, it can be disabled by setting the system property 
+				<code>org.eclipse.sirius.diagram.enableActiveParentLayerOptimization</code> to 
+				<code>false</code>.
+			</li>
+		</ul>
 		<h4 id="Changesinorg.eclipse.sirius.diagram.elk">Changes in  
 			<code>org.eclipse.sirius.diagram.elk</code>
 		</h4>
@@ -282,7 +306,7 @@
 			</li>
 		</ul>
 		<h3 id="DeveloperVisibleChanges3">Developer-Visible Changes</h3>
-		<h4 id="Changesinorg.eclipse.sirius.common">Changes in 
+		<h4 id="Changesinorg.eclipse.sirius.common2">Changes in 
 			<code>org.eclipse.sirius.common</code>
 		</h4>
 		<ul>
@@ -385,7 +409,7 @@
 				<code>org.eclipse.sirius.diagram.formatdata</code>
 			</li>
 		</ul>
-		<h4 id="Changesinorg.eclipse.sirius.diagram">Changes in  
+		<h4 id="Changesinorg.eclipse.sirius.diagram2">Changes in  
 			<code>org.eclipse.sirius.diagram</code>
 		</h4>
 		<ul>
@@ -695,7 +719,7 @@
 				<code>org.eclipse.sirius.diagram.ui.tools.api.layout.provider.AbstractLayoutProvider</code> has been made protected to allow to provide layout provider from other mechanism than LayoutService.
 			</li>
 		</ul>
-		<h4 id="Changesinorg.eclipse.sirius.diagram2">Changes in  
+		<h4 id="Changesinorg.eclipse.sirius.diagram3">Changes in  
 			<code>org.eclipse.sirius.diagram</code>
 		</h4>
 		<ul>
@@ -703,7 +727,7 @@
 				<code>org.eclipse.sirius.diagram.ui.tools.api.decoration.DecorationDescriptor.isPrintable</code>. This attribute is used to know if the decoration should be hidden when printing or exporting the diagram. The behavior is applied only if there is no printable decoration in its diagram element location (South, West, South-West etc).
 			</li>
 		</ul>
-		<h4 id="Changesinorg.eclipse.sirius.common2">Changes in  
+		<h4 id="Changesinorg.eclipse.sirius.common3">Changes in  
 			<code>org.eclipse.sirius.common</code>
 		</h4>
 		<ul>
@@ -720,7 +744,7 @@
 			</li>
 		</ul>
 		<h2 id="sirius6.1.1">Changes in Sirius 6.1.1</h2>
-		<h4 id="Changesinorg.eclipse.sirius.diagram3">Changes in  
+		<h4 id="Changesinorg.eclipse.sirius.diagram4">Changes in  
 			<code>org.eclipse.sirius.diagram</code>
 		</h4>
 		<ul>
@@ -1031,7 +1055,7 @@
 				<code>org.eclipse.sirius.ext.gmf.runtime.gef.ui.figures</code> package.
 			</li>
 		</ul>
-		<h4 id="Changesinorg.eclipse.sirius.common3">Changes in  
+		<h4 id="Changesinorg.eclipse.sirius.common4">Changes in  
 			<code>org.eclipse.sirius.common</code>
 		</h4>
 		<ul>
@@ -1164,7 +1188,7 @@
 				<code>SemanticBasedDecoration</code>.
 			</li>
 		</ul>
-		<h4 id="Changesinorg.eclipse.sirius.common4">Changes in 
+		<h4 id="Changesinorg.eclipse.sirius.common5">Changes in 
 			<code>org.eclipse.sirius.common</code>
 		</h4>
 		<ul>
@@ -1228,7 +1252,7 @@
 				<code>ToolMangament</code> mechanism used to handle tools and layer changes.
 			</li>
 		</ul>
-		<h4 id="Changesinorg.eclipse.sirius.diagram4">Changes in 
+		<h4 id="Changesinorg.eclipse.sirius.diagram5">Changes in 
 			<code>org.eclipse.sirius.diagram</code>
 		</h4>
 		<ul>
@@ -1603,7 +1627,7 @@
 				<code>DialectManagerImpl</code>.
 			</li>
 		</ul>
-		<h4 id="Changesinorg.eclipse.sirius.common5">Changes in 
+		<h4 id="Changesinorg.eclipse.sirius.common6">Changes in 
 			<code>org.eclipse.sirius.common</code>
 		</h4>
 		<ul>
@@ -1615,7 +1639,7 @@
 				<code>getFilesFromWorkspace(Collection&lt;IContainer&gt;, String)</code> to be more generic.
 			</li>
 		</ul>
-		<h4 id="Changesinorg.eclipse.sirius.diagram5">Changes in 
+		<h4 id="Changesinorg.eclipse.sirius.diagram6">Changes in 
 			<code>org.eclipse.sirius.diagram</code>
 		</h4>
 		<ul>
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
index 30c97de..8695e8e 100644
--- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
+++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
@@ -25,6 +25,14 @@
 * <span class="label label-info">Modified</span>The method @org.eclipse.sirius.business.api.dialect.AbstractRepresentationDialectServices.copyRepresentation(DRepresentation, String, Session, IProgressMonitor)@ has its first parameter changed from @DRepresentation@ to @DRepresentationDescriptor@. Also the constructor of @org.eclipse.sirius.business.api.dialect.command.CopyRepresentationCommand@ has been modified. Its parameter @Collection<DRepresentation> representations@ has been replaced by @Collection<DRepresentationDescriptor> representationDescriptors@. Theses changes were made  to be able to copy the name that is now only in @DRepresentationDescriptor@.
 * <span class="label label-danger">Removed</span> In @org.eclipse.sirius.business.api.session.CustomDataConstants@, the constants @DREPRESENTATION@ and @DREPRESENTATION_DESCRIPTOR@ has been removed because they are not available anymore in custom data.
 
+h4. Changes in  @org.eclipse.sirius.common@
+
+* <span class="label label-success">Added</span> A cache has been added to optimize the way the uri fragments are computed in @org.eclipse.sirius.common.tools.api.util.EqualityHelper@, it is managed with the @setUriFragmentCacheEnabled(boolean)@ method. The cache is currently used in two locations: @org.eclipse.sirius.diagram.business.internal.sync.DDiagramSynchronizer.refreshOperation(IProgressMonitor)@ and @org.eclipse.sirius.diagram.business.internal.helper.display.DisplayServiceImpl.refreshAllElementsVisibility(DDiagram)@. This optimization is enabled by default, it can be disabled by setting the system property @org.eclipse.sirius.common.enableUriFragmentOptimization@ to @false@.
+
+h4. Changes in  @org.eclipse.sirius.diagram@
+
+* <span class="label label-success">Added</span> A cache has been added to optimize the way Sirius checks that a mapping is in the activated layers of a diagram. The cache is currently used in two locations: @org.eclipse.sirius.diagram.business.internal.sync.DDiagramSynchronizer.refreshOperation(IProgressMonitor)@ and @org.eclipse.sirius.diagram.business.internal.helper.display.DisplayServiceImpl.refreshAllElementsVisibility(DDiagram)@.  This optimization is enabled by default, it can be disabled by setting the system property @org.eclipse.sirius.diagram.enableActiveParentLayerOptimization@ to @false@.
+
 h4. Changes in  @org.eclipse.sirius.diagram.elk@
 
 * <span class="label label-success">Added</span> The @org.eclipse.sirius.diagram.elk.layout.extension@ experimental extension-point has been added to make it possible to extend the ELK layout with pre end post operations. See the extension-point associated documentation and @org.eclipse.sirius.diagram.elk.IELKLayoutExtension@ interface for more details.