[582091] Use model constraint to layout Regions

System property to enable the behavior:
-Dorg.eclipse.sirius.diagram.ui.internal.region.autosize.figure.optimized=true

We used to store the computed constraint during layout, but this make the
figures unable to adapt their size to the content in auto-size.
Behavior is wrong for the user: if he close and reopen the diagram (or
do some undo redo, or add new content) : the layout changes.

Bug: https://eclip.se/582091
Cherry-picked-from: https://eclip.se/582089
Change-Id: I9f28c92a705b549277a6e8534c1fb72ba3f38728
Signed-off-by: Maxime Porhel <maxime.porhel@obeo.fr>
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/AbstractDNodeContainerCompartmentEditPart.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/AbstractDNodeContainerCompartmentEditPart.java
index 534c015..c3d2730 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/AbstractDNodeContainerCompartmentEditPart.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/AbstractDNodeContainerCompartmentEditPart.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2022 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2009, 2023 THALES GLOBAL SERVICES and others.
  * 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
@@ -529,6 +529,9 @@
      * @author mporhel
      */
     public static class RegionContainerLayoutManager extends FreeFormLayoutEx {
+        
+        private static final boolean REGION_IMPROVED_AUTOSIZE_LAYOUT = Boolean.getBoolean("org.eclipse.sirius.diagram.ui.internal.region.autosize.figure.optimized"); //$NON-NLS-1$
+        
 
         private final boolean isVertical;
 
@@ -631,7 +634,9 @@
                     x += bounds.width;
                 }
 
-                setConstraint(f, bounds);
+                if(!REGION_IMPROVED_AUTOSIZE_LAYOUT) {
+                  setConstraint(f, bounds);
+                }
                 f.setBounds(bounds.translate(offset));
                 // For vertical stack, notify last region of the width change (it is useful only if the current figure f
                 // is also a region with HStack).
@@ -656,7 +661,9 @@
                 if (!isVertical && delta > 0) {
                     bounds = regionsBounds.get(last);
                     bounds.setWidth(bounds.width + delta);
-                    setConstraint(last, bounds);
+                    if(!REGION_IMPROVED_AUTOSIZE_LAYOUT) {
+                        setConstraint(last, bounds);
+                      }
                     last.setBounds(bounds.translate(offset));
                 }
             }