diff options
author | Remi Schnekenburger | 2018-08-10 14:54:46 +0000 |
---|---|---|
committer | Remi Schnekenburger | 2018-08-10 14:54:46 +0000 |
commit | b463de7c05ce34a1a41dd5200d990b0eef84dd94 (patch) | |
tree | f6463a2cbf75d316be2f0c7c723e1075b4b01ea3 | |
parent | 4455415161ccfed3737407e65a5c81aafcbd3c0e (diff) | |
download | org.eclipse.papyrus-bugs/536631-SequenceDurations.tar.gz org.eclipse.papyrus-bugs/536631-SequenceDurations.tar.xz org.eclipse.papyrus-bugs/536631-SequenceDurations.zip |
Bug 537849: [Sequence Diagram] Ensure TimeObservation representation isbugs/536631-SequenceDurations
coherent with Graphical representation
- Ensure coherence at creation.
- not possible currently to check for evolution of constrained element,
as the property view deletes the entire list and then adds the new
selected element
Change-Id: I66889e0fae69c7923e0c3ae8d24249033985c8d0
Signed-off-by: Remi Schnekenburger <rschnekenburger@eclipsesource.com>
3 files changed, 70 insertions, 8 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/CustomExecutionSpecificationSemanticEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/CustomExecutionSpecificationSemanticEditPolicy.java new file mode 100644 index 00000000000..7cdcca025c1 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/CustomExecutionSpecificationSemanticEditPolicy.java @@ -0,0 +1,57 @@ +/***************************************************************************** + * Copyright (c) 2018 CEA LIST 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 France - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.sequence.edit.policies; + +import java.util.Arrays; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.commands.Command; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultSemanticEditPolicy; +import org.eclipse.papyrus.uml.diagram.sequence.util.DurationLinkUtil; +import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes; +import org.eclipse.papyrus.uml.service.types.utils.ElementUtil; +import org.eclipse.papyrus.uml.service.types.utils.SequenceRequestConstant; +import org.eclipse.uml2.uml.ExecutionSpecification; +import org.eclipse.uml2.uml.TimeConstraint; + +/** + * Specific policy to set the contrained element for {@link TimeConstraint}. + */ +public class CustomExecutionSpecificationSemanticEditPolicy extends DefaultSemanticEditPolicy { + + @Override + protected Command getCreateCommand(CreateElementRequest req) { + if (ElementUtil.isTypeOf(req.getElementType(), UMLElementTypes.TIME_CONSTRAINT)) { + Object loc = req.getParameter("initialMouseLocationForCreation"); + // evaluate parameters + if (!Point.class.isInstance(loc) + || !IGraphicalEditPart.class.isInstance(getHost()) + || !ExecutionSpecification.class.isInstance(req.getContainer())) { + return super.getCreateCommand(req); + } + + boolean isStart = DurationLinkUtil.isStart(((IGraphicalEditPart) getHost()).getFigure(), Point.class.cast(loc)); + if (isStart) { + req.setParameter(SequenceRequestConstant.NEAREST_OCCURRENCE_SPECIFICATION, Arrays.asList(((ExecutionSpecification) req.getContainer()).getStart())); + } else { + req.setParameter(SequenceRequestConstant.NEAREST_OCCURRENCE_SPECIFICATION, Arrays.asList(((ExecutionSpecification) req.getContainer()).getFinish())); + } + + } + return super.getCreateCommand(req); + } + + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/providers/CustomExecutionSpecificationEditPolicyProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/providers/CustomExecutionSpecificationEditPolicyProvider.java index 314d4289d37..4de9612a18c 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/providers/CustomExecutionSpecificationEditPolicyProvider.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/providers/CustomExecutionSpecificationEditPolicyProvider.java @@ -21,6 +21,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation; import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider; import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.AbstractExecutionSpecificationEditPart; +import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.CustomExecutionSpecificationSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling.CustomExecutionSpecificationCreationEditPolicy; import org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling.CustomExecutionSpecificationXYLayoutEditPolicy; @@ -56,6 +57,7 @@ public class CustomExecutionSpecificationEditPolicyProvider extends AbstractProv public void createEditPolicies(final EditPart editPart) { editPart.installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CustomExecutionSpecificationCreationEditPolicy()); editPart.installEditPolicy(EditPolicy.LAYOUT_ROLE, new CustomExecutionSpecificationXYLayoutEditPolicy()); + editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomExecutionSpecificationSemanticEditPolicy()); } } diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/TimeConstraintHelperAdvice.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/TimeConstraintHelperAdvice.java index 62c10191316..0a82a1ac49a 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/TimeConstraintHelperAdvice.java +++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/TimeConstraintHelperAdvice.java @@ -1,14 +1,14 @@ /***************************************************************************** * Copyright (c) 2010 CEA LIST. * - * + * * 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: - * + * * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation * *****************************************************************************/ @@ -36,7 +36,8 @@ import org.eclipse.uml2.uml.OccurrenceSpecification; import org.eclipse.uml2.uml.TimeConstraint; /** - * This advice add automatically the constrained element (occurrence specification) for a time constraint + * This advice add automatically the constrained element (occurrence specification) for a time constraint + * * @since 3.0 */ public class TimeConstraintHelperAdvice extends AbstractEditHelperAdvice { @@ -48,14 +49,15 @@ public class TimeConstraintHelperAdvice extends AbstractEditHelperAdvice { protected ICommand getBeforeConfigureCommand(final ConfigureRequest request) { return new ConfigureElementCommand(request) { + @Override protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException { - NamedElement element = (NamedElement)request.getElementToConfigure(); + NamedElement element = (NamedElement) request.getElementToConfigure(); - TimeConstraint newElement = (TimeConstraint)request.getElementToConfigure(); + TimeConstraint newElement = (TimeConstraint) request.getElementToConfigure(); // assign the occurrence specification Object paramOccurrence = getRequest().getParameter(SequenceRequestConstant.NEAREST_OCCURRENCE_SPECIFICATION); - List<OccurrenceSpecification> occList =getAsOccSpecList(paramOccurrence); + List<OccurrenceSpecification> occList = getAsOccSpecList(paramOccurrence); if (!occList.isEmpty()) { for (OccurrenceSpecification occurrence : occList) { if (occurrence instanceof MessageOccurrenceSpecification) { @@ -74,7 +76,7 @@ public class TimeConstraintHelperAdvice extends AbstractEditHelperAdvice { } }; } - + /** * Get the object safely casted as a list of OccurrenceSpecification * @@ -85,7 +87,7 @@ public class TimeConstraintHelperAdvice extends AbstractEditHelperAdvice { if (occurrenceSpecificationList instanceof List<?>) { List<?> list = (List<?>) occurrenceSpecificationList; if (!list.isEmpty()) { - List<OccurrenceSpecification> newList = new ArrayList<OccurrenceSpecification>(list.size()); + List<OccurrenceSpecification> newList = new ArrayList<>(list.size()); for (Object elt : list) { if (elt instanceof OccurrenceSpecification) { newList.add((OccurrenceSpecification) elt); @@ -96,4 +98,5 @@ public class TimeConstraintHelperAdvice extends AbstractEditHelperAdvice { } return Collections.emptyList(); } + } |