diff options
| author | Maxime Porhel | 2016-02-15 15:07:13 +0000 |
|---|---|---|
| committer | Maxime Porhel | 2016-03-01 14:48:59 +0000 |
| commit | a3820d0a236e45be6b63482f31a9aa5c42d81c18 (patch) | |
| tree | 0e878d49df5cac8e31bb66ee221d0586173f9518 | |
| parent | 8ee4b66d913ac0662e4cab7201c860192d243cc1 (diff) | |
| download | org.eclipse.sirius-a3820d0a236e45be6b63482f31a9aa5c42d81c18.tar.gz org.eclipse.sirius-a3820d0a236e45be6b63482f31a9aa5c42d81c18.tar.xz org.eclipse.sirius-a3820d0a236e45be6b63482f31a9aa5c42d81c18.zip | |
[488575] Correctly configure border and margin of list regions
Configure the list compartment with the same margin and layout manager
than the non-region lists.
Bug: 488575
Change-Id: Ia7b2dadf921ff5e0663491d1aa458ec78b711288
Signed-off-by: Maxime Porhel <maxime.porhel@obeo.fr>
2 files changed, 29 insertions, 6 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/AbstractDNodeListCompartmentEditPart.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/AbstractDNodeListCompartmentEditPart.java index 9edbe16c8a..19b860813f 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/AbstractDNodeListCompartmentEditPart.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/AbstractDNodeListCompartmentEditPart.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2015 THALES GLOBAL SERVICES and others. + * Copyright (c) 2011, 2016 THALES GLOBAL SERVICES and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -17,6 +17,7 @@ import java.util.Iterator; import java.util.List; import java.util.Set; +import org.eclipse.draw2d.Border; import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.LineBorder; import org.eclipse.draw2d.MarginBorder; @@ -142,11 +143,22 @@ public abstract class AbstractDNodeListCompartmentEditPart extends ListCompartme @Override public IFigure createFigure() { ResizableCompartmentFigure result = (ResizableCompartmentFigure) super.createFigure(); - if (new DDiagramElementContainerExperimentalQuery((DDiagramElementContainer) resolveSemanticElement()).isRegion()) { + boolean isRegion = new DDiagramElementContainerExperimentalQuery((DDiagramElementContainer) resolveSemanticElement()).isRegion(); + if (isRegion) { // Use a NestableResizableCompartmentFigure to have collapsed Region // to have only the label area visible ResizableCompartmentFigure nrcf = new NestedResizableCompartmentFigure(getMapMode()); - nrcf.getContentPane().setLayoutManager(result.getLayoutManager()); + // Configure the text pane layout manager to be the same as the + // non-region case. + nrcf.getContentPane().setLayoutManager(result.getContentPane().getLayoutManager()); + // Get the viewport border computed for the non-region case to keep + // the same margin: + Border border = result.getScrollPane().getContents().getBorder(); + if (border instanceof MarginBorder) { + Insets insets = border.getInsets(nrcf); + border = new MarginBorder(0, insets.left, 0, insets.right); + nrcf.getScrollPane().getContents().setBorder(border); + } result = nrcf; } @@ -158,11 +170,11 @@ public abstract class AbstractDNodeListCompartmentEditPart extends ListCompartme // Now that the border size is taken into account to calculate border // margin; reduce the scroll pane insets to retrieve the previous // minimum/preferred size, scroll-bar visibility condition for one pixel - // borders. + // borders. Impact only horizontal insets for regions. IFigure contentPane = result.getContentPane(); if (contentPane != null && contentPane.getBorder() instanceof MarginBorder) { Insets insets = contentPane.getBorder().getInsets(result); - Insets legacyBorderCompensation = new Insets(0, -1, -1, -1); + Insets legacyBorderCompensation = new Insets(0, -1, isRegion ? 0 : -1, -1); contentPane.setBorder(new MarginBorder(insets.getAdded(legacyBorderCompensation))); } return result; diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/compartment/CompartmentsLayoutTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/compartment/CompartmentsLayoutTest.java index 755f0337e4..06728d2147 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/compartment/CompartmentsLayoutTest.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/compartment/CompartmentsLayoutTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Obeo. + * Copyright (c) 2015, 2016 Obeo. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -62,6 +62,8 @@ import org.eclipse.sirius.diagram.ui.business.internal.edit.helpers.LabelAlignme import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramContainerEditPart; import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramElementContainerEditPart; import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramNameEditPart; +import org.eclipse.sirius.diagram.ui.edit.api.part.IDiagramContainerEditPart; +import org.eclipse.sirius.diagram.ui.edit.api.part.IDiagramListEditPart; import org.eclipse.sirius.diagram.ui.internal.edit.parts.AbstractDNodeContainerCompartmentEditPart; import org.eclipse.sirius.diagram.ui.internal.edit.parts.AbstractDiagramElementContainerNameEditPart; import org.eclipse.sirius.diagram.ui.tools.api.figure.AlphaDropShadowBorder; @@ -247,6 +249,15 @@ public class CompartmentsLayoutTest extends SiriusDiagramTestCase implements ICo assertEquals("Wrong GMF bounds for " + label, expectedGmfBounds, getBounds((Node) editPart.getNotationView())); assertEquals("Wrong Draw2D bounds for " + label, expectedFigureBounds, mainFigure.getBounds()); + + ResizableCompartmentEditPart compartmentEditPart = (ResizableCompartmentEditPart) editPart.getChildren().get(1); + Border border = compartmentEditPart.getContentPane().getBorder(); + + if (editPart instanceof IDiagramListEditPart) { + assertEquals("Wrong border margin for " + label, new Insets(0, 4, editPart.isRegion() ? 0 : 1, 4), border.getInsets(null)); + } else if (editPart instanceof IDiagramContainerEditPart) { + assertNull("Wrong border for " + label + ": the BorderItemsAwareFreeFormLayer used as content pane of a freeform region should not have a border.", border); + } } private Rectangle getBounds(Node notationView) { |
