Skip to content

Commit

Permalink
[518] Add dynamic margin property check on interaction container tests
Browse files Browse the repository at this point in the history
A system property has been introduced to choose if the left side of the
'interaction container' show dynamically follow the first (most-left)
element or be fixed. The Interaction container swtbot test now check
both modes.

Bug: #518
Signed-off-by: Steve Monnier <[email protected]>
  • Loading branch information
SteveMonnier committed Dec 19, 2024
1 parent d6ffec1 commit 846c236
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class SequenceHorizontalLayout extends AbstractSequenceOrderingLayout<ISe
* of the interaction container not on x=0, but positioned to the left of the first interaction container (with
* margin).
*/
private static final boolean INTERACTION_CONTAINER_DYNAMIC_LEFT = Boolean.getBoolean("org.eclipse.sirius.diagram.sequence.layout.interaction.container.dynamic.left"); //$NON-NLS-1$
public static final String INTERACTION_CONTAINER_DYNAMIC_LEFT_PROPERTY_NAME = "org.eclipse.sirius.diagram.sequence.layout.interaction.container.dynamic.left"; //$NON-NLS-1$

private static final Function<Rectangle, Integer> RECT_TO_X = new Function<Rectangle, Integer>() {
@Override
Expand Down Expand Up @@ -560,7 +560,7 @@ private int getLifelineLeftGap(Lifeline lifeline, Range zone, int irWidth, Map<L
private Rectangle computeInteractionContainerLayout(InteractionContainer interactionContainer, Map<? extends ISequenceElement, Rectangle> bounds, Map<LostMessageEnd, Integer> lostEndsDelta) {
// Reset width of the interaction container
Rectangle rectangle = new Rectangle(-1, 0, InteractionContainer.DEFAULT_WIDTH, InteractionContainer.DEFAULT_HEIGHT);
if (INTERACTION_CONTAINER_DYNAMIC_LEFT) {
if (Boolean.getBoolean(INTERACTION_CONTAINER_DYNAMIC_LEFT_PROPERTY_NAME)) {
rectangle.setX(-1);
}

Expand All @@ -583,7 +583,7 @@ private Rectangle computeInteractionContainerLayout(InteractionContainer interac
rectangle.setRight(right);
}

if (INTERACTION_CONTAINER_DYNAMIC_LEFT) {
if (Boolean.getBoolean(INTERACTION_CONTAINER_DYNAMIC_LEFT_PROPERTY_NAME)) {
int left = sequenceElementRectangle.x() - InteractionContainer.MARGIN;
if (left < rectangle.x() || rectangle.x() == -1) {
if (rectangle.x() == -1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) CEA.
* Copyright 2024 (c) CEA.
* 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
Expand All @@ -19,14 +19,19 @@
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.eclipse.sirius.diagram.DDiagram;
import org.eclipse.sirius.diagram.sequence.business.internal.elements.InteractionContainer;
import org.eclipse.sirius.diagram.sequence.business.internal.layout.LayoutConstants;
import org.eclipse.sirius.diagram.sequence.business.internal.layout.horizontal.SequenceHorizontalLayout;
import org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.part.EndOfLifeEditPart;
import org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.part.InteractionContainerEditPart;
import org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.part.LifelineEditPart;
import org.eclipse.sirius.diagram.tools.api.preferences.SiriusDiagramPreferencesKeys;
import org.eclipse.sirius.diagram.ui.tools.api.preferences.SiriusDiagramUiPreferencesKeys;
import org.eclipse.sirius.ext.base.Option;
import org.eclipse.sirius.ext.base.Options;
import org.eclipse.sirius.tests.swtbot.support.api.business.UIDiagramRepresentation;
import org.eclipse.sirius.tests.swtbot.support.api.business.UIResource;
import org.eclipse.sirius.tests.swtbot.support.api.condition.OperationDoneCondition;
import org.eclipse.sirius.tests.swtbot.support.api.editor.SWTBotSiriusDiagramEditor;
import org.eclipse.sirius.tests.unit.diagram.sequence.InteractionsConstants;
Expand Down Expand Up @@ -67,13 +72,29 @@ public class InteractionContainerAdditionalLayerTests extends AbstractSequenceDi

private UIDiagramRepresentation diagram;


/**
* {@inheritDoc}
*/
@Override
protected void onSetUpAfterOpeningDesignerPerspective() throws Exception {
super.onSetUpAfterOpeningDesignerPerspective();
changeDiagramUIPreference(SiriusDiagramUiPreferencesKeys.PREF_OLD_UI.name(), true);
changeDiagramPreference(SiriusDiagramPreferencesKeys.PREF_DISPLAY_HEADER_SECTION.name(), false);
}

public void initDiagram() {
if (getSessionModel() == null) {

} else {
sessionAirdResource = new UIResource(designerProject, FILE_DIR, getSessionModel());
localSession = designerPerspective.openSessionFromFile(sessionAirdResource, true);
Option<String> dRepresentationName = getDRepresentationName();
if (dRepresentationName.some()) {
editor = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), getRepresentationId(), dRepresentationName.get(), DDiagram.class, true, true);
}
}

initEditor();
diagram = localSession.getLocalSessionBrowser().perCategory().selectViewpoint(VIEWPOINT_NAME).selectRepresentation(getRepresentationId())
.selectRepresentationInstance(getDRepresentationName().get(), UIDiagramRepresentation.class);

Expand All @@ -87,43 +108,94 @@ protected void onSetUpAfterOpeningDesignerPerspective() throws Exception {
}

/**
* Check that on lifeline move and change position, the interaction container bounds also move accordingly.
* Check that on lifeline move and change position, the interaction container bounds also move accordingly.In this
* version of the test, the property to have a left margin dynamic is true.
*/
public void testInteractionResizeOnInstanceRolePositionChange() {
// Activate the extension layer.
ICondition done = new OperationDoneCondition();
diagram.changeLayerActivation(INTERACTION_CONTAINER_LAYER);
bot.waitUntil(done);

// Check that the Interaction Container east bound correspond to the Instance Role C east bound + margin
SWTBotGefEditPart interactionContainereditPart = editor.getEditPart("Lifelines", InteractionContainerEditPart.class);
Rectangle interactionContainerBounds = editor.getBounds(interactionContainereditPart);
assertEquals("Interaction Container east bound is not where expected", instanceRoleEditPartCBounds.getRight().x + InteractionContainer.MARGIN, interactionContainerBounds.getRight().x, 1);

/*
* Move lifelines to graphically change their order.
*/
// drag LIFELINE_C to (250,0) delta
editor.drag(instanceRoleEditPartCBot, instanceRoleEditPartCBounds.x + 250, origin.y);
// Drag LIFELINE_A to (300,0) delta, Lifeline A forth between Lifeline B
// and Lifeline C
editor.drag(instanceRoleEditPartABot, instanceRoleEditPartABounds.x + 300, origin.y);
public void testInteractionResizeOnInstanceRolePositionChangeWithLeftMargin() {
String oldPreferenceValue = System.getProperty(SequenceHorizontalLayout.INTERACTION_CONTAINER_DYNAMIC_LEFT_PROPERTY_NAME);
try {
System.setProperty(SequenceHorizontalLayout.INTERACTION_CONTAINER_DYNAMIC_LEFT_PROPERTY_NAME, String.valueOf(true));
initDiagram();
// Activate the extension layer.
ICondition done = new OperationDoneCondition();
diagram.changeLayerActivation(INTERACTION_CONTAINER_LAYER);
bot.waitUntil(done);

// Check that the Interaction Container east bound correspond to the Instance Role C east bound + margin
SWTBotGefEditPart interactionContainereditPart = editor.getEditPart("Lifelines", InteractionContainerEditPart.class);
Rectangle interactionContainerBounds = editor.getBounds(interactionContainereditPart);
assertEquals("Interaction Container east bound is not where expected", instanceRoleEditPartCBounds.getRight().x + InteractionContainer.MARGIN, interactionContainerBounds.getRight().x, 1);

/*
* Move lifelines to graphically change their order.
*/
// drag LIFELINE_C to (250,0) delta
editor.drag(instanceRoleEditPartCBot, instanceRoleEditPartCBounds.x + 250, origin.y);
// Drag LIFELINE_A to (300,0) delta, Lifeline A forth between Lifeline B
// and Lifeline C
editor.drag(instanceRoleEditPartABot, instanceRoleEditPartABounds.x + 300, origin.y);

// Check that the Interaction Container east bound still correspond to the Instance Role C east bound + margin
instanceRoleEditPartCBot = editor.getEditPart(LIFELINE_C);
instanceRoleEditPartCBounds = editor.getBounds(instanceRoleEditPartCBot);
instanceRoleEditPartBBot = editor.getEditPart(LIFELINE_B);
instanceRoleEditPartBBounds = editor.getBounds(instanceRoleEditPartBBot);
interactionContainereditPart = editor.getEditPart("Lifelines", InteractionContainerEditPart.class);
interactionContainerBounds = editor.getBounds(interactionContainereditPart);
assertEquals("Interaction Container east bound is not where expected", instanceRoleEditPartCBounds.getRight().x + InteractionContainer.MARGIN, interactionContainerBounds.getRight().x, 1);
assertEquals("Interaction Container west bound is not where expected", instanceRoleEditPartBBounds.getLeft().x - InteractionContainer.MARGIN, interactionContainerBounds.getLeft().x, 1);
} finally {
System.setProperty(SequenceHorizontalLayout.INTERACTION_CONTAINER_DYNAMIC_LEFT_PROPERTY_NAME, oldPreferenceValue != null ? oldPreferenceValue : String.valueOf(false));
}
}

// Check that the Interaction Container east bound still correspond to the Instance Role C east bound + margin
instanceRoleEditPartCBot = editor.getEditPart(LIFELINE_C);
instanceRoleEditPartCBounds = editor.getBounds(instanceRoleEditPartCBot);
instanceRoleEditPartBBot = editor.getEditPart(LIFELINE_B);
instanceRoleEditPartBBounds = editor.getBounds(instanceRoleEditPartBBot);
interactionContainereditPart = editor.getEditPart("Lifelines", InteractionContainerEditPart.class);
interactionContainerBounds = editor.getBounds(interactionContainereditPart);
assertEquals("Interaction Container east bound is not where expected", instanceRoleEditPartCBounds.getRight().x + InteractionContainer.MARGIN, interactionContainerBounds.getRight().x, 1);
assertEquals("Interaction Container west bound is not where expected", instanceRoleEditPartBBounds.getLeft().x - InteractionContainer.MARGIN, interactionContainerBounds.getLeft().x, 1);
/**
* Check that on lifeline move and change position, the interaction container bounds also move accordingly.In this
* version of the test, the property to have a left margin dynamic is true.
*/
public void testInteractionResizeOnInstanceRolePositionChangeWithoutLeftMargin() {
String oldPreferenceValue = System.getProperty(SequenceHorizontalLayout.INTERACTION_CONTAINER_DYNAMIC_LEFT_PROPERTY_NAME);
try {
System.setProperty(SequenceHorizontalLayout.INTERACTION_CONTAINER_DYNAMIC_LEFT_PROPERTY_NAME, String.valueOf(false));
initDiagram();
// Activate the extension layer.
ICondition done = new OperationDoneCondition();
diagram.changeLayerActivation(INTERACTION_CONTAINER_LAYER);
bot.waitUntil(done);

// Check that the Interaction Container east bound correspond to the Instance Role C east bound + margin
SWTBotGefEditPart interactionContainereditPart = editor.getEditPart("Lifelines", InteractionContainerEditPart.class);
Rectangle interactionContainerBounds = editor.getBounds(interactionContainereditPart);
assertEquals("Interaction Container east bound is not where expected", instanceRoleEditPartCBounds.getRight().x + InteractionContainer.MARGIN, interactionContainerBounds.getRight().x, 1);

/*
* Move lifelines to graphically change their order.
*/
// drag LIFELINE_C to (250,0) delta
editor.drag(instanceRoleEditPartCBot, instanceRoleEditPartCBounds.x + 250, origin.y);
// Drag LIFELINE_A to (300,0) delta, Lifeline A forth between Lifeline B
// and Lifeline C
editor.drag(instanceRoleEditPartABot, instanceRoleEditPartABounds.x + 300, origin.y);

// Check that the Interaction Container east bound still correspond to the Instance Role C east bound + margin
instanceRoleEditPartCBot = editor.getEditPart(LIFELINE_C);
instanceRoleEditPartCBounds = editor.getBounds(instanceRoleEditPartCBot);
instanceRoleEditPartBBot = editor.getEditPart(LIFELINE_B);
instanceRoleEditPartBBounds = editor.getBounds(instanceRoleEditPartBBot);
interactionContainereditPart = editor.getEditPart("Lifelines", InteractionContainerEditPart.class);
interactionContainerBounds = editor.getBounds(interactionContainereditPart);
assertEquals("Interaction Container east bound is not where expected", instanceRoleEditPartCBounds.getRight().x + InteractionContainer.MARGIN, interactionContainerBounds.getRight().x, 1);
assertEquals("Interaction Container west bound is not where expected", -1, interactionContainerBounds.getLeft().x, 1);
} finally {
System.setProperty(SequenceHorizontalLayout.INTERACTION_CONTAINER_DYNAMIC_LEFT_PROPERTY_NAME, oldPreferenceValue != null ? oldPreferenceValue : String.valueOf(false));
}
}

/**
* Check that when the last lifeline move back and forth, the interaction container bounds also move accordingly.
*/
public void testInteractionResizeOnInstanceRoleMoveBackAndForth() {
initDiagram();
// Activate the extension layer.
ICondition done = new OperationDoneCondition();
diagram.changeLayerActivation(INTERACTION_CONTAINER_LAYER);
Expand Down Expand Up @@ -164,6 +236,7 @@ public void testInteractionResizeOnInstanceRoleMoveBackAndForth() {
* accordingly.
*/
public void testInteractionResizeOnExecutionMove() {
initDiagram();
// Activate the extension layer.
ICondition done = new OperationDoneCondition();
diagram.changeLayerActivation(INTERACTION_CONTAINER_LAYER);
Expand Down
Loading

0 comments on commit 846c236

Please sign in to comment.