aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2018-06-25 08:37:52 -0400
committerNicolas FAUVERGUE2018-07-06 04:10:40 -0400
commitab2727e4253b6bb8f4dbb9303ff62c882ee28b17 (patch)
tree803d82689829608eadb962838ef1d905c3dbff2a
parent5af9263e49248bbaa7048522909cda202f37642b (diff)
downloadorg.eclipse.papyrus-ab2727e4253b6bb8f4dbb9303ff62c882ee28b17.tar.gz
org.eclipse.papyrus-ab2727e4253b6bb8f4dbb9303ff62c882ee28b17.tar.xz
org.eclipse.papyrus-ab2727e4253b6bb8f4dbb9303ff62c882ee28b17.zip
Bug 533697: [Sequence Diagram] InteractionOperand shall be reordered
pressing a combination key in the CombinedFragment https://bugs.eclipse.org/bugs/show_bug.cgi?id=533697 - Restructure the Resize and DragDrop policies for InteractionOperands - Allow reordering operands by drag & drop Change-Id: Id0ce8dbde49030f810c0c5c2f8b602f44eed6150 Signed-off-by: Camille Letavernier <cletavernier@eclipsesource.com>
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/.settings/.api_filters33
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/META-INF/MANIFEST.MF2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CInteractionOperandEditPart.java12
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandDragDropEditPolicy.java152
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandResizePolicy.java76
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ResizeOperandEditPolicy.java4
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/pom.xml2
7 files changed, 226 insertions, 55 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/.settings/.api_filters b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/.settings/.api_filters
new file mode 100644
index 00000000000..3d7cee1853b
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/.settings/.api_filters
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<component id="org.eclipse.papyrus.uml.diagram.sequence" version="2">
+ <resource path="custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandDragDropEditPolicy.java" type="org.eclipse.papyrus.uml.diagram.sequence.edit.policies.InteractionOperandDragDropEditPolicy">
+ <filter comment="API moved to InteractionOperandResizePolicy" id="337682486">
+ <message_arguments>
+ <message_argument value="org.eclipse.papyrus.uml.diagram.sequence.edit.policies.InteractionOperandDragDropEditPolicy"/>
+ </message_arguments>
+ </filter>
+ <filter comment="API moved to InteractionOperandResizePolicy" id="338755678">
+ <message_arguments>
+ <message_argument value="org.eclipse.papyrus.uml.diagram.sequence.edit.policies.InteractionOperandDragDropEditPolicy"/>
+ <message_argument value="MIN_HEIGHT"/>
+ </message_arguments>
+ </filter>
+ <filter comment="API moved to InteractionOperandResizePolicy" id="338755678">
+ <message_arguments>
+ <message_argument value="org.eclipse.papyrus.uml.diagram.sequence.edit.policies.InteractionOperandDragDropEditPolicy"/>
+ <message_argument value="MIN_WIDTH"/>
+ </message_arguments>
+ </filter>
+ <filter comment="API moved to InteractionOperandResizePolicy" id="338792546">
+ <message_arguments>
+ <message_argument value="org.eclipse.papyrus.uml.diagram.sequence.edit.policies.InteractionOperandDragDropEditPolicy"/>
+ <message_argument value="getResizeCommand(ChangeBoundsRequest)"/>
+ </message_arguments>
+ </filter>
+ <filter comment="API moved to InteractionOperandResizePolicy" id="338849923">
+ <message_arguments>
+ <message_argument value="org.eclipse.papyrus.uml.diagram.sequence.edit.policies.InteractionOperandDragDropEditPolicy"/>
+ </message_arguments>
+ </filter>
+ </resource>
+</component>
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/META-INF/MANIFEST.MF
index afd9db21e9f..4294ef024c9 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/META-INF/MANIFEST.MF
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/META-INF/MANIFEST.MF
@@ -69,7 +69,7 @@ Require-Bundle: org.eclipse.ui.navigator;bundle-version="[3.6.0,4.0.0)";visibili
org.eclipse.papyrus.uml.service.validation;bundle-version="[2.1.0,3.0.0)",
org.eclipse.papyrus.infra.services.validation;bundle-version="[3.0.0,4.0.0)"
Bundle-Vendor: %providerName
-Bundle-Version: 5.0.100.qualifier
+Bundle-Version: 5.1.0.qualifier
Bundle-ManifestVersion: 2
Bundle-Activator: org.eclipse.papyrus.uml.diagram.sequence.part.UMLDiagramEditorPlugin
Bundle-SymbolicName: org.eclipse.papyrus.uml.diagram.sequence; singleton:=true
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CInteractionOperandEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CInteractionOperandEditPart.java
index 397632f44a7..578542dd0f4 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CInteractionOperandEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CInteractionOperandEditPart.java
@@ -17,13 +17,13 @@ import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.EditPartListener;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.InteractionOperandResizePolicy;
import org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling.BoundForEditPart;
/**
@@ -73,15 +73,17 @@ public class CInteractionOperandEditPart extends InteractionOperandEditPart {
super.refresh();
}
+
/**
- * @see org.eclipse.gef.editparts.AbstractEditPart#removeEditPartListener(org.eclipse.gef.EditPartListener)
+ * @see org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionOperandEditPart#createDefaultEditPolicies()
*
- * @param listener
*/
@Override
- public void removeEditPartListener(EditPartListener listener) {
- super.removeEditPartListener(listener);
+ protected void createDefaultEditPolicies() {
+ super.createDefaultEditPolicies();
+ installEditPolicy(InteractionOperandResizePolicy.class.getSimpleName(), new InteractionOperandResizePolicy());
}
+
/**
* this method method has been overloaded because of a mistake in the gmfgen.
* so we has to implement addition of sub-figures inside the primary figure...
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandDragDropEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandDragDropEditPolicy.java
index 4b68a9243a2..4e86de1832a 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandDragDropEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandDragDropEditPolicy.java
@@ -14,73 +14,133 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.edit.policies;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.draw2d.geometry.Dimension;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gef.editpolicies.ResizableEditPolicy;
import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
+import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
+import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.gmf.runtime.notation.Bounds;
+import org.eclipse.gmf.runtime.notation.LayoutConstraint;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.sequence.command.SetLocationCommand;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionOperandEditPart;
+import org.eclipse.uml2.uml.CombinedFragment;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.InteractionOperand;
+import org.eclipse.uml2.uml.UMLPackage;
/**
- * The customn DragDropEditPolicy for InteractionOperandEditPart.
+ * The custom DragDropEditPolicy for InteractionOperandEditPart.
*/
-public class InteractionOperandDragDropEditPolicy extends ResizableEditPolicy {
+public class InteractionOperandDragDropEditPolicy extends DragDropEditPolicy {
/**
- * The minimum height for the Operand. The policy will reject resize operations
- * if they would result in a smaller height
+ * @see org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy#getCommand(org.eclipse.gef.Request)
*
- * @since 5.0
- */
- public static final int MIN_HEIGHT = 5;
-
- /**
- * The minimum width for the Operand. The policy will reject resize operations
- * if they would result in a smaller width
- *
- * @since 5.0
- */
- public static final int MIN_WIDTH = 5;
-
- /**
- * Disable drag and allow only south resize. {@inheritDoc}
+ * @param request
+ * @return
*/
- public InteractionOperandDragDropEditPolicy() {
- super();
- setDragAllowed(false);
-
- // Bug 533770: The layout is now handled exclusively by the parent.
- // The operand is no longer directly resizable. It may still provide
- // a height hint (Integer or Rectangle, height in pixels)
- setResizeDirections(PositionConstants.NONE);
+ @Override
+ public Command getCommand(Request request) {
+ return super.getCommand(request);
}
/**
- * @see org.eclipse.gef.editpolicies.ResizableEditPolicy#getResizeCommand(org.eclipse.gef.requests.ChangeBoundsRequest)
+ * @see org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy#getDropCommand(org.eclipse.gef.requests.ChangeBoundsRequest)
*
* @param request
* @return
*/
@Override
- protected Command getResizeCommand(ChangeBoundsRequest request) {
- Dimension delta = new Dimension(request.getSizeDelta());
- IFigure figure = getHostFigure();
- if (figure != null) {
- Dimension currentDimension = figure.getBounds().getSize();
-
- // Take zoom into account; the request contains absolute mouse coordinates delta.
- figure.translateToRelative(delta);
- Dimension newDimension = currentDimension.expand(delta);
- if (newDimension.width() < MIN_WIDTH || newDimension.height < MIN_HEIGHT) {
- // XXX Currently we just reject the request. Ideally, we'd simply edit
- // the request to match the min size. However, since this policy is typically
- // called by the CF during its resize, we'd have to change that request, too. But we can't do that from here;
- // so it's easier to just reject the request.
+ @SuppressWarnings("unchecked") // GMF is Java 1.4
+ protected Command getDropCommand(ChangeBoundsRequest request) {
+ List<EditPart> editParts = request.getEditParts();
+
+ if (editParts.size() == 1 && editParts.get(0) instanceof InteractionOperandEditPart) {
+ InteractionOperandEditPart partToMove = (InteractionOperandEditPart) editParts.get(0);
+ InteractionOperand operandToReorder = getOperand(partToMove);
+
+ EditPart fragmentCptPart = getHost().getParent();
+ CombinedFragment fragment = getCombinedFragment();
+ if (fragment == null || false == fragmentCptPart instanceof IGraphicalEditPart) {
return UnexecutableCommand.INSTANCE;
}
+ IGraphicalEditPart fragmentGEP = (IGraphicalEditPart)fragmentCptPart;
+ CompositeCommand command = new CompositeCommand("Reorder operands");
+ List<InteractionOperand> operands = new ArrayList<>(fragment.getOperands());
+ if (! operands.contains(operandToReorder)) {
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ // Reorder semantic elements
+ int newIndex = operands.indexOf(getHostOperand());
+ operands.remove(operandToReorder);
+ operands.add(newIndex, operandToReorder);
+ SetRequest semanticReorder = new SetRequest(fragment, UMLPackage.Literals.COMBINED_FRAGMENT__OPERAND, operands);
+ command.add(new SetValueCommand(semanticReorder));
+
+ // Reorder notation elements
+ List<View> operandViews = new ArrayList<>(fragmentGEP.getNotationView().getChildren());
+ View operandViewToReorder = partToMove.getNotationView();
+ operandViews.remove(operandViewToReorder);
+ operandViews.add(newIndex, operandViewToReorder);
+ SetRequest graphicalReorder = new SetRequest(fragmentGEP.getNotationView(), NotationPackage.Literals.VIEW__PERSISTED_CHILDREN, operandViews);
+ command.add(new SetValueCommand(graphicalReorder));
+
+ // Compute the new bounds of each view, based on the new order
+ // The height of each operand didn't change, so we just have to compute the sum of heights for each previous view
+ int y = 0;
+ CompositeCommand updateBounds = new CompositeCommand("Update operands bounds");
+ TransactionalEditingDomain editingDomain = ((IGraphicalEditPart)getHost()).getEditingDomain();
+ for (View view : operandViews) {
+ if (view instanceof Node) {
+ Node node = (Node)view;
+ LayoutConstraint layoutConstraint = node.getLayoutConstraint();
+ if (layoutConstraint instanceof Bounds) {
+ Bounds currentBounds = (Bounds)layoutConstraint;
+ Point newPos = new Point(0, y);
+ updateBounds.add(new SetLocationCommand(editingDomain, "Update bounds", new EObjectAdapter(node), newPos));
+ y += currentBounds.getHeight();
+ }
+ }
+ }
+ command.add(updateBounds);
+
+ return new ICommandProxy(command);
}
- return super.getResizeCommand(request);
+ return null;
}
+
+ private InteractionOperand getOperand(InteractionOperandEditPart editPart) {
+ EObject element = editPart.getNotationView().getElement();
+ return element instanceof InteractionOperand ? (InteractionOperand)element : null;
+ }
+
+ private CombinedFragment getCombinedFragment() {
+ InteractionOperand operand = getHostOperand();
+ Element parent = operand == null ? null : operand.getOwner();
+ return parent instanceof CombinedFragment ? (CombinedFragment) parent : null;
+ }
+
+ private InteractionOperand getHostOperand() {
+ EObject hostSemantic = getHostObject();
+ return hostSemantic instanceof InteractionOperand ? (InteractionOperand)hostSemantic : null;
+ }
+
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandResizePolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandResizePolicy.java
new file mode 100644
index 00000000000..697cb8611da
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandResizePolicy.java
@@ -0,0 +1,76 @@
+/*****************************************************************************
+ * Copyright (c) 2018 CEA LIST, EclipseSource 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * EclipseSource - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.sequence.edit.policies;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gef.editpolicies.ResizableEditPolicy;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+
+/**
+ * The resize policy for InteractionOperands.
+ *
+ * @since 5.1
+ */
+public class InteractionOperandResizePolicy extends ResizableEditPolicy {
+
+ /**
+ * The minimum height for the Operand. The policy will reject resize operations
+ * if they would result in a smaller height
+ */
+ public static final int MIN_HEIGHT = 5;
+
+ /**
+ * The minimum width for the Operand. The policy will reject resize operations
+ * if they would result in a smaller width
+ */
+ public static final int MIN_WIDTH = 5;
+
+ /**
+ * Disable drag and allow only south resize. {@inheritDoc}
+ */
+ public InteractionOperandResizePolicy() {
+ super();
+ // Bug 533770: The layout is now handled exclusively by the parent.
+ // The operand is no longer directly resizable. It may still provide
+ // a height hint (Integer or Rectangle, height in pixels)
+ setResizeDirections(PositionConstants.NONE);
+ setDragAllowed(false);
+ }
+
+ @Override
+ protected Command getResizeCommand(ChangeBoundsRequest request) {
+ Dimension delta = new Dimension(request.getSizeDelta());
+ IFigure figure = getHostFigure();
+ if (figure != null) {
+ Dimension currentDimension = figure.getBounds().getSize();
+
+ // Take zoom into account; the request contains absolute mouse coordinates delta.
+ figure.translateToRelative(delta);
+ Dimension newDimension = currentDimension.expand(delta);
+ if (newDimension.width() < MIN_WIDTH || newDimension.height < MIN_HEIGHT) {
+ // XXX Currently we just reject the request. Ideally, we'd simply edit
+ // the request to match the min size. However, since this policy is typically
+ // called by the CF during its resize, we'd have to change that request, too. But we can't do that from here;
+ // so it's easier to just reject the request.
+ return UnexecutableCommand.INSTANCE;
+ }
+ }
+
+ return super.getResizeCommand(request);
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ResizeOperandEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ResizeOperandEditPolicy.java
index 7f4cf8f0054..9fa44ce77e7 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ResizeOperandEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ResizeOperandEditPolicy.java
@@ -41,8 +41,8 @@ import org.eclipse.uml2.uml.InteractionOperand;
/**
- * This class is used to allow the resize and adding of children of the combined Fragment
- *
+ * This class is used to allow the resize and adding of children of the combined Fragment.
+ * It is applied on the CombinedFragment
*/
public class ResizeOperandEditPolicy extends GraphicalEditPolicy {
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/pom.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/pom.xml
index eb6100e75c9..b1953dacc59 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/pom.xml
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/pom.xml
@@ -7,6 +7,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.uml.diagram.sequence</artifactId>
- <version>5.0.100-SNAPSHOT</version>
+ <version>5.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project> \ No newline at end of file