aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2018-04-25 16:28:05 -0400
committerNicolas FAUVERGUE2018-05-14 11:15:01 -0400
commit3ef042ffd8437bcc54f7b2258bcea0b6962f110c (patch)
tree2c95fb747c64ef6d66fbf61c84f315c1a74a9093
parentffad788980af9a4d5dc533f283a29915cc13a786 (diff)
downloadorg.eclipse.papyrus-3ef042ffd8437bcc54f7b2258bcea0b6962f110c.zip
org.eclipse.papyrus-3ef042ffd8437bcc54f7b2258bcea0b6962f110c.tar.gz
org.eclipse.papyrus-3ef042ffd8437bcc54f7b2258bcea0b6962f110c.tar.xz
Bug 533699: [Sequence Diagram] InteractionOperand Guard should not be moved
Disable moving of interaction operand guards. Resize was already disabled. Add JUnit test coverage for both move and resize. Change-Id: Ibbb29ff64f684b184be1efc6142f7c35df218399 Signed-off-by: Christian W. Damus <give.a.damus@gmail.com>
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/InteractionOperandGuardEditPart.java16
-rw-r--r--tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/CommandMatchers.java16
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/CombinedFragmentRegressionTest.java76
3 files changed, 102 insertions, 6 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/InteractionOperandGuardEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/InteractionOperandGuardEditPart.java
index a95d772..f1fe69c 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/InteractionOperandGuardEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/InteractionOperandGuardEditPart.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013 CEA
+ * Copyright (c) 2013, 2018 CEA, Christian W. Damus, and others
*
*
* All rights reserved. This program and the accompanying materials
@@ -10,6 +10,7 @@
* Contributors:
* Soyatec - Initial API and implementation
* Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 533689
+ * Christian W. Damus - bug 533699
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.edit.parts;
@@ -252,6 +253,19 @@ public class InteractionOperandGuardEditPart extends ShapeEditPart implements IT
feedback.translateToAbsolute(rect);
request.setMoveDelta(new Point(rect.x - initialAbsBounds.x, rect.y - initialAbsBounds.y));
}
+
+ /**
+ * Disable moving of the interaction operand guard, per
+ * <a href="http://eclip.se/533699">bug 533699</a>.
+ *
+ * @return {@code false}, always
+ *
+ * @see <a href="http://eclip.se/533699">bug 533699</a>
+ */
+ @Override
+ public boolean isDragAllowed() {
+ return false;
+ }
};
}
diff --git a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/CommandMatchers.java b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/CommandMatchers.java
index 3cd355c..c8e7f58 100644
--- a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/CommandMatchers.java
+++ b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/CommandMatchers.java
@@ -17,7 +17,7 @@ import java.util.function.Predicate;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
-import org.hamcrest.TypeSafeMatcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
/**
* Matchers for commands of various flavours, which are defined in nested classes.
@@ -34,15 +34,21 @@ public final class CommandMatchers {
}
static <C> Matcher<C> executable(Predicate<? super C> canExecute) {
- return new TypeSafeMatcher<C>() {
+ return new TypeSafeDiagnosingMatcher<C>() {
@Override
public void describeTo(Description description) {
- description.appendText("unexecutable");
+ description.appendText("executable");
}
@Override
- protected boolean matchesSafely(C item) {
- return canExecute.test(item);
+ protected boolean matchesSafely(C item, Description mismatch) {
+ boolean result = canExecute.test(item);
+
+ if (!result) {
+ mismatch.appendText("unexecutable");
+ }
+
+ return result;
}
};
}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/CombinedFragmentRegressionTest.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/CombinedFragmentRegressionTest.java
index 83a0afb..5cdd09f 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/CombinedFragmentRegressionTest.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/CombinedFragmentRegressionTest.java
@@ -34,12 +34,22 @@ import static org.junit.Assume.assumeThat;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequestFactory;
@@ -523,6 +533,72 @@ public class CombinedFragmentRegressionTest extends AbstractPapyrusTest {
.or(instanceOf(Comment.class)))));
}
+ /**
+ * Verify that the guard of an interaction operand cannot be moved.
+ */
+ @Test
+ @PluginResource("resource/bugs/bug533681.di")
+ public void attemptToMoveOperandGuard_533699() {
+ operandGuardUnchangeable("move", ep -> {
+ Rectangle currentBounds = ep.getFigure().getBounds();
+ ChangeBoundsRequest result = new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
+ Point moveDelta = new Point(5, 5); // Just a nudge
+ Point newLoc = currentBounds.getLocation().getTranslated(moveDelta);
+ result.setLocation(newLoc); // Within the constraint shape
+ result.setMoveDelta(moveDelta);
+ result.setConstrainedMove(false);
+ result.setSnapToEnabled(false);
+ return result;
+ });
+ }
+
+ private void operandGuardUnchangeable(String action, Function<? super GraphicalEditPart, ? extends Request> requestFunction) {
+ EditPart combinedFragmentEP = editor.findEditPart("cfrag", CombinedFragment.class);
+ CombinedFragment cfrag = (CombinedFragment) combinedFragmentEP.getAdapter(EObject.class);
+ Interaction interaction = cfrag.getEnclosingInteraction();
+ assumeThat("No interaction", interaction, notNullValue());
+
+ InteractionOperand alt1 = cfrag.getOperand("alt1");
+ Constraint alt1Guard = alt1.getGuard();
+ InteractionOperand alt2 = cfrag.getOperand("alt2");
+ Constraint alt2Guard = alt2.getGuard();
+
+ List<GraphicalEditPart> guardEPs = Stream.of(alt1Guard, alt2Guard)
+ .map(g -> editor.requireEditPart(editor.getActiveDiagram(), g))
+ .filter(GraphicalEditPart.class::isInstance).map(GraphicalEditPart.class::cast)
+ .collect(Collectors.toList());
+ assertThat(guardEPs.size(), greaterThanOrEqual(2));
+
+ guardEPs.forEach(ep -> {
+ Request request = requestFunction.apply(ep);
+
+ EditPart target = ep.getTargetEditPart(request);
+ if (target != null) {
+ Command command = target.getCommand(request);
+ assertThat("Can " + action + " guard", command, not(CommandMatchers.GEF.canExecute()));
+ } // null target EP is a way to disable the request
+ });
+ }
+
+ /**
+ * Verify that the guard of an interaction operand cannot be resized.
+ */
+ @Test
+ @PluginResource("resource/bugs/bug533681.di")
+ public void attemptToResizeOperandGuard_533699() {
+ operandGuardUnchangeable("resize", ep -> {
+ Rectangle currentBounds = ep.getFigure().getBounds();
+ ChangeBoundsRequest result = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE);
+ result.setLocation(currentBounds.getBottomRight());
+ result.setSizeDelta(new Dimension(5, 5)); // Just a tweak
+ result.setResizeDirection(PositionConstants.SOUTH_WEST);
+ result.setConstrainedResize(false);
+ result.setCenteredResize(false);
+ result.setSnapToEnabled(false);
+ return result;
+ });
+ }
+
//
// Test framework
//