diff options
| author | Steve Monnier | 2017-08-11 16:17:28 +0000 |
|---|---|---|
| committer | pguilet | 2017-08-22 13:42:35 +0000 |
| commit | a1dd6254cc1bbc93dbef584585c0f4ca180d82dd (patch) | |
| tree | ec51556531d52bef8b066a536a29023d69c9de68 | |
| parent | 82112831e1d5f557b444e9e8b9be7baed927ce58 (diff) | |
| download | org.eclipse.sirius-a1dd6254cc1bbc93dbef584585c0f4ca180d82dd.tar.gz org.eclipse.sirius-a1dd6254cc1bbc93dbef584585c0f4ca180d82dd.tar.xz org.eclipse.sirius-a1dd6254cc1bbc93dbef584585c0f4ca180d82dd.zip | |
[520900] Add 4 new straighten action with a side pinned
Add 4 actions to straighten a selection of edges with a side pinned. For
a selection of horizontal edges, it would be possible to straighten them
with the left side pinned or the right side pinned. For a selection of
vertical edges, it would be possible to straighten them with the top
side pinned or the bottom side pinned.
Bug: 520900
Change-Id: I9093d794815bcbd0f2f3da30de81a049c79ec651
Signed-off-by: Steve Monnier <steve.monnier@obeo.fr>
Signed-off-by: pguilet <pierre.guilet@obeo.fr>
11 files changed, 500 insertions, 151 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/plugin.properties b/plugins/org.eclipse.sirius.diagram.ui/plugin.properties index 0b5ae86157..c60855b9b1 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/plugin.properties +++ b/plugins/org.eclipse.sirius.diagram.ui/plugin.properties @@ -1187,6 +1187,14 @@ StraightenToAction_toLeftLabel = To left StraightenToAction_toLeftTooltip = Straighten to left StraightenToAction_toRightLabel = To right StraightenToAction_toRightTooltip = Straighten to right +StraightenToAction_LeftSidePinnedLabel = With left side pinned +StraightenToAction_LeftSidePinnedTooltip = Straighten with left side pinned +StraightenToAction_RightSidePinnedLabel = With right side pinned +StraightenToAction_RightSidePinnedTooltip = Straighten with right side pinned +StraightenToAction_TopSidePinnedLabel = With top side pinned +StraightenToAction_TopSidePinnedTooltip = Straighten with top side pinned +StraightenToAction_BottomSidePinnedLabel = With bottom side pinned +StraightenToAction_BottomSidePinnedTooltip = Straighten with bottom side pinned StraightenToCommand_errorMsg = The selected elements can not be straightened as requested. StraightenToMenuAction_text = Straighten StraightenToMenuAction_tooltip = Straighten selected edges diff --git a/plugins/org.eclipse.sirius.diagram.ui/plugin.xml b/plugins/org.eclipse.sirius.diagram.ui/plugin.xml index b9711d3142..8faeb33e87 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/plugin.xml +++ b/plugins/org.eclipse.sirius.diagram.ui/plugin.xml @@ -190,6 +190,10 @@ <popupAction path="/formatMenu/arrangeMenu/straightenToMenu/straightenToHorizontalGroup" id="straightenToBottom"/> <popupAction path="/formatMenu/arrangeMenu/straightenToMenu/straightenToVerticalGroup" id="straightenToLeft"/> <popupAction path="/formatMenu/arrangeMenu/straightenToMenu/straightenToVerticalGroup" id="straightenToRight"/> + <popupAction path="/formatMenu/arrangeMenu/straightenToMenu/straightenToVerticalGroup" id="straightenToTopSidePinned" /> + <popupAction path="/formatMenu/arrangeMenu/straightenToMenu/straightenToVerticalGroup" id="straightenToBottomSidePinned"/> + <popupAction path="/formatMenu/arrangeMenu/straightenToMenu/straightenToHorizontalGroup" id="straightenToLeftSidePinned"/> + <popupAction path="/formatMenu/arrangeMenu/straightenToMenu/straightenToHorizontalGroup" id="straightenToRightSidePinned"/> </popupContribution> <popupContribution class="org.eclipse.sirius.diagram.ui.tools.internal.menu.DiagramEditorContextMenuProvider"> <popupStructuredContributionCriteria objectClass="org.eclipse.sirius.diagram.ui.edit.api.part.ISiriusEditPart" /> diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/StraightenToCommand.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/StraightenToCommand.java index 3ff4ea60f4..8efd161262 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/StraightenToCommand.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/StraightenToCommand.java @@ -185,8 +185,10 @@ public class StraightenToCommand extends AbstractTransactionalCommand { int axis = getSourceAndTargetSameAxis(edgeEditPart, data); canExecuteThisEdge = axis != PositionConstants.NONE; if (canExecuteThisEdge) { - if ((axis == PositionConstants.HORIZONTAL && (straightenType == StraightenToAction.TO_TOP || straightenType == StraightenToAction.TO_BOTTOM)) - || (axis == PositionConstants.VERTICAL && (straightenType == StraightenToAction.TO_LEFT || straightenType == StraightenToAction.TO_RIGHT))) { + if ((axis == PositionConstants.HORIZONTAL && (straightenType == StraightenToAction.TO_TOP || straightenType == StraightenToAction.TO_BOTTOM + || straightenType == StraightenToAction.LEFT_SIDE_PINNED || straightenType == StraightenToAction.RIGHT_SIDE_PINNED)) + || (axis == PositionConstants.VERTICAL && (straightenType == StraightenToAction.TO_LEFT || straightenType == StraightenToAction.TO_RIGHT + || straightenType == StraightenToAction.TOP_SIDE_PINNED || straightenType == StraightenToAction.BOTTOM_SIDE_PINNED))) { data.moveSource = isSourceWillBeMoved(edgeEditPart, data); } else { canExecuteThisEdge = false; @@ -319,7 +321,8 @@ public class StraightenToCommand extends AbstractTransactionalCommand { } private void computePointsInSpecificCase(Point firstPoint, Point lastPoint, Rectangle sourceBounds, Rectangle targetBounds) { - if (straightenType == StraightenToAction.TO_TOP || straightenType == StraightenToAction.TO_BOTTOM) { + if (straightenType == StraightenToAction.TO_TOP || straightenType == StraightenToAction.TO_BOTTOM || straightenType == StraightenToAction.LEFT_SIDE_PINNED + || straightenType == StraightenToAction.RIGHT_SIDE_PINNED) { firstPoint.setX(firstPoint.x).setY(sourceBounds.getCenter().y); lastPoint.setX(lastPoint.x).setY(targetBounds.getCenter().y); } else { @@ -445,15 +448,15 @@ public class StraightenToCommand extends AbstractTransactionalCommand { } else { targetPoint = new Point(); } - if (straightenType == StraightenToAction.TO_LEFT) { + if (straightenType == StraightenToAction.TO_LEFT || straightenType == StraightenToAction.LEFT_SIDE_PINNED) { if (sourcePoint.x > targetPoint.x) { isSourceWillBeMoved = true; } - } else if (straightenType == StraightenToAction.TO_RIGHT) { + } else if (straightenType == StraightenToAction.TO_RIGHT || straightenType == StraightenToAction.RIGHT_SIDE_PINNED) { if (sourcePoint.x < targetPoint.x) { isSourceWillBeMoved = true; } - } else if (straightenType == StraightenToAction.TO_TOP) { + } else if (straightenType == StraightenToAction.TO_TOP || straightenType == StraightenToAction.TOP_SIDE_PINNED) { if (sourcePoint.y > targetPoint.y) { isSourceWillBeMoved = true; } @@ -520,9 +523,11 @@ public class StraightenToCommand extends AbstractTransactionalCommand { lastPoint = GraphicalHelper.getAbsoluteBoundsIn100Percent(data.targetEditPart).getCenter(); } if (data.moveSource) { - if (straightenType == StraightenToAction.TO_TOP || straightenType == StraightenToAction.TO_BOTTOM) { + if (straightenType == StraightenToAction.TO_TOP || straightenType == StraightenToAction.TO_BOTTOM || straightenType == StraightenToAction.LEFT_SIDE_PINNED + || straightenType == StraightenToAction.RIGHT_SIDE_PINNED) { data.deltaY = lastPoint.y - firstPoint.y; - } else if (straightenType == StraightenToAction.TO_LEFT || straightenType == StraightenToAction.TO_RIGHT) { + } else if (straightenType == StraightenToAction.TO_LEFT || straightenType == StraightenToAction.TO_RIGHT || straightenType == StraightenToAction.TOP_SIDE_PINNED + || straightenType == StraightenToAction.BOTTOM_SIDE_PINNED) { data.deltaX = lastPoint.x - firstPoint.x; } if (data.isSourceABorderNode) { @@ -530,31 +535,37 @@ public class StraightenToCommand extends AbstractTransactionalCommand { Rectangle borderNodeBounds = GraphicalHelper.getAbsoluteBoundsIn100Percent(data.sourceEditPart); // Get the computed bounds after the move borderNodeBounds = borderNodeBounds.getTranslated(data.deltaX, data.deltaY); - if (straightenType == StraightenToAction.TO_TOP || straightenType == StraightenToAction.TO_BOTTOM) { + if (straightenType == StraightenToAction.TO_TOP || straightenType == StraightenToAction.TO_BOTTOM || straightenType == StraightenToAction.LEFT_SIDE_PINNED + || straightenType == StraightenToAction.RIGHT_SIDE_PINNED) { if (parentBorderNodeBounds.y <= borderNodeBounds.y && (borderNodeBounds.y + borderNodeBounds.height) <= (parentBorderNodeBounds.y + parentBorderNodeBounds.height)) { isNewLocationInParentBounds = true; } - } else if (straightenType == StraightenToAction.TO_LEFT || straightenType == StraightenToAction.TO_RIGHT) { + } else if (straightenType == StraightenToAction.TO_LEFT || straightenType == StraightenToAction.TO_RIGHT || straightenType == StraightenToAction.TOP_SIDE_PINNED + || straightenType == StraightenToAction.BOTTOM_SIDE_PINNED) { if (parentBorderNodeBounds.x <= borderNodeBounds.x && (borderNodeBounds.x + borderNodeBounds.width) <= (parentBorderNodeBounds.x + parentBorderNodeBounds.width)) { isNewLocationInParentBounds = true; } } } else { Rectangle bounds = GraphicalHelper.getAbsoluteBoundsIn100Percent(data.sourceEditPart); - if (straightenType == StraightenToAction.TO_TOP || straightenType == StraightenToAction.TO_BOTTOM) { + if (straightenType == StraightenToAction.TO_TOP || straightenType == StraightenToAction.TO_BOTTOM || straightenType == StraightenToAction.LEFT_SIDE_PINNED + || straightenType == StraightenToAction.RIGHT_SIDE_PINNED) { if (bounds.y <= lastPoint.y && lastPoint.y <= (bounds.y + bounds.height)) { isNewLocationInParentBounds = true; } - } else if (straightenType == StraightenToAction.TO_LEFT || straightenType == StraightenToAction.TO_RIGHT) { + } else if (straightenType == StraightenToAction.TO_LEFT || straightenType == StraightenToAction.TO_RIGHT || straightenType == StraightenToAction.TOP_SIDE_PINNED + || straightenType == StraightenToAction.BOTTOM_SIDE_PINNED) { if (bounds.x <= lastPoint.x && lastPoint.x <= (bounds.x + bounds.width)) { isNewLocationInParentBounds = true; } } } } else { - if (straightenType == StraightenToAction.TO_TOP || straightenType == StraightenToAction.TO_BOTTOM) { + if (straightenType == StraightenToAction.TO_TOP || straightenType == StraightenToAction.TO_BOTTOM || straightenType == StraightenToAction.LEFT_SIDE_PINNED + || straightenType == StraightenToAction.RIGHT_SIDE_PINNED) { data.deltaY = firstPoint.y - lastPoint.y; - } else if (straightenType == StraightenToAction.TO_LEFT || straightenType == StraightenToAction.TO_RIGHT) { + } else if (straightenType == StraightenToAction.TO_LEFT || straightenType == StraightenToAction.TO_RIGHT || straightenType == StraightenToAction.TOP_SIDE_PINNED + || straightenType == StraightenToAction.BOTTOM_SIDE_PINNED) { data.deltaX = firstPoint.x - lastPoint.x; } if (data.isTargetABorderNode) { @@ -562,22 +573,26 @@ public class StraightenToCommand extends AbstractTransactionalCommand { Rectangle borderNodeBounds = GraphicalHelper.getAbsoluteBoundsIn100Percent(data.targetEditPart); // Get the computed bounds after the move borderNodeBounds = borderNodeBounds.getTranslated(data.deltaX, data.deltaY); - if (straightenType == StraightenToAction.TO_TOP || straightenType == StraightenToAction.TO_BOTTOM) { + if (straightenType == StraightenToAction.TO_TOP || straightenType == StraightenToAction.TO_BOTTOM || straightenType == StraightenToAction.LEFT_SIDE_PINNED + || straightenType == StraightenToAction.RIGHT_SIDE_PINNED) { if (parentBorderNodeBounds.y <= borderNodeBounds.y && (borderNodeBounds.y + borderNodeBounds.height) <= (parentBorderNodeBounds.y + parentBorderNodeBounds.height)) { isNewLocationInParentBounds = true; } - } else if (straightenType == StraightenToAction.TO_LEFT || straightenType == StraightenToAction.TO_RIGHT) { + } else if (straightenType == StraightenToAction.TO_LEFT || straightenType == StraightenToAction.TO_RIGHT || straightenType == StraightenToAction.TOP_SIDE_PINNED + || straightenType == StraightenToAction.BOTTOM_SIDE_PINNED) { if (parentBorderNodeBounds.x <= borderNodeBounds.x && (borderNodeBounds.x + borderNodeBounds.width) <= (parentBorderNodeBounds.x + parentBorderNodeBounds.width)) { isNewLocationInParentBounds = true; } } } else { Rectangle bounds = GraphicalHelper.getAbsoluteBoundsIn100Percent(data.targetEditPart); - if (straightenType == StraightenToAction.TO_TOP || straightenType == StraightenToAction.TO_BOTTOM) { + if (straightenType == StraightenToAction.TO_TOP || straightenType == StraightenToAction.TO_BOTTOM || straightenType == StraightenToAction.LEFT_SIDE_PINNED + || straightenType == StraightenToAction.RIGHT_SIDE_PINNED) { if (bounds.y <= firstPoint.y && firstPoint.y <= (bounds.y + bounds.height)) { isNewLocationInParentBounds = true; } - } else if (straightenType == StraightenToAction.TO_LEFT || straightenType == StraightenToAction.TO_RIGHT) { + } else if (straightenType == StraightenToAction.TO_LEFT || straightenType == StraightenToAction.TO_RIGHT || straightenType == StraightenToAction.TOP_SIDE_PINNED + || straightenType == StraightenToAction.BOTTOM_SIDE_PINNED) { if (bounds.x <= firstPoint.x && firstPoint.x <= (bounds.x + bounds.width)) { isNewLocationInParentBounds = true; } @@ -650,10 +665,12 @@ public class StraightenToCommand extends AbstractTransactionalCommand { Rectangle initialAsboluteConstraint = initialRelativeConstraint.getTranslated(parentAbsoluteLocation); Point validInitialAbsoluteLocation = borderItemLocator.getValidLocation(initialAsboluteConstraint, node, Lists.newArrayList(node)); Rectangle validInitialAbsoluteConstraint = initialAsboluteConstraint.getCopy(); - if ((straightenType == StraightenToAction.TO_LEFT || straightenType == StraightenToAction.TO_RIGHT) && initialAsboluteConstraint.y != validInitialAbsoluteLocation.y) { + if ((straightenType == StraightenToAction.TO_LEFT || straightenType == StraightenToAction.TO_RIGHT || straightenType == StraightenToAction.TOP_SIDE_PINNED + || straightenType == StraightenToAction.BOTTOM_SIDE_PINNED) && initialAsboluteConstraint.y != validInitialAbsoluteLocation.y) { // There is probably a bug in the GMF location, fix it. validInitialAbsoluteConstraint.setY(validInitialAbsoluteLocation.y); - } else if ((straightenType == StraightenToAction.TO_TOP || straightenType == StraightenToAction.TO_BOTTOM) && initialAsboluteConstraint.x != validInitialAbsoluteLocation.x) { + } else if ((straightenType == StraightenToAction.TO_TOP || straightenType == StraightenToAction.TO_BOTTOM || straightenType == StraightenToAction.LEFT_SIDE_PINNED + || straightenType == StraightenToAction.RIGHT_SIDE_PINNED) && initialAsboluteConstraint.x != validInitialAbsoluteLocation.x) { // There is probably a bug in the GMF location, fix it. validInitialAbsoluteConstraint.setX(validInitialAbsoluteLocation.x); } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/providers/SiriusContributionItemProvider.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/providers/SiriusContributionItemProvider.java index af025affe4..01c341885f 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/providers/SiriusContributionItemProvider.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/providers/SiriusContributionItemProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2016 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2017 THALES GLOBAL SERVICES. * 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 @@ -101,6 +101,14 @@ public class SiriusContributionItemProvider extends AbstractContributionItemProv result = StraightenToAction.createStraightenToLeftAction(workbenchPage); } else if (ActionIds.STRAIGHTEN_TO_RIGHT.equals(actionId)) { result = StraightenToAction.createStraightenToRightAction(workbenchPage); + } else if (ActionIds.STRAIGHTEN_TOP_SIDE_PINNED.equals(actionId)) { + result = StraightenToAction.createStraightenTopSidePinnedAction(workbenchPage); + } else if (ActionIds.STRAIGHTEN_BOTTOM_SIDE_PINNED.equals(actionId)) { + result = StraightenToAction.createStraightenBottomSidePinnedAction(workbenchPage); + } else if (ActionIds.STRAIGHTEN_LEFT_SIDE_PINNED.equals(actionId)) { + result = StraightenToAction.createStraightenLeftSidePinnedAction(workbenchPage); + } else if (ActionIds.STRAIGHTEN_RIGHT_SIDE_PINNED.equals(actionId)) { + result = StraightenToAction.createStraightenRightSidePinnedAction(workbenchPage); } else { result = super.createAction(actionId, partDescriptor); } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/ui/actions/ActionIds.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/ui/actions/ActionIds.java index 78dd9b165d..a53526e286 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/ui/actions/ActionIds.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/ui/actions/ActionIds.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2016 THALES GLOBAL SERVICES and others. + * Copyright (c) 2009, 2017 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 @@ -15,8 +15,7 @@ import org.eclipse.sirius.diagram.ui.tools.api.requests.RequestConstants; /** * A list of constants defining the diagram action and menu action ids. * <p> - * This interface defines constants only, it is <EM>not</EM> intended to be - * implemented by clients. + * This interface defines constants only, it is <EM>not</EM> intended to be implemented by clients. * </p> * * @author <a href="mailto:laurent.redor@obeo.fr">Laurent Redor</a> @@ -127,4 +126,16 @@ public interface ActionIds { /** Action's id to straighten to right. */ String STRAIGHTEN_TO_RIGHT = RequestConstants.REQ_STRAIGHTEN + "Right"; //$NON-NLS-1$ + /** Action's id to straighten to top. */ + String STRAIGHTEN_LEFT_SIDE_PINNED = RequestConstants.REQ_STRAIGHTEN + "LeftSidePinned"; //$NON-NLS-1$ + + /** Action's id to straighten to bottom. */ + String STRAIGHTEN_RIGHT_SIDE_PINNED = RequestConstants.REQ_STRAIGHTEN + "RightSidePinned"; //$NON-NLS-1$ + + /** Action's id to straighten to left. */ + String STRAIGHTEN_TOP_SIDE_PINNED = RequestConstants.REQ_STRAIGHTEN + "TopSidePinned"; //$NON-NLS-1$ + + /** Action's id to straighten to right. */ + String STRAIGHTEN_BOTTOM_SIDE_PINNED = RequestConstants.REQ_STRAIGHTEN + "BottomSidePinned"; //$NON-NLS-1$ + } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/straighten/StraightenToAction.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/straighten/StraightenToAction.java index 5fc0049a94..e20a81a784 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/straighten/StraightenToAction.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/straighten/StraightenToAction.java @@ -35,7 +35,6 @@ import com.google.common.collect.Lists; * * @author <a href="mailto:laurent.redor@obeo.fr">Laurent Redor</a> */ -@SuppressWarnings("restriction") public class StraightenToAction extends DiagramAction { /** Constant indicating a straighten to top action. */ @@ -50,6 +49,18 @@ public class StraightenToAction extends DiagramAction { /** Constant indicating a straighten to right action. */ public static final int TO_RIGHT = 3; + /** Constant indicating a straighten with left side pinned action. */ + public static final int LEFT_SIDE_PINNED = 4; + + /** Constant indicating a straighten with right side pinned action. */ + public static final int RIGHT_SIDE_PINNED = 5; + + /** Constant indicating a straighten with top side pinned action. */ + public static final int TOP_SIDE_PINNED = 6; + + /** Constant indicating a straighten with bottom side pinned action. */ + public static final int BOTTOM_SIDE_PINNED = 7; + /** * The straighten type must by one of: * <UL> @@ -57,6 +68,10 @@ public class StraightenToAction extends DiagramAction { * <LI>{@link StraightenToAction#TO_BOTTOM}</LI> * <LI>{@link StraightenToAction#TO_LEFT}</LI> * <LI>{@link StraightenToAction#TO_RIGHT}</LI> + * <LI>{@link StraightenToAction#TOP_SIDE_PINNED}</LI> + * <LI>{@link StraightenToAction#BOTTOM_SIDE_PINNED}</LI> + * <LI>{@link StraightenToAction#LEFT_SIDE_PINNED}</LI> + * <LI>{@link StraightenToAction#RIGHT_SIDE_PINNED}</LI> * </UL> */ private int straightenType; @@ -70,6 +85,10 @@ public class StraightenToAction extends DiagramAction { * <LI>{@link StraightenToAction#TO_BOTTOM}</LI> * <LI>{@link StraightenToAction#TO_LEFT}</LI> * <LI>{@link StraightenToAction#TO_RIGHT}</LI> + * <LI>{@link StraightenToAction#TOP_SIDE_PINNED}</LI> + * <LI>{@link StraightenToAction#BOTTOM_SIDE_PINNED}</LI> + * <LI>{@link StraightenToAction#LEFT_SIDE_PINNED}</LI> + * <LI>{@link StraightenToAction#RIGHT_SIDE_PINNED}</LI> * </UL> * * @param workbenchPage @@ -106,6 +125,18 @@ public class StraightenToAction extends DiagramAction { case StraightenToAction.TO_RIGHT: label = Messages.StraightenToAction_toRightLabel; break; + case StraightenToAction.LEFT_SIDE_PINNED: + label = Messages.StraightenToAction_LeftSidePinnedLabel; + break; + case StraightenToAction.RIGHT_SIDE_PINNED: + label = Messages.StraightenToAction_RightSidePinnedLabel; + break; + case StraightenToAction.TOP_SIDE_PINNED: + label = Messages.StraightenToAction_TopSidePinnedLabel; + break; + case StraightenToAction.BOTTOM_SIDE_PINNED: + label = Messages.StraightenToAction_BottomSidePinnedLabel; + break; default: break; } @@ -134,6 +165,18 @@ public class StraightenToAction extends DiagramAction { case StraightenToAction.TO_RIGHT: tooltip = Messages.StraightenToAction_toRightTooltip; break; + case StraightenToAction.LEFT_SIDE_PINNED: + tooltip = Messages.StraightenToAction_LeftSidePinnedTooltip; + break; + case StraightenToAction.RIGHT_SIDE_PINNED: + tooltip = Messages.StraightenToAction_RightSidePinnedTooltip; + break; + case StraightenToAction.TOP_SIDE_PINNED: + tooltip = Messages.StraightenToAction_TopSidePinnedTooltip; + break; + case StraightenToAction.BOTTOM_SIDE_PINNED: + tooltip = Messages.StraightenToAction_BottomSidePinnedTooltip; + break; default: break; } @@ -204,6 +247,74 @@ public class StraightenToAction extends DiagramAction { return action; } + /** + * Creates the Straighten with left side pinned action to align the edge(s) horizontally by moving all right side + * extremities of edge(s). + * + * @param workbenchPage + * the workbench part used to obtain context + * @return the corresponding action + */ + public static StraightenToAction createStraightenLeftSidePinnedAction(IWorkbenchPage workbenchPage) { + StraightenToAction action = new StraightenToAction(workbenchPage, StraightenToAction.LEFT_SIDE_PINNED); + action.setId(ActionIds.STRAIGHTEN_LEFT_SIDE_PINNED); + ImageDescriptor bundledImageDescriptor = DiagramUIPlugin.Implementation.getBundledImageDescriptor(DiagramImagesPath.STRAIGHTEN_TO_TOP); + action.setImageDescriptor(bundledImageDescriptor); + action.setHoverImageDescriptor(bundledImageDescriptor); + return action; + } + + /** + * Creates the Straighten with right side pinned action to align the edge(s) horizontally by moving all left side + * extremities of edge(s). + * + * @param workbenchPage + * the workbench part used to obtain context + * @return the corresponding action + */ + public static StraightenToAction createStraightenRightSidePinnedAction(IWorkbenchPage workbenchPage) { + StraightenToAction action = new StraightenToAction(workbenchPage, StraightenToAction.RIGHT_SIDE_PINNED); + action.setId(ActionIds.STRAIGHTEN_RIGHT_SIDE_PINNED); + ImageDescriptor bundledImageDescriptor = DiagramUIPlugin.Implementation.getBundledImageDescriptor(DiagramImagesPath.STRAIGHTEN_TO_BOTTOM); + action.setImageDescriptor(bundledImageDescriptor); + action.setHoverImageDescriptor(bundledImageDescriptor); + return action; + } + + /** + * Creates the Straighten with top side pinned action to align the edge(s) vertically by moving all bottom side + * extremities of edge(s). + * + * @param workbenchPage + * the workbench part used to obtain context + * @return the corresponding action + */ + public static StraightenToAction createStraightenTopSidePinnedAction(IWorkbenchPage workbenchPage) { + StraightenToAction action = new StraightenToAction(workbenchPage, StraightenToAction.TOP_SIDE_PINNED); + action.setId(ActionIds.STRAIGHTEN_TOP_SIDE_PINNED); + ImageDescriptor bundledImageDescriptor = DiagramUIPlugin.Implementation.getBundledImageDescriptor(DiagramImagesPath.STRAIGHTEN_TO_LEFT); + action.setImageDescriptor(bundledImageDescriptor); + action.setHoverImageDescriptor(bundledImageDescriptor); + return action; + } + + /** + * Creates the Straighten with bottom side pinned action to align the edge(s) vertically by moving all top side + * extremities of edge(s). + * + * @param workbenchPage + * the workbench part used to obtain context + * @return the corresponding action + */ + public static StraightenToAction createStraightenBottomSidePinnedAction(IWorkbenchPage workbenchPage) { + StraightenToAction action = new StraightenToAction(workbenchPage, StraightenToAction.BOTTOM_SIDE_PINNED); + action.setId(ActionIds.STRAIGHTEN_BOTTOM_SIDE_PINNED); + ImageDescriptor bundledImageDescriptor = DiagramUIPlugin.Implementation.getBundledImageDescriptor(DiagramImagesPath.STRAIGHTEN_TO_RIGHT); + action.setImageDescriptor(bundledImageDescriptor); + action.setHoverImageDescriptor(bundledImageDescriptor); + return action; + } + @Override protected Request createTargetRequest() { StraightenToRequest straightenRequest = new StraightenToRequest(); diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/actions/StraightenToMenuManager.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/actions/StraightenToMenuManager.java index 5bcf529bd4..4b9cfec7c3 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/actions/StraightenToMenuManager.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/actions/StraightenToMenuManager.java @@ -10,13 +10,23 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.actions; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + import org.eclipse.gmf.runtime.common.ui.action.ActionMenuManager; import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IContributionItem; +import org.eclipse.jface.action.Separator; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.sirius.common.ui.tools.api.util.EclipseUIUtil; import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; import org.eclipse.sirius.diagram.ui.provider.Messages; import org.eclipse.sirius.diagram.ui.tools.api.image.DiagramImagesPath; import org.eclipse.sirius.diagram.ui.tools.api.ui.actions.ActionIds; +import org.eclipse.sirius.diagram.ui.tools.internal.actions.straighten.StraightenToAction; +import org.eclipse.ui.IWorkbenchPage; /** * The straighten menu manager. It contains all straighten-related actions. @@ -44,4 +54,69 @@ public class StraightenToMenuManager extends ActionMenuManager { public StraightenToMenuManager() { super(ActionIds.MENU_STRAIGHTEN_TO, new StraightenMenuAction(), true); } + + /** + * Set the default action id for this menu manager. + * + * @param actionId + * the action id to set + */ + public void setDefaultAction(String actionId) { + for (final IContributionItem item : getItems()) { + if (item instanceof ActionContributionItem) { + if (actionId.equals(((ActionContributionItem) item).getAction().getId())) { + final IAction defaultAction = ((ActionContributionItem) item).getAction(); + setHandler(defaultAction); + super.setDefaultAction(defaultAction); + return; + } + } + } + } + + /** + * We should use reflection to access the default handler method + * + * @param defaultAction + * the default action to set + */ + private void setHandler(final IAction defaultAction) { + Method method; + try { + method = MenuCreatorAction.class.getDeclaredMethod("setActionHandler", IAction.class); //$NON-NLS-1$ + method.setAccessible(true); + method.invoke(super.action, defaultAction); + } catch (SecurityException e) { + /* do nothing should not happen */ + } catch (NoSuchMethodException e) { + /* do nothing should not happen */ + } catch (IllegalArgumentException e) { + /* do nothing should not happen */ + } catch (IllegalAccessException e) { + /* do nothing should not happen */ + } catch (InvocationTargetException e) { + /* do nothing should not happen */ + } + } + + @Override + public void setVisible(boolean visible) { + super.setVisible(visible); + if (isEmpty() && visible) { + IWorkbenchPage page = EclipseUIUtil.getActivePage(); + if (page != null) { + add(StraightenToAction.createStraightenToTopAction(page)); + add(StraightenToAction.createStraightenToBottomAction(page)); + add(StraightenToAction.createStraightenLeftSidePinnedAction(page)); + add(StraightenToAction.createStraightenRightSidePinnedAction(page)); + add(new Separator()); + add(StraightenToAction.createStraightenToLeftAction(page)); + add(StraightenToAction.createStraightenToRightAction(page)); + add(StraightenToAction.createStraightenTopSidePinnedAction(page)); + add(StraightenToAction.createStraightenBottomSidePinnedAction(page)); + + setDefaultAction(ActionIds.STRAIGHTEN_TO_TOP); + } + } + } } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/actions/TabbarStraightenToMenuManager.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/actions/TabbarStraightenToMenuManager.java index ca15235904..c9a9aabbf4 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/actions/TabbarStraightenToMenuManager.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/actions/TabbarStraightenToMenuManager.java @@ -18,6 +18,7 @@ import org.eclipse.gmf.runtime.common.ui.action.IDisposableAction; import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IContributionItem; +import org.eclipse.jface.action.Separator; import org.eclipse.sirius.common.ui.tools.api.util.EclipseUIUtil; import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; import org.eclipse.sirius.diagram.ui.tools.api.ui.actions.ActionIds; @@ -99,11 +100,16 @@ public class TabbarStraightenToMenuManager extends DistributeMenuManager { if (isEmpty() && visible) { IWorkbenchPage page = EclipseUIUtil.getActivePage(); if (page != null) { - add(StraightenToAction.createStraightenToLeftAction(page)); - add(StraightenToAction.createStraightenToRightAction(page)); add(StraightenToAction.createStraightenToTopAction(page)); add(StraightenToAction.createStraightenToBottomAction(page)); - setDefaultAction(ActionIds.STRAIGHTEN_TO_LEFT); + add(StraightenToAction.createStraightenLeftSidePinnedAction(page)); + add(StraightenToAction.createStraightenRightSidePinnedAction(page)); + add(new Separator()); + add(StraightenToAction.createStraightenToLeftAction(page)); + add(StraightenToAction.createStraightenToRightAction(page)); + add(StraightenToAction.createStraightenTopSidePinnedAction(page)); + add(StraightenToAction.createStraightenBottomSidePinnedAction(page)); + setDefaultAction(ActionIds.STRAIGHTEN_TO_TOP); } } } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java index d5094dd8af..2fe1ba98a2 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java @@ -1335,6 +1335,30 @@ public final class Messages { public static String StraightenToAction_toTopTooltip; @TranslatableMessage + public static String StraightenToAction_LeftSidePinnedLabel; + + @TranslatableMessage + public static String StraightenToAction_LeftSidePinnedTooltip; + + @TranslatableMessage + public static String StraightenToAction_RightSidePinnedLabel; + + @TranslatableMessage + public static String StraightenToAction_RightSidePinnedTooltip; + + @TranslatableMessage + public static String StraightenToAction_TopSidePinnedLabel; + + @TranslatableMessage + public static String StraightenToAction_TopSidePinnedTooltip; + + @TranslatableMessage + public static String StraightenToAction_BottomSidePinnedLabel; + + @TranslatableMessage + public static String StraightenToAction_BottomSidePinnedTooltip; + + @TranslatableMessage public static String StraightenToCommand_errorMsg; @TranslatableMessage diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/layout/StraightenToTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/layout/StraightenToTest.java index ae8afe5e96..5ccf957073 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/layout/StraightenToTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/layout/StraightenToTest.java @@ -15,6 +15,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.stream.Collectors; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.PointList; @@ -29,6 +30,7 @@ import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramEdgeEditPart; import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramEdgeEditPart.ViewEdgeFigure; import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramNameEditPart; import org.eclipse.sirius.diagram.ui.internal.edit.parts.DEdgeEditPart; +import org.eclipse.sirius.diagram.ui.internal.edit.parts.DEdgeNameEditPart; import org.eclipse.sirius.diagram.ui.provider.Messages; import org.eclipse.sirius.diagram.ui.tools.api.figure.SiriusWrapLabel; import org.eclipse.sirius.ext.gmf.runtime.editparts.GraphicalHelper; @@ -65,7 +67,34 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { private static final Point IGNORED_POINT = new Point(-1, -1); - private String[] labels = { Messages.StraightenToAction_toTopLabel, Messages.StraightenToAction_toBottomLabel, Messages.StraightenToAction_toLeftLabel, Messages.StraightenToAction_toRightLabel }; + private String[] labels = { Messages.StraightenToAction_toTopLabel, Messages.StraightenToAction_toBottomLabel, Messages.StraightenToAction_LeftSidePinnedLabel, + Messages.StraightenToAction_RightSidePinnedLabel, Messages.StraightenToAction_toLeftLabel, Messages.StraightenToAction_toRightLabel, Messages.StraightenToAction_TopSidePinnedLabel, + Messages.StraightenToAction_BottomSidePinnedLabel }; + + /** + * This class allows to gather diagrams parts or swtbot parts with their label. + * + * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> + * + */ + private class TestPart { + public String partName; + + public SWTBotGefEditPart swtBotpart; + + public AbstractDiagramEdgeEditPart part; + + public TestPart(String edgeName, SWTBotGefEditPart editPart) { + this.partName = edgeName; + this.swtBotpart = editPart; + } + + public TestPart(String edgeName, AbstractDiagramEdgeEditPart edgeEditPart) { + this.partName = edgeName; + this.part = edgeEditPart; + } + + } @Override protected void onSetUpBeforeClosingWelcomePage() throws Exception { @@ -106,8 +135,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { * </UL> */ public void testObliqueEdgeLeftAndRight() { - // {top,bottom,left,right} - boolean[] availableDirections = { false, false, true, true }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { false, false, false, false, true, true, true, true }; checkEdgeActions(availableDirections, "edge12"); } @@ -120,8 +149,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { * </UL> */ public void testObliqueEdgeLeftAndRightWithWrongYGMFCoordinate() { - // {top,bottom,left,right} - boolean[] availableDirections = { false, false, true, true }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { false, false, false, false, true, true, true, true }; checkEdgeActions(availableDirections, "edge24"); } @@ -132,8 +161,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { * </ul> */ public void testObliqueEdgeLeftAndRightForbiddenBecauseofCentering() { - // {top,bottom,left,right} - boolean[] availableDirections = { false, false, false, false }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { false, false, false, false, false, false, false, false }; checkEdgeActions(availableDirections, "edge8"); } @@ -144,8 +173,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { * </ul> */ public void testObliqueEdgeLeftAndRightCenteringOnBothSourceAndTargetBorderNodes() { - // {top,bottom,left,right} - boolean[] availableDirections = { false, false, true, true }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { false, false, false, false, true, true, true, true }; checkEdgeActions(availableDirections, "edge9"); } @@ -156,8 +185,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { * </UL> */ public void testObliqueEdgeTopAndBottom() { - // {top,bottom,left,right} - boolean[] availableDirections = { true, true, false, false }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { true, true, true, true, false, false, false, false }; checkEdgeActions(availableDirections, "edge15"); } @@ -168,8 +197,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { * </UL> */ public void testObliqueEdgeTopAndBottomWithWrongXGMFCoordinate() { - // {top,bottom,left,right} - boolean[] availableDirections = { true, true, false, false }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { true, true, true, true, false, false, false, false }; checkEdgeActions(availableDirections, "edge25"); } @@ -180,8 +209,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { * </UL> */ public void testObliqueEdgeTopAndBottomBetweenBorderNodeNotAsSameLevel() { - // {top,bottom,left,right} - boolean[] availableDirections = { false, true, false, false }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { false, true, true, false, false, false, false, false }; checkEdgeActions(availableDirections, "edge21"); } @@ -192,8 +221,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { * </UL> */ public void testRectilinearTopAndBottomOutOfBounds() { - // {top,bottom,left,right} - boolean[] availableDirections = { true, false, false, false }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { true, false, false, true, false, false, false, false }; checkEdgeActions(availableDirections, "edge14"); } @@ -204,8 +233,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { * </ul> */ public void testObliqueEdgeLinkedToBorderNodeWithSeveralEdges() { - // {top,bottom,left,right} - boolean[] availableDirections = { true, true, false, false }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { true, true, true, true, false, false, false, false }; checkEdgeActions(availableDirections, true, null, "edge4"); } @@ -216,8 +245,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { * </ul> */ public void testRectilinearEdgeLinkedToBorderNodeWithSeveralEdges() { - // {top,bottom,left,right} - boolean[] availableDirections = { false, false, true, true }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { false, false, false, false, true, true, true, true }; checkEdgeActions(availableDirections, true, null, "edge17"); } @@ -243,8 +272,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { * </ul> */ public void testObliqueEdgeTopAndBottomForbiddenForOverlap() { - // {top,bottom,left,right} - boolean[] availableDirections = { true, false, false, false }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { true, false, false, true, false, false, false, false }; checkEdgeActions(availableDirections, "edge6"); } @@ -252,8 +281,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { * Straighten rectilinear edge2 to *: Expected: menu disabled (not same axis) */ public void testRectilinearAllForbiddenForDifferentAxes() { - // {top,bottom,left,right} - boolean[] availableDirections = { false, false, false, false }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { false, false, false, false, false, false, false, false }; checkEdgeActions(availableDirections, "edge2"); } @@ -264,8 +293,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { * </ul> */ public void testRectilinearToRightWithLeftForbiddenBecauseofCentering() { - // {top,bottom,left,right} - boolean[] availableDirections = { false, false, false, true }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { false, false, false, false, false, true, true, false }; checkEdgeActions(availableDirections, "edge5"); } @@ -279,8 +308,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { public void testRectilinearToRightWithLeftForbiddenBecauseofCenteringWithZoom200() { editor.zoom(ZoomLevel.ZOOM_200); try { - // {top,bottom,left,right} - boolean[] availableDirections = { false, false, false, true }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { false, false, false, false, false, true, true, false }; checkEdgeActions(availableDirections, "edge5"); } finally { editor.zoom(ZoomLevel.ZOOM_100); @@ -291,8 +320,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { * Straighten edge3 AND edge5 to Right: Expected: OK (for both) */ public void testTwoEdgesToRightWithOneWithLeftForbidden() { - // {top,bottom,left,right} - boolean[] availableDirections = { false, false, false, true }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { false, false, false, false, false, true, true, false }; checkEdgeActions(availableDirections, "edge5", "edge3"); } @@ -311,13 +340,16 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { * to this edge without error. */ public void testTwoEdgesAllIncompatibleStraigthenAction() { - // {top,bottom,left,right} - boolean[] availableDirections = { true, true, false, true }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { true, true, true, true, false, true, true, false }; Map<Integer, EdgeImpact> directionsIndexToConcernedEdge = new HashMap<>(); - directionsIndexToConcernedEdge.put(0, EdgeImpact.SECOND_EDGE); - directionsIndexToConcernedEdge.put(1, EdgeImpact.SECOND_EDGE); + directionsIndexToConcernedEdge.put(0, EdgeImpact.FIRST_EDGE); + directionsIndexToConcernedEdge.put(1, EdgeImpact.FIRST_EDGE); + directionsIndexToConcernedEdge.put(2, EdgeImpact.FIRST_EDGE); directionsIndexToConcernedEdge.put(3, EdgeImpact.FIRST_EDGE); - checkEdgeActions(availableDirections, directionsIndexToConcernedEdge, "edge5", "edge15"); + directionsIndexToConcernedEdge.put(5, EdgeImpact.SECOND_EDGE); + directionsIndexToConcernedEdge.put(6, EdgeImpact.SECOND_EDGE); + checkEdgeActions(availableDirections, directionsIndexToConcernedEdge, "edge15", "edge5"); } /** @@ -330,8 +362,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { // Reveals the edit part to have scrollbar SWTBotGefEditPart editPart = editor.getEditPart("edge7", AbstractDiagramEdgeEditPart.class); editor.reveal(editPart.part()); - // {top,bottom,left,right} - boolean[] availableDirections = { false, true, false, false }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { false, true, false, true, false, false, false, false }; checkEdgeActions(availableDirections, "edge7"); } @@ -345,8 +377,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { // Reveals the edit part to have scrollbar SWTBotGefEditPart editPart = editor.getEditPart("edge14", AbstractDiagramEdgeEditPart.class); editor.reveal(editPart.part()); - // {top,bottom,left,right} - boolean[] availableDirections = { true, false, false, false }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { true, false, false, true, false, false, false, false }; checkEdgeActions(availableDirections, "edge14"); } @@ -358,8 +390,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { SWTBotGefEditPart editPart2 = editor.getEditPart("container3", AbstractDiagramContainerEditPart.class); editor.select(editPart1, editPart2); editor.reveal(editPart1.part()); - // {top,bottom,left,right} - boolean[] availableDirections = { false, true, false, false }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { false, true, true, false, false, false, false, false }; checkEdgeActions(availableDirections, "edge11"); } @@ -373,8 +405,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { SWTBotGefEditPart editPart2 = editor.getEditPart("edge12", AbstractDiagramNameEditPart.class); editor.select(editPart1, editPart2); editor.reveal(editPart1.part()); - // {top,bottom,left,right} - boolean[] availableDirections = { false, true, false, false }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { false, true, true, false, false, false, false, false }; checkEdgeActions(availableDirections, "edge11"); } @@ -387,8 +419,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { public void testObliqueEdgeTopAndBottomBetweenElementAtSameLevelButNotInSameContainer() { SWTBotGefEditPart editPart = editor.getEditPart("container9", AbstractDiagramContainerEditPart.class); editor.reveal(editPart.part()); - // {top,bottom,left,right} - boolean[] availableDirections = { false, true, false, false }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { false, true, true, false, false, false, false, false }; checkEdgeActions(availableDirections, "edge11"); } @@ -401,8 +433,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { public void testObliqueEdgeTopAndBottomBetweenElementNotAtSameLevel() { SWTBotGefEditPart editPart = editor.getEditPart("container9", AbstractDiagramContainerEditPart.class); editor.reveal(editPart.part()); - // {top,bottom,left,right} - boolean[] availableDirections = { true, false, false, false }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { true, false, true, false, false, false, false, false }; checkEdgeActions(availableDirections, "edge10"); } @@ -415,8 +447,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { public void testObliqueEdgeTopAndBottomBetweenBorderNodeAtSameLevelButNotInSameContainer() { SWTBotGefEditPart editPart = editor.getEditPart("container9", AbstractDiagramContainerEditPart.class); editor.reveal(editPart.part()); - // {top,bottom,left,right} - boolean[] availableDirections = { true, true, false, false }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { true, true, true, true, false, false, false, false }; checkEdgeActions(availableDirections, "edge13"); } @@ -424,8 +456,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { * Straighten edge22 AND edge23 to top and bottom: Expected: OK (for both) */ public void testTwoEdgesLinkedToBorderNodeWithOverlapBeforeStraighten() { - // {top,bottom,left,right} - boolean[] availableDirections = { true, true, false, false }; + // {top,bottom,leftSide,rightSide,left,right,topSide,BottomSide} + boolean[] availableDirections = { true, true, true, true, false, false, false, false }; checkEdgeActions(availableDirections, "edge22", "edge23"); } @@ -477,17 +509,21 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { * true if the bendpoints stability of edges linked to moved border node must also be checked (only * segment linked to border node must be moved), false otherwise * @param directionsIndexToConcernedEdge - * * @param edgeNames list of names corresponding to the edges to select. + * a map that associate the edge(s) that will be changed if the straighten command at the index given by + * the key is executed. The command to execute is the one represented by the direction at the given index + * of availableDirections parameter. + * @param edgeNames + * list of names corresponding to the edges to select. */ private void checkEdgeActions(boolean[] availableDirections, boolean checkOtherEdges, Map<Integer, EdgeImpact> directionsIndexToConcernedEdge, String... edgeNames) { - for (int i = 0; i < 4; i++) { - Map<SWTBotGefEditPart, List<Point>> gefEditParts2ExpectedPointList = Maps.newHashMap(); + for (int i = 0; i < 8; i++) { + Map<TestPart, List<Point>> gefEditParts2ExpectedPointList = Maps.newHashMap(); // Map only used if checkOtherEdges is true - Map<AbstractDiagramEdgeEditPart, PointList> otherEdgeEditParts2ExpectedPointList = Maps.newHashMap(); + Map<TestPart, PointList> otherEdgeEditParts2ExpectedPointList = Maps.newHashMap(); for (String edgeName : edgeNames) { - gefEditParts2ExpectedPointList.put(editor.getEditPart(edgeName, AbstractDiagramEdgeEditPart.class), Lists.<Point> newArrayList()); + gefEditParts2ExpectedPointList.put(new TestPart(edgeName, editor.getEditPart(edgeName, AbstractDiagramEdgeEditPart.class)), Lists.<Point> newArrayList()); } - editor.select(gefEditParts2ExpectedPointList.keySet()); + editor.select(gefEditParts2ExpectedPointList.keySet().stream().map(part -> part.swtBotpart).collect(Collectors.toSet())); try { boolean enable = SWTBotUtils.isMenuEnabled(bot.getDisplay(), editor.getDiagramEditPart().getViewer().getControl(), labels[i]); // The test fail if the action should not be enable and if it is @@ -499,33 +535,12 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { if (enable) { int j = 0; // if the action is enabled we check the result. - for (SWTBotGefEditPart edgeEditPart : gefEditParts2ExpectedPointList.keySet()) { - boolean computePoints = false; - if (directionsIndexToConcernedEdge != null) { - switch (directionsIndexToConcernedEdge.get(i)) { - case BOTH_EDGE: - if (j == 0 || j == 1) { - computePoints = true; - } - break; - case FIRST_EDGE: - if (j == 0) { - computePoints = true; - } - break; - case SECOND_EDGE: - if (j == 1) { - computePoints = true; - } - break; - default: - computePoints = true; - break; - } - - } + for (String edgeName : edgeNames) { + TestPart testPart = gefEditParts2ExpectedPointList.keySet().stream().filter(part -> edgeName.equals(part.partName)).findFirst().get(); + SWTBotGefEditPart edgeEditPart = testPart.swtBotpart; + boolean computePoints = checkEdge(directionsIndexToConcernedEdge, i, j); if (computePoints) { - List<Point> pointList = gefEditParts2ExpectedPointList.get(edgeEditPart); + List<Point> pointList = gefEditParts2ExpectedPointList.get(testPart); computeExpectedPoints(edgeEditPart, pointList, i); if (checkOtherEdges) { computeOtherEdgesExpectedPoints(edgeEditPart, otherEdgeEditParts2ExpectedPointList, i); @@ -535,33 +550,12 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { } editor.clickContextMenu(labels[i]); j = 0; - for (SWTBotGefEditPart edgeEditPart : gefEditParts2ExpectedPointList.keySet()) { - boolean checkResult = false; - if (directionsIndexToConcernedEdge != null) { - switch (directionsIndexToConcernedEdge.get(i)) { - case BOTH_EDGE: - if (j == 0 || j == 1) { - checkResult = true; - } - break; - case FIRST_EDGE: - if (j == 0) { - checkResult = true; - } - break; - case SECOND_EDGE: - if (j == 1) { - checkResult = true; - } - break; - default: - checkResult = true; - break; - } - - } + for (String edgeName : edgeNames) { + TestPart testPart = gefEditParts2ExpectedPointList.keySet().stream().filter(part -> edgeName.equals(part.partName)).findFirst().get(); + SWTBotGefEditPart edgeEditPart = testPart.swtBotpart; + boolean checkResult = checkEdge(directionsIndexToConcernedEdge, i, j); if (checkResult) { - List<Point> pointList = gefEditParts2ExpectedPointList.get(edgeEditPart); + List<Point> pointList = gefEditParts2ExpectedPointList.get(testPart); checkResult(edgeEditPart, pointList, i); if (checkOtherEdges) { checkResultOfOtherEdges(edgeEditPart, otherEdgeEditParts2ExpectedPointList); @@ -578,6 +572,49 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { } /** + * Checks that the j th edge selected is changed by the straighten command at i index and thus it's change should be + * verified. + * + * @param directionsIndexToConcernedEdge + * the map that gives the edges impacted by the straighten command at the key position. + * @param i + * the index of the straighten command to execute. + * @param j + * the j th edge selected before executing the straighten command. + * @return true the j th edge selected is changed by the straighten command at i index and thus it's change should + * be verified. False otherwise + */ + private boolean checkEdge(Map<Integer, EdgeImpact> directionsIndexToConcernedEdge, int i, int j) { + boolean checkEdge = false; + if (directionsIndexToConcernedEdge != null) { + // we only check result for edges concerned by the straighten command executed. + switch (directionsIndexToConcernedEdge.get(i)) { + case BOTH_EDGE: + if (j == 0 || j == 1) { + checkEdge = true; + } + break; + case FIRST_EDGE: + if (j == 0) { + checkEdge = true; + } + break; + case SECOND_EDGE: + if (j == 1) { + checkEdge = true; + } + break; + default: + checkEdge = true; + break; + } + } else { + checkEdge = true; + } + return checkEdge; + } + + /** * Checks that the current edge has the expected start and end points * * @param edgeEditPart @@ -608,12 +645,12 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { * @param otherEdgeEditParts2ExpectedPointList * the list where register the expected points, a point set to {-1, -1} is to ignore in the comparison */ - private void checkResultOfOtherEdges(SWTBotGefEditPart edgeEditPart, Map<AbstractDiagramEdgeEditPart, PointList> otherEdgeEditParts2ExpectedPointList) { - for (Entry<AbstractDiagramEdgeEditPart, PointList> entry : otherEdgeEditParts2ExpectedPointList.entrySet()) { - PolylineConnectionEx polylineConnection = entry.getKey().getPolylineConnectionFigure(); + private void checkResultOfOtherEdges(SWTBotGefEditPart edgeEditPart, Map<TestPart, PointList> otherEdgeEditParts2ExpectedPointList) { + for (Entry<TestPart, PointList> entry : otherEdgeEditParts2ExpectedPointList.entrySet()) { + PolylineConnectionEx polylineConnection = entry.getKey().part.getPolylineConnectionFigure(); for (int i = 0; i < entry.getValue().size(); i++) { if (!IGNORED_POINT.equals(entry.getValue().getPoint(i))) { - assertEquals("The point \"" + i + "\" of edge \"" + getLabelFromEdgeEditPart(entry.getKey()) + "\" is not valid.", entry.getValue().getPoint(i), + assertEquals("The point \"" + i + "\" of edge \"" + getLabelFromEdgeEditPart(entry.getKey().part) + "\" is not valid.", entry.getValue().getPoint(i), polylineConnection.getPoints().getPoint(i)); } } @@ -689,9 +726,33 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { expectedEndPoint.setX(endPointBefore.x()); } break; - // left + // left side case 2: if (startPointBefore.x <= endPointBefore.x) { + expectedEndPoint.setY(expectedStartPoint.y); + } else { + expectedStartPoint.setY(expectedEndPoint.y); + } + if (specificCase) { + expectedStartPoint.setX(startPointBefore.x()); + expectedEndPoint.setX(endPointBefore.x()); + } + break; + // right side + case 3: + if (startPointBefore.x <= endPointBefore.x) { + expectedStartPoint.setY(expectedEndPoint.y); + } else { + expectedEndPoint.setY(expectedStartPoint.y); + } + if (specificCase) { + expectedStartPoint.setX(startPointBefore.x()); + expectedEndPoint.setX(endPointBefore.x()); + } + break; + // left + case 4: + if (startPointBefore.x <= endPointBefore.x) { expectedEndPoint.setX(expectedStartPoint.x); } else { expectedStartPoint.setX(expectedEndPoint.x); @@ -702,7 +763,7 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { } break; // right - case 3: + case 5: if (startPointBefore.x <= endPointBefore.x) { expectedStartPoint.setX(expectedEndPoint.x); } else { @@ -714,7 +775,30 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { } break; - + // top side + case 6: + if (startPointBefore.y <= endPointBefore.y) { + expectedEndPoint.setX(expectedStartPoint.x); + } else { + expectedStartPoint.setX(expectedEndPoint.x); + } + if (specificCase) { + expectedStartPoint.setY(startPointBefore.y()); + expectedEndPoint.setY(endPointBefore.y()); + } + break; + // bottom side + case 7: + if (startPointBefore.y <= endPointBefore.y) { + expectedStartPoint.setX(expectedEndPoint.x); + } else { + expectedEndPoint.setX(expectedStartPoint.x); + } + if (specificCase) { + expectedStartPoint.setY(startPointBefore.y()); + expectedEndPoint.setY(endPointBefore.y()); + } + break; default: break; } @@ -731,7 +815,7 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { * @param i * the current action index in labels order {top,bottom,left,right} order */ - private void computeOtherEdgesExpectedPoints(SWTBotGefEditPart edgeEditPart, Map<AbstractDiagramEdgeEditPart, PointList> otherEdgeEditParts2ExpectedPointList, int i) { + private void computeOtherEdgesExpectedPoints(SWTBotGefEditPart edgeEditPart, Map<TestPart, PointList> otherEdgeEditParts2ExpectedPointList, int i) { AbstractDiagramEdgeEditPart part = (AbstractDiagramEdgeEditPart) edgeEditPart.part(); PolylineConnectionEx polylineConnection = part.getPolylineConnectionFigure(); Point startPointBefore = polylineConnection.getStart(); @@ -800,7 +884,7 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { * the list where register the expected points, a point set to {-1, -1} is to ignore in the comparison */ private void computeOtherEdgesExpectedPoints(AbstractDiagramBorderNodeEditPart borderNodeEditPart, AbstractDiagramEdgeEditPart selectedEdgeEditPart, - Map<AbstractDiagramEdgeEditPart, PointList> otherEdgeEditParts2ExpectedPointList) { + Map<TestPart, PointList> otherEdgeEditParts2ExpectedPointList) { for (AbstractDiagramEdgeEditPart edgeEditPart : Iterables.filter(borderNodeEditPart.getSourceConnections(), AbstractDiagramEdgeEditPart.class)) { if (!edgeEditPart.equals(selectedEdgeEditPart)) { PolylineConnectionEx polylineConnection = edgeEditPart.getPolylineConnectionFigure(); @@ -814,7 +898,7 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { pointList.setPoint(IGNORED_POINT, 0); pointList.setPoint(IGNORED_POINT, 1); } - otherEdgeEditParts2ExpectedPointList.put(edgeEditPart, pointList); + otherEdgeEditParts2ExpectedPointList.put(new TestPart(((DEdgeNameEditPart) edgeEditPart.getChildren().get(0)).getLabelText(), edgeEditPart), pointList); } } for (AbstractDiagramEdgeEditPart edgeEditPart : Iterables.filter(borderNodeEditPart.getTargetConnections(), AbstractDiagramEdgeEditPart.class)) { @@ -830,7 +914,8 @@ public class StraightenToTest extends AbstractSiriusSwtBotGefTestCase { pointList.setPoint(IGNORED_POINT, pointList.size() - 1); pointList.setPoint(IGNORED_POINT, pointList.size() - 2); } - otherEdgeEditParts2ExpectedPointList.put(edgeEditPart, pointList); + otherEdgeEditParts2ExpectedPointList.put( + new TestPart(((DEdgeNameEditPart) edgeEditPart.getChildren().stream().filter(DEdgeNameEditPart.class::isInstance).findFirst().get()).getLabelText(), edgeEditPart), pointList); } } } diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/tabbar/TabBarTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/tabbar/TabBarTest.java index f019974db8..f1725a6103 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/tabbar/TabBarTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/tabbar/TabBarTest.java @@ -95,8 +95,8 @@ public class TabBarTest extends AbstractSiriusSwtBotGefTestCase { private static final String[] DIAGRAM_TOOLBARTOGGLEBUTTONS_TOOLTIPS = { Messages.LayoutingModeSwitchingAction_activate }; - private static final String[] CONTAINER_TOOLBARDROPDOWNBUTTONS_TOOLTIPS = { "Arrange Selection", "Straighten to left", "Align Left", - DistributeAction.getTooltip(DistributeAction.GAPS_HORIZONTALLY), "Font Color", "Fill &Color", "Li&ne Color", "Line Style" }; + private static final String[] CONTAINER_TOOLBARDROPDOWNBUTTONS_TOOLTIPS = { "Arrange Selection", "Align Left", DistributeAction.getTooltip(DistributeAction.GAPS_HORIZONTALLY), "Straighten to top", + "Font Color", "Fill &Color", "Li&ne Color", "Line Style" }; private static final String[] CONTAINER_TOOLBARBUTTONS_TOOLTIPS = { Messages.PinElementsEclipseAction_text, Messages.UnpinElementsEclipseAction_text, Messages.CopyFormatAction_toolTipText, Messages.SiriusDiagramActionBarContributor_hideElement, Messages.SiriusDiagramActionBarContributor_hideLabel, Messages.SiriusDiagramActionBarContributor_deleteFromDiagram, |
