Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2018-05-04 14:35:27 +0000
committerNicolas FAUVERGUE2018-05-22 15:58:01 +0000
commit6abb6f2000f2efe7201bcdf989572fffa302a943 (patch)
tree1e2afa7cfe4b0cc9990bd71bd7d34940d5b3d141
parentd4f0d45f9f3881b9313349150e37ab03a779647c (diff)
downloadorg.eclipse.papyrus-6abb6f2000f2efe7201bcdf989572fffa302a943.tar.gz
org.eclipse.papyrus-6abb6f2000f2efe7201bcdf989572fffa302a943.tar.xz
org.eclipse.papyrus-6abb6f2000f2efe7201bcdf989572fffa302a943.zip
Bug 533678: [Sequence Diagram] Creation of a new InteractionOperand in a
CombinedFragment https://bugs.eclipse.org/bugs/show_bug.cgi?id=533678 Change-Id: I4f13d706fbca0620c9d3f415718ca6533860ccf2 Signed-off-by: Camille Letavernier <cletavernier@eclipsesource.com>
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.edit/META-INF/MANIFEST.MF2
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.edit/pom.xml2
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.edit/src/org/eclipse/papyrus/infra/services/edit/commands/InsertAtCommand.java90
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.edit/src/org/eclipse/papyrus/infra/services/edit/utils/RequestParameterConstants.java48
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/CombinedCreationEditPolicy.java180
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandLayoutEditPolicy.java21
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ResizeOperandEditPolicy.java23
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/CombinedFragmentEditHelperAdvice.java29
8 files changed, 326 insertions, 69 deletions
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/META-INF/MANIFEST.MF b/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/META-INF/MANIFEST.MF
index f10cd73952c..48a9d196f2f 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/META-INF/MANIFEST.MF
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/META-INF/MANIFEST.MF
@@ -14,7 +14,7 @@ Require-Bundle: org.eclipse.gmf.runtime.emf.type.core;bundle-version="[1.9.0,2.0
org.eclipse.papyrus.infra.core.architecture;bundle-version="[2.0.0,3.0.0)"
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
-Bundle-Version: 3.0.0.qualifier
+Bundle-Version: 3.1.0.qualifier
Bundle-Localization: plugin
Bundle-Name: %pluginName
Bundle-Activator: org.eclipse.papyrus.infra.services.edit.Activator
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/pom.xml b/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/pom.xml
index 6a9aa72899e..c6e94d651d6 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/pom.xml
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/pom.xml
@@ -6,6 +6,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.infra.services.edit</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project> \ No newline at end of file
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/src/org/eclipse/papyrus/infra/services/edit/commands/InsertAtCommand.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/src/org/eclipse/papyrus/infra/services/edit/commands/InsertAtCommand.java
new file mode 100644
index 00000000000..568fe2df346
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/src/org/eclipse/papyrus/infra/services/edit/commands/InsertAtCommand.java
@@ -0,0 +1,90 @@
+/*****************************************************************************
+ * Copyright (c) 2018 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: Bug 533678
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.edit.commands;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants;
+
+/**
+ * <p>
+ * A Command to move an element to the given index after its creation. This command
+ * is meant to be used as an <code>after create</code> command, via an {@link IEditHelperAdvice},
+ * as it doesn't take care of the creation.
+ * </p>
+ *
+ * <p>
+ * The command is based on the {@link RequestParameterConstants#INSERT_AT} parameter, and
+ * will retrieve all the required parameters from a {@link CreateElementRequest}. If some
+ * required parameters are missing, the command will do nothing and return {@link CommandResult#newOKCommandResult()}.
+ * It will <strong>not</strong> block the execution of other commands in the chain.
+ * </p>
+ *
+ * @since 3.1
+ */
+public class InsertAtCommand extends AbstractTransactionalCommand {
+
+ private final CreateElementRequest request;
+
+ public InsertAtCommand(CreateElementRequest request, String label) {
+ super(request.getEditingDomain(), label, null);
+ this.request = request;
+ }
+
+ public InsertAtCommand(CreateElementRequest request) {
+ this(request, "Insert element at " + getIndex(request));
+ }
+
+ private static int getIndex(CreateElementRequest request) {
+ Object indexParameter = request.getParameter(RequestParameterConstants.INSERT_AT);
+ return indexParameter instanceof Integer ? (Integer) indexParameter : -1;
+ }
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ int index = getIndex(request);
+ if (index < 0) {
+ return CommandResult.newOKCommandResult(); // Nothing to do
+ }
+ EObject newElement = request.getNewElement();
+ EObject container = request.getContainer();
+ EReference containmentFeature = request.getContainmentFeature();
+
+ // To be safe, this command will work if all input at present; otherwise, it will do nothing
+ // and return OK (We make sure the command won't prevent anything, even when used incorrectly)
+ if (newElement != null && containmentFeature != null && container != null) {
+ Object childrenValue = container.eGet(containmentFeature);
+ if (childrenValue instanceof EList) {
+ // We're not sure about the exact type of the list, but since we're moving an element already
+ // present inside it, it doesn't matter.
+ @SuppressWarnings("unchecked")
+ EList<EObject> children = (EList<EObject>) childrenValue;
+ if (index < children.size()) {
+ int currentIndex = children.indexOf(newElement);
+ if (currentIndex >= 0) { // Avoid IndexOutOfBounds if the element is not already present in the list
+ children.move(index, currentIndex);
+ }
+ }
+ }
+ }
+ return CommandResult.newOKCommandResult();
+ }
+} \ No newline at end of file
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/src/org/eclipse/papyrus/infra/services/edit/utils/RequestParameterConstants.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/src/org/eclipse/papyrus/infra/services/edit/utils/RequestParameterConstants.java
index 2d94ef3c125..6dd8b114dbe 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/src/org/eclipse/papyrus/infra/services/edit/utils/RequestParameterConstants.java
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/src/org/eclipse/papyrus/infra/services/edit/utils/RequestParameterConstants.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2011, 2015, 2018 CEA LIST, Christian W. Damus, and others.
+ * Copyright (c) 2011, 2015, 2018 CEA LIST, Christian W. Damus, 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
@@ -12,6 +12,7 @@
* Bonnabesse Fanch (ALL4TEC) fanch.bonnabesse@alltec.net - Bug 476872
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - bug 492522
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - bug 530026
+ * EclipseSource - Bug 533678
*****************************************************************************/
package org.eclipse.papyrus.infra.services.edit.utils;
@@ -114,7 +115,8 @@ public interface RequestParameterConstants {
/**
* indicates the string to take to build the name of the new element (typically, we will increments the provided string)
* if the value of the parameter can't be null. If the string is empty, the new element won't be named
- * @since 3.0
+ *
+ * @since 3.0
*/
public final static String BASE_NAME_TO_SET = "baseNameToSet"; //$NON-NLS-1$
@@ -134,7 +136,7 @@ public interface RequestParameterConstants {
* because it will have an inverse reference to some element of the relationship).
* The default value is {@code true} if the parameter is not specified. <b>Note</b>
* that this is different from the {@link #AFFECTS_TARGET} parameter.
- *
+ *
* @see #AFFECTS_TARGET
*/
public static final String AFFECTS_SOURCE = "papyrus.affectsSource"; //$NON-NLS-1$
@@ -145,7 +147,7 @@ public interface RequestParameterConstants {
* because it will have an inverse reference to some element of the relationship).
* The default value is {@code false} if the parameter is not specified. <b>Note</b>
* that this is different from the {@link #AFFECTS_SOURCE} parameter.
- *
+ *
* @see #AFFECTS_SOURCE
*/
public static final String AFFECTS_TARGET = "papyrus.affectsTarget"; //$NON-NLS-1$
@@ -170,6 +172,24 @@ public interface RequestParameterConstants {
*/
public static String DIALOG_CANCELLABLE = "DIALOG_CANCELLABLE"; //$NON-NLS-1$
+ /**
+ * <p>
+ * Parameter used to create a new element at the given index. The value must be
+ * an {@link Integer}.
+ * </p>
+ * <p>
+ * A Value lower than 0 means that the element should be inserted at the end of the list. This is equivalent
+ * to not specifying the parameter at all, and is the default behavior.
+ * </p>
+ * <p>
+ * <code>Note:</code> In general, <strong>this parameter is unsupported</strong>; it is only used in a few specific cases.
+ * If used outside of these few supported cases, the parameter will be ignored.
+ * </p>
+ *
+ * @since 3.1
+ */
+ public static final String INSERT_AT = "InsertAt"; //$NON-NLS-1$
+
//
// Nested types
//
@@ -183,14 +203,14 @@ public interface RequestParameterConstants {
* Obtains the value of a parameter of the given {@code type} from a {@code request},
* returning the parameter's default value (if any such is defined) in the case that it
* is absent from the request.
- *
+ *
* @param request
- * an edit request
+ * an edit request
* @param parameterName
- * the name of the parameter to retrieve
+ * the name of the parameter to retrieve
* @param type
- * the type of the parameter
- *
+ * the type of the parameter
+ *
* @return the parameter value, its default (if specified) in case it is absent from the
* {@code request}, or the {@code type}'s default-default otherwise
*/
@@ -217,14 +237,14 @@ public interface RequestParameterConstants {
/**
* Queries the default value of a boolean-valued request parameter.
- *
+ *
* @param parameterName
- * the boolean-value parameter for which to obtain the default value
- *
+ * the boolean-value parameter for which to obtain the default value
+ *
* @return the default value
- *
+ *
* @throws IllegalArgumentException
- * if the parameter is not boolean-valued or if it does not have a default value
+ * if the parameter is not boolean-valued or if it does not have a default value
*/
public static boolean defaultBoolean(String parameterName) {
switch (parameterName) {
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/CombinedCreationEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/CombinedCreationEditPolicy.java
index 250a58d0d49..7b48b580c57 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/CombinedCreationEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/CombinedCreationEditPolicy.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2017 CEA LIST and others.
+ * Copyright (c) 2017, 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
@@ -8,31 +8,100 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
+ * EclipseSource - Bugs 533770, 533678
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.edit.policies;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+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.emf.common.util.EList;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
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.CreateViewRequest.ViewDescriptor;
-import org.eclipse.gmf.runtime.notation.Bounds;
-import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.adapter.NotationAndTypeAdapter;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultCreationEditPolicy;
-import org.eclipse.papyrus.uml.diagram.sequence.command.SetResizeAndLocationCommand;
+import org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants;
+import org.eclipse.papyrus.uml.diagram.sequence.command.SetResizeCommand;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionOperandEditPart;
/**
* @author Patrick Tessier
* @since 3.0
- * This class is used to set location and dimension for the InteractionOperand
+ * This class is used to set location and dimension for the InteractionOperand
*
*/
public class CombinedCreationEditPolicy extends DefaultCreationEditPolicy {
/**
+ * {@inheritDoc}
+ *
+ * <p>
+ * The {@link CombinedCreationEditPolicy} also takes the {@link RequestParameterConstants#INSERT_AT}
+ * parameter into account, if present, to allow creating new operands in the middle of the CF's operands
+ * list.
+ * </p>
+ *
+ * @param request
+ * @return
+ */
+ @Override
+ protected Command getCreateCommand(CreateViewRequest request) {
+ Command createCommand = super.getCreateCommand(request);
+ if (request.getExtendedData().get(RequestParameterConstants.INSERT_AT) instanceof Integer) {
+ int insertAt = (Integer) request.getExtendedData().get(RequestParameterConstants.INSERT_AT);
+ if (insertAt >= 0) {
+ // The view descriptor has an index, but we can't rely on it: the descriptor is created directly
+ // by the palette tool, in a very generic layer, and always uses -1 as the index.
+ GraphicalEditPart graphicalHost = (GraphicalEditPart) getHost();
+ ICommand insertAtCommand = new AbstractTransactionalCommand(graphicalHost.getEditingDomain(), "Insert view at " + insertAt, null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ View container = graphicalHost.getNotationView();
+ EList<View> children = container.getPersistedChildren();
+ List<? extends ViewDescriptor> viewDescriptors = request.getViewDescriptors();
+ List<ViewDescriptor> reversedDescriptors = new ArrayList<>(viewDescriptors);
+ Collections.reverse(reversedDescriptors);
+ for (ViewDescriptor descriptor : reversedDescriptors) {
+ children.move(insertAt, (View) descriptor.getAdapter(View.class));
+ }
+ return CommandResult.newOKCommandResult();
+ }
+ };
+ return new ICommandProxy(createCommand == null ? insertAtCommand : new CommandProxy(createCommand).compose(insertAtCommand).reduce());
+ }
+ }
+ return createCommand;
+ }
+
+ /**
+ * <p>
+ * Adds a command to properly update the CF's operand(s) sizes. This policy will
+ * make sure the new Operand is created "under the mouse cursor", shrinking
+ * the existing Operand under the mouse cursor if necessary.
+ * </p>
+ *
* @see org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultCreationEditPolicy#getSetBoundsCommand(org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest, org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor)
*
* @param request
@@ -42,21 +111,96 @@ public class CombinedCreationEditPolicy extends DefaultCreationEditPolicy {
@Override
protected ICommand getSetBoundsCommand(CreateViewRequest request, ViewDescriptor descriptor) {
TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
- Node node=(Node)((GraphicalEditPart)getHost()).getNotationView();
- int labelHeight=27;
- Node combinedFragmentNode = (Node)((GraphicalEditPart)(getHost().getParent())).getNotationView();
- int y=0;
- int height=((Bounds)combinedFragmentNode.getLayoutConstraint()).getHeight()-labelHeight;
- for(int i=0; i<getHost().getChildren().size();i++) {
-
- Node currentNode=(Node)(((GraphicalEditPart)getHost().getChildren().get(i))).getNotationView();
- int previousheight=((Bounds)currentNode.getLayoutConstraint()).getHeight();
- y=y+previousheight;
- height=height-previousheight;
+ GraphicalEditPart compartmentEditPart = (GraphicalEditPart) getHost();
+
+ IFigure compartmentFigure = compartmentEditPart.getFigure();
+ Point locationToViewer = request.getLocation().getCopy(); // Relative to visible viewer area (Changes when scroll/zoom is applied).
+
+ Point locationToCompartment = locationToViewer.getCopy(); // Transform to diagram coordinates (Relative to the compartment).
+ compartmentFigure.translateToRelative(locationToCompartment);
+ compartmentFigure.translateFromParent(locationToCompartment);
+
+ final GraphicalEditPart targetOperandPart = findOperandAt(locationToCompartment, compartmentEditPart);
+
+ // TODO Support feedback (From mouse location to the top of the next operand, or to the bottom of the CF)
+
+ if (targetOperandPart != null) {
+
+ final IFigure targetOperandFigure = targetOperandPart.getFigure();
+ Rectangle targetOperandBounds = targetOperandFigure.getBounds();
+
+ Point locationToOperand = locationToViewer.getCopy();
+ targetOperandFigure.translateToRelative(locationToOperand);
+ targetOperandFigure.translateFromParent(locationToOperand);
+
+ // We get the size from the mouse cursor location to the bottom of the existing operand
+ int height = targetOperandBounds.getBottom().y() - locationToOperand.y();
+
+ Dimension size = new Dimension(-1, height);
+ ICommand setBoundsCommand = new SetResizeCommand(editingDomain, "Set dimension", descriptor, size);
+
+ // Also reduce the size of the existing operand, to avoid shifting the entire operands stack
+ View view = targetOperandPart.getNotationView();
+
+ int siblingHeight = targetOperandPart.getFigure().getBounds().height();
+
+ Dimension siblingDimension = new Dimension(-1, siblingHeight - height);
+ ICommand reduceSiblingSizeCommand = new SetResizeCommand(editingDomain, "Set dimension", new NotationAndTypeAdapter(view.getElement(), view), siblingDimension);
+ return setBoundsCommand.compose(reduceSiblingSizeCommand);
}
- org.eclipse.draw2d.geometry.Rectangle rect= new org.eclipse.draw2d.geometry.Rectangle(0,y ,-1,height);
- ICommand setBoundsCommand = new SetResizeAndLocationCommand(editingDomain, "Set dimension", descriptor, rect);
+
+ // Shouldn't happen in a well-formed diagram, since a CF should always have at least one operand.
+ // If this happens, simply take all available height
+ Rectangle clientArea = compartmentFigure.getClientArea();
+ int height = clientArea.height();
+ Dimension size = new Dimension(-1, height);
+ ICommand setBoundsCommand = new SetResizeCommand(editingDomain, "Set dimension", descriptor, size);
return setBoundsCommand;
}
+ private static InteractionOperandEditPart findOperandAt(Point locationToCompartment, GraphicalEditPart compartmentPart) {
+ final EditPart targetPart = findEditPartAt(locationToCompartment, compartmentPart);
+
+ final InteractionOperandEditPart operandEditPart;
+ if (targetPart instanceof InteractionOperandEditPart) {
+ operandEditPart = (InteractionOperandEditPart) targetPart;
+ } else if (targetPart != null) {
+ operandEditPart = findParentOperandPart(targetPart);
+ } else {
+ operandEditPart = null;
+ }
+ return operandEditPart;
+ }
+
+ private static EditPart findEditPartAt(Point locationToCompartment, GraphicalEditPart compartmentPart) {
+ IFigure targetOperandFigure = compartmentPart.getFigure().findFigureAt(locationToCompartment);
+ final EditPart targetPart;
+ if (targetOperandFigure == null) {
+ targetPart = null;
+ } else {
+ EditPart partForFigure = null;
+ IFigure currentFigure = targetOperandFigure;
+ while (currentFigure != null) {
+ partForFigure = (EditPart) compartmentPart.getViewer().getVisualPartMap().get(currentFigure);
+ if (partForFigure != null) {
+ break;
+ }
+ currentFigure = currentFigure.getParent();
+ }
+ targetPart = partForFigure;
+ }
+ return targetPart;
+ }
+
+ private static InteractionOperandEditPart findParentOperandPart(final EditPart part) {
+ EditPart currentPart = part.getParent();
+ while (currentPart != null) {
+ if (currentPart instanceof InteractionOperandEditPart) {
+ return (InteractionOperandEditPart) currentPart;
+ }
+ currentPart = currentPart.getParent();
+ }
+ return null;
+ }
+
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandLayoutEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandLayoutEditPolicy.java
index 7c950800336..8657f8cf122 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandLayoutEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandLayoutEditPolicy.java
@@ -14,6 +14,7 @@
package org.eclipse.papyrus.uml.diagram.sequence.edit.policies;
import java.util.List;
+import java.util.Map;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.EditPart;
@@ -29,14 +30,15 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.XYLayoutEditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewAndElementRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateUnspecifiedTypeRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
+import org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionOperandGuardEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
/**
* The custom LayoutEditPolicy for InteractionOperandEditPart.
-* this class has been customized to prevent the strange feedback of lifeline during the move
-*
+ * this class has been customized to prevent the strange feedback of lifeline during the move
+ *
*/
public class InteractionOperandLayoutEditPolicy extends XYLayoutEditPolicy {
@@ -65,6 +67,9 @@ public class InteractionOperandLayoutEditPolicy extends XYLayoutEditPolicy {
EditPart interactionCompartment = combinedFragment.getParent();
if (REQ_CREATE.equals(request.getType()) && request instanceof CreateUnspecifiedTypeRequest) {
if (UMLElementTypes.InteractionOperand_Shape.equals(((CreateUnspecifiedTypeRequest) request).getElementTypes().get(0))) {
+ Map<? super String, Object> extendedData = request.getExtendedData();
+ int hostIndex = combinedFragmentCompartment.getChildren().indexOf(getHost());
+ extendedData.put(RequestParameterConstants.INSERT_AT, hostIndex + 1); // Insert after the target
return combinedFragmentCompartment.getCommand(request);
} else if (UMLElementTypes.CombinedFragment_Shape.equals(((CreateUnspecifiedTypeRequest) request).getElementTypes().get(0))) {
// Fixed bug about creating on InteractionOperand. (executed Twice).
@@ -133,6 +138,7 @@ public class InteractionOperandLayoutEditPolicy extends XYLayoutEditPolicy {
}
return super.getOrphanChildrenCommand(request);
}
+
/**
* @see org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#createAddCommand(org.eclipse.gef.requests.ChangeBoundsRequest, org.eclipse.gef.EditPart, java.lang.Object)
*
@@ -143,11 +149,12 @@ public class InteractionOperandLayoutEditPolicy extends XYLayoutEditPolicy {
*/
@Override
protected Command createAddCommand(ChangeBoundsRequest request, EditPart child, Object constraint) {
- if( child instanceof LifelineEditPart) {
+ if (child instanceof LifelineEditPart) {
return UnexecutableCommand.INSTANCE;
}
return super.createAddCommand(request, child, constraint);
}
+
/**
* @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#showTargetFeedback(org.eclipse.gef.Request)
*
@@ -155,11 +162,11 @@ public class InteractionOperandLayoutEditPolicy extends XYLayoutEditPolicy {
*/
@Override
public void showTargetFeedback(Request request) {
- if(request instanceof ChangeBoundsRequest){
- ChangeBoundsRequest changeBoundsRequest= (ChangeBoundsRequest)request;
+ if (request instanceof ChangeBoundsRequest) {
+ ChangeBoundsRequest changeBoundsRequest = (ChangeBoundsRequest) request;
- if( changeBoundsRequest.getEditParts().get(0) instanceof LifelineEditPart) {
- changeBoundsRequest.setMoveDelta(new Point(changeBoundsRequest.getMoveDelta().x,0));
+ if (changeBoundsRequest.getEditParts().get(0) instanceof LifelineEditPart) {
+ changeBoundsRequest.setMoveDelta(new Point(changeBoundsRequest.getMoveDelta().x, 0));
}
}
super.showTargetFeedback(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 dcac8f89f5b..fb6d52f2dc0 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
@@ -28,18 +28,10 @@ import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest.ViewAndElementDescriptor;
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
-import org.eclipse.gmf.runtime.emf.type.core.IElementType;
-import org.eclipse.gmf.runtime.notation.Bounds;
-import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
import org.eclipse.papyrus.uml.diagram.sequence.command.SetResizeCommand;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CInteractionOperandEditPart;
-import org.eclipse.papyrus.uml.service.types.element.UMLDIElementTypes;
-import org.eclipse.papyrus.uml.service.types.utils.ElementUtil;
/**
@@ -74,21 +66,6 @@ public class ResizeOperandEditPolicy extends GraphicalEditPolicy {
*/
@Override
public Command getCommand(Request request) {
- if (request instanceof CreateViewAndElementRequest) {
- CreateViewAndElementRequest req = (CreateViewAndElementRequest) request;
- ViewAndElementDescriptor descriptor = (req).getViewAndElementDescriptor();
- IElementType elementType = descriptor.getElementAdapter().getAdapter(IElementType.class);
- if (ElementUtil.isTypeOf(elementType, UMLDIElementTypes.INTERACTION_OPERAND_SHAPE)) {
- Node combinedFragmentNode = (Node) ((GraphicalEditPart) (getHost().getParent())).getNotationView();
- // we add a new Operand so we add the default height
- int height = ((Bounds) combinedFragmentNode.getLayoutConstraint()).getHeight();
- if (getHost().getChildren().size() > 0) {
- int newHeight = height + CInteractionOperandEditPart.DEFAULT_HEIGHT;
-
- return new ICommandProxy(new SetResizeCommand(getEditingDomain(), "set dimension", new EObjectAdapter(combinedFragmentNode), new Dimension(BoundForEditPart.getWidthFromView(combinedFragmentNode), newHeight)));
- }
- }
- }
if (RequestConstants.REQ_RESIZE_CHILDREN.equals(request.getType())) {
CompositeCommand compositeCommand = new CompositeCommand("Resize Operands");
ChangeBoundsRequest changeBoundsRequest = (ChangeBoundsRequest) request;
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/CombinedFragmentEditHelperAdvice.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/CombinedFragmentEditHelperAdvice.java
index e02ff6e2ca4..7dcaf1ad530 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/CombinedFragmentEditHelperAdvice.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/CombinedFragmentEditHelperAdvice.java
@@ -1,6 +1,6 @@
/*****************************************************************************
- * Copyright (c) 2017, 2018 CEA LIST, Christian W. Damus, and others.
- *
+ * Copyright (c) 2017, 2018 CEA LIST, Christian W. Damus, 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
@@ -9,9 +9,9 @@
* Contributors:
* Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
* Christian W. Damus - bug 533682
- *
+ * EclipseSource - Bug 533678
+ *
*****************************************************************************/
-
package org.eclipse.papyrus.uml.service.types.helper.advice;
import org.eclipse.core.commands.ExecutionException;
@@ -22,7 +22,10 @@ import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand;
import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
+import org.eclipse.papyrus.infra.services.edit.commands.InsertAtCommand;
+import org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants;
import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
import org.eclipse.uml2.uml.CombinedFragment;
import org.eclipse.uml2.uml.InteractionOperand;
@@ -30,7 +33,7 @@ import org.eclipse.uml2.uml.UMLFactory;
/**
* This allows to manage the combined fragment creation with an interaction operand at the same moment.
- *
+ *
* @since 3.0
*/
public class CombinedFragmentEditHelperAdvice extends AbstractEditHelperAdvice {
@@ -55,6 +58,22 @@ public class CombinedFragmentEditHelperAdvice extends AbstractEditHelperAdvice {
}
/**
+ * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getAfterCreateCommand(org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest)
+ *
+ * @param request
+ * @return
+ */
+ @Override
+ protected ICommand getAfterCreateCommand(CreateElementRequest request) {
+ ICommand afterCreateCommand = super.getAfterCreateCommand(request);
+ if (request.getParameter(RequestParameterConstants.INSERT_AT) instanceof Integer) {
+ InsertAtCommand insertAtCommand = new InsertAtCommand(request);
+ return afterCreateCommand == null ? insertAtCommand : afterCreateCommand.compose(insertAtCommand);
+ }
+ return afterCreateCommand;
+ }
+
+ /**
* Create an interaction operand.
*/
public static InteractionOperand createInteractionOperand() {

Back to the top