diff options
author | Vincent Lorenzo | 2016-05-11 11:24:47 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2016-05-26 08:41:24 +0000 |
commit | c35076dc3e1ee6ab19c2daa6f71d990d1b798450 (patch) | |
tree | 28704c2bb96bb475150e30c48d3061f6fa5a9ddd /plugins/uml | |
parent | e6450f0d3364d2ee0e84a35e5216d67d9af731bf (diff) | |
download | org.eclipse.papyrus-c35076dc3e1ee6ab19c2daa6f71d990d1b798450.tar.gz org.eclipse.papyrus-c35076dc3e1ee6ab19c2daa6f71d990d1b798450.tar.xz org.eclipse.papyrus-c35076dc3e1ee6ab19c2daa6f71d990d1b798450.zip |
bug 492522: [All Diagrams] Delete from model on comment links does not
work (does a delete from diagram)
bug 439317: [All Diagrams] Delete from model on contraint links and constraints specification links does not work (do a delete from diagram)
new deprecated class : org.eclipse.papyrus.uml.diagram.common.editpolicies.ContextLinkSemanticEditPolicy
I remove it from the installed editpolicy for Class, Profile and StateMachine diagrams
- add tests about comment link deletion for ClassDiagram, CompositeDiagram and ComponentDiagram
Change-Id: I0be833fe18d751bf4873b6e09962b8878b3d010c
Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
Diffstat (limited to 'plugins/uml')
13 files changed, 415 insertions, 19 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/model/classdiagram.gmfgen b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/model/classdiagram.gmfgen index 17e10d07206..f509202e346 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/model/classdiagram.gmfgen +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/model/classdiagram.gmfgen @@ -7311,10 +7311,6 @@ xsi:type="gmfgen:CustomBehaviour" key="org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLinkLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY" editPolicyQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomAppliedStereotypeContextLinkLabelDisplayEditPolicy"/> - <behaviour - xsi:type="gmfgen:CustomBehaviour" - key="org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.SEMANTIC_ROLE" - editPolicyQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.editpolicies.ContextLinkSemanticEditPolicy"/> <modelFacet xsi:type="gmfgen:FeatureLinkModelFacet"> <metaFeature diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/src-gen/org/eclipse/papyrus/uml/diagram/clazz/edit/parts/ContextLinkEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/src-gen/org/eclipse/papyrus/uml/diagram/clazz/edit/parts/ContextLinkEditPart.java index 9dbf29abc62..1dc79e57431 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/src-gen/org/eclipse/papyrus/uml/diagram/clazz/edit/parts/ContextLinkEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/src-gen/org/eclipse/papyrus/uml/diagram/clazz/edit/parts/ContextLinkEditPart.java @@ -22,7 +22,6 @@ import org.eclipse.papyrus.uml.diagram.clazz.custom.figure.CustomContextLinkFigu import org.eclipse.papyrus.uml.diagram.clazz.custom.policies.CustomGraphicalNodeEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editparts.UMLConnectionNodeEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLinkLabelDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.ContextLinkSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomAppliedStereotypeContextLinkLabelDisplayEditPolicy; /** @@ -52,7 +51,6 @@ public class ContextLinkEditPart extends UMLConnectionNodeEditPart implements IT installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomGraphicalNodeEditPolicy()); installEditPolicy(AppliedStereotypeLinkLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new CustomAppliedStereotypeContextLinkLabelDisplayEditPolicy()); - installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new ContextLinkSemanticEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ContextLinkSemanticEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ContextLinkSemanticEditPolicy.java index 126841516d4..3efbaecff07 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ContextLinkSemanticEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ContextLinkSemanticEditPolicy.java @@ -8,7 +8,7 @@ *
* Contributors:
* CEA LIST - Initial API and implementation
- *
+ * Vincent Lorenzo - bug 493317 (deprecated)
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.editpolicies;
@@ -31,6 +31,8 @@ import org.eclipse.uml2.uml.Constraint; /**
* Custom context link semantic edit policy that provides removing a context from constrained element
* during delete/hide context link command
+ *
+ * @deprecated since 2.0, the work is now done by an advice helper in the oep.uml.service.types
*/
public class ContextLinkSemanticEditPolicy extends DefaultSemanticEditPolicy {
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/model/profilediagram.gmfgen b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/model/profilediagram.gmfgen index 2b4f8dfd0d5..50bf0b50794 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/model/profilediagram.gmfgen +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/model/profilediagram.gmfgen @@ -2880,10 +2880,6 @@ xsi:type="gmfgen:CustomBehaviour" key="org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLinkLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY" editPolicyQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomAppliedStereotypeContextLinkLabelDisplayEditPolicy"/> - <behaviour - xsi:type="gmfgen:CustomBehaviour" - key="org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.SEMANTIC_ROLE" - editPolicyQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.editpolicies.ContextLinkSemanticEditPolicy"/> <modelFacet xsi:type="gmfgen:FeatureLinkModelFacet"> <metaFeature diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/src-gen/org/eclipse/papyrus/uml/diagram/profile/edit/parts/ContextLinkEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/src-gen/org/eclipse/papyrus/uml/diagram/profile/edit/parts/ContextLinkEditPart.java index 45ce0dc9906..b0ab14dd6ae 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/src-gen/org/eclipse/papyrus/uml/diagram/profile/edit/parts/ContextLinkEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/src-gen/org/eclipse/papyrus/uml/diagram/profile/edit/parts/ContextLinkEditPart.java @@ -20,7 +20,6 @@ import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editparts.UMLConnectionNodeEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLinkLabelDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.ContextLinkSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomAppliedStereotypeContextLinkLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.profile.custom.figure.CustomContextLinkFigure; import org.eclipse.papyrus.uml.diagram.profile.custom.policies.CustomGraphicalNodeEditPolicy; @@ -52,7 +51,6 @@ public class ContextLinkEditPart extends UMLConnectionNodeEditPart implements IT installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomGraphicalNodeEditPolicy()); installEditPolicy(AppliedStereotypeLinkLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new CustomAppliedStereotypeContextLinkLabelDisplayEditPolicy()); - installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new ContextLinkSemanticEditPolicy()); } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/SequenceViewDependentsAdvice.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/SequenceViewDependentsAdvice.java index 47bf88300c4..7f90659e9d9 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/SequenceViewDependentsAdvice.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/SequenceViewDependentsAdvice.java @@ -42,6 +42,8 @@ import org.eclipse.uml2.uml.UMLPackage; /**
* @author Jin Liu (jin.liu@soyatec.com)
+ *
+ * TODO : refactore me, see Bugs 493512, and 492522
*/
public class SequenceViewDependentsAdvice extends AbstractEditHelperAdvice {
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/model/stateMachineDiagram.gmfgen b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/model/stateMachineDiagram.gmfgen index c90094e0e3f..0d00d100d4a 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/model/stateMachineDiagram.gmfgen +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/model/stateMachineDiagram.gmfgen @@ -2300,10 +2300,6 @@ xsi:type="gmfgen:CustomBehaviour" key="org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLinkLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY" editPolicyQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomAppliedStereotypeContextLinkLabelDisplayEditPolicy"/> - <behaviour - xsi:type="gmfgen:CustomBehaviour" - key="org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.SEMANTIC_ROLE" - editPolicyQualifiedClassName="org.eclipse.papyrus.uml.diagram.common.editpolicies.ContextLinkSemanticEditPolicy"/> <modelFacet xsi:type="gmfgen:FeatureLinkModelFacet"> <metaFeature diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/src-gen/org/eclipse/papyrus/uml/diagram/statemachine/edit/parts/ContextLinkEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/src-gen/org/eclipse/papyrus/uml/diagram/statemachine/edit/parts/ContextLinkEditPart.java index 39dee1baae5..096f1aa2850 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/src-gen/org/eclipse/papyrus/uml/diagram/statemachine/edit/parts/ContextLinkEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/src-gen/org/eclipse/papyrus/uml/diagram/statemachine/edit/parts/ContextLinkEditPart.java @@ -19,7 +19,6 @@ import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editparts.UMLConnectionNodeEditPart; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLinkLabelDisplayEditPolicy; -import org.eclipse.papyrus.uml.diagram.common.editpolicies.ContextLinkSemanticEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomAppliedStereotypeContextLinkLabelDisplayEditPolicy; import org.eclipse.papyrus.uml.diagram.statemachine.custom.figures.CustomContextLinkFigure; @@ -48,7 +47,6 @@ public class ContextLinkEditPart extends UMLConnectionNodeEditPart implements IT super.createDefaultEditPolicies(); installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new DefaultSemanticEditPolicy()); installEditPolicy(AppliedStereotypeLinkLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new CustomAppliedStereotypeContextLinkLabelDisplayEditPolicy()); - installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new ContextLinkSemanticEditPolicy()); } /** diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/README b/plugins/uml/org.eclipse.papyrus.uml.service.types/README new file mode 100644 index 00000000000..26708a33c93 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/README @@ -0,0 +1,7 @@ +bug 492522: [All Diagrams] Delete from model on comment links does not work (does a delete from diagram) +https://bugs.eclipse.org/bugs/show_bug.cgi?id=492522 + +1. Delete from model for a link representing a feature (like the comment link mapped on Comment#annotatedElement, the contraint link mapped on Contraints#contrainedElements and others) +must remove the referenced element of the feature +2. To do that we need to map the type of the link (visual id) to a feature and we need to use the same id for all diagrams +3. if these conditions are respected, the uml service type is able to remove all representations of a given link doing Delete From Model for a link
\ No newline at end of file diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/model/uml.elementtypesconfigurations b/plugins/uml/org.eclipse.papyrus.uml.service.types/model/uml.elementtypesconfigurations index 3f6e796d9aa..0dc73296de0 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.service.types/model/uml.elementtypesconfigurations +++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/model/uml.elementtypesconfigurations @@ -1071,6 +1071,8 @@ <specializedTypesID>org.eclipse.gmf.runtime.emf.type.core.null</specializedTypesID> <editHelperAdviceConfiguration xsi:type="elementtypesconfigurations:EditHelperAdviceConfiguration" xmi:id="_JdUX4MHTEeSpuJnfbRdiWQ" editHelperAdviceClassName="org.eclipse.papyrus.uml.service.types.helper.advice.ElementOwnedElementEditHelperAdvice"/> </elementTypeConfigurations> + <adviceBindingsConfigurations xsi:type="elementtypesconfigurations:AdviceBindingConfiguration" xmi:id="_wayS0BgzEeaW-4uSpAcmpQ" identifier="org.eclipse.papyrus.uml.advice.ConstraintDestroyConstrainedElements" target="_SccC-1YCEeS0WsAAtVmToA" inheritance="all" editHelperAdviceClassName="org.eclipse.papyrus.uml.service.types.helper.advice.ConstraintDestroyConstrainedElementsEditHelperAdvice"/> + <adviceBindingsConfigurations xsi:type="elementtypesconfigurations:AdviceBindingConfiguration" xmi:id="_pSKXgBa4EeaJFJ1Mo_kk8w" identifier="org.eclipse.papyrus.uml.advice.CommentDestroyAnnotatedElements" target="_Scbb2FYCEeS0WsAAtVmToA" inheritance="all" editHelperAdviceClassName="org.eclipse.papyrus.uml.service.types.helper.advice.CommentDestroyAnnotatedElementsEditHelperAdvice"/> <adviceBindingsConfigurations xsi:type="elementtypesconfigurations:AdviceBindingConfiguration" xmi:id="_mqX8YMHdEeSpuJnfbRdiWQ" identifier="org.eclipse.papyrus.uml.advice.Containment" target="_ScgUUFYCEeS0WsAAtVmToA" inheritance="all" editHelperAdviceClassName="org.eclipse.papyrus.uml.service.types.helper.advice.ElementOwnedElementReorientEditHelperAdvice"/> <adviceBindingsConfigurations xsi:type="elementtypesconfigurations:AdviceBindingConfiguration" xmi:id="_6AWx0MJaEeSl6M4_Zhyt7Q" identifier="org.eclipse.papyrus.uml.advice.ConstraintConstrainedElementsReorient" target="_SccC-1YCEeS0WsAAtVmToA" inheritance="all" editHelperAdviceClassName="org.eclipse.papyrus.uml.service.types.helper.advice.ConstraintConstrainedElementsReorientEditHelperAdvice"/> <adviceBindingsConfigurations xsi:type="elementtypesconfigurations:AdviceBindingConfiguration" xmi:id="_Biw5sMdFEeS1POoqrCEMrQ" identifier="org.eclipse.papyrus.uml.advice.CommentAnnotatedElementsReorient" target="_Scbb2FYCEeS0WsAAtVmToA" inheritance="all" editHelperAdviceClassName="org.eclipse.papyrus.uml.service.types.helper.advice.CommentAnnotatedElementsReorientEditHelperAdvice"/> diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/AbstractReferenceDeleteRelationshipEditHelperAdvice.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/AbstractReferenceDeleteRelationshipEditHelperAdvice.java new file mode 100644 index 00000000000..9ebd0d631f5 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/AbstractReferenceDeleteRelationshipEditHelperAdvice.java @@ -0,0 +1,260 @@ +/***************************************************************************** + * Copyright (c) 2016 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: + * CEA LIST - Initial API and implementation + * Vincent Lorenzo - bug 492522 + *****************************************************************************/ + +package org.eclipse.papyrus.uml.service.types.helper.advice; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature.Setting; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry; +import org.eclipse.gmf.runtime.emf.type.core.IClientContext; +import org.eclipse.gmf.runtime.emf.type.core.IElementType; +import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType; +import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice; +import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; +import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest; +import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest; +import org.eclipse.gmf.runtime.notation.Connector; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.services.edit.internal.context.TypeContext; +import org.eclipse.papyrus.infra.types.core.utils.ElementTypeRegistryUtils; +import org.eclipse.papyrus.uml.service.types.utils.RequestParameterConstants; +import org.eclipse.uml2.common.util.CacheAdapter; + +/** + * Abstract class used to remove referenced element when a link with no direct semantic element linked to it is destroyed + * + */ +public abstract class AbstractReferenceDeleteRelationshipEditHelperAdvice extends AbstractEditHelperAdvice { + + /** + * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#configureRequest(org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest) + * + * @param request + */ + @Override + public void configureRequest(IEditCommandRequest request) { + super.configureRequest(request); + if (request instanceof DestroyReferenceRequest && ((DestroyReferenceRequest) request).getContainingFeature() == null) { + String visualId = (String) request.getParameter(RequestParameterConstants.VIEW_VISUAL_ID); + ((DestroyReferenceRequest) request).setContainingFeature(getFeature(visualId)); + } + } + + /** + * + * @param visualId + * the visual id + * @return + * the EReference represented by the view with this visual id + */ + protected EReference getFeature(String visualId) { + + try { + IClientContext context = TypeContext.getContext(); + List<IElementType> elementTypes = ElementTypeRegistryUtils.getElementTypesBySemanticHint(visualId, context.getId()); + + for (IElementType iElementType : elementTypes) { + Map<String, EReference> featureElementTypeToEReferenceMap = getFeatureElementTypeToEReferenceMap(); + for (String featureElementType : featureElementTypeToEReferenceMap.keySet()) { + List<ISpecializationType> subs = Arrays.asList(ElementTypeRegistry.getInstance().getSpecializationsOf(featureElementType)); + if (subs.contains(iElementType)) { + return featureElementTypeToEReferenceMap.get(featureElementType); + } + } + } + } catch (ServiceException e) { + org.eclipse.papyrus.uml.service.types.Activator.log.error(e); + } + + return null; + } + + /** + * + * @return + * the map linking an element type to a EReference + */ + abstract protected Map<String, EReference> getFeatureElementTypeToEReferenceMap(); + + /** + * + * @param eobject + * an eobject + * @return + * all the views for the given element, the returned value is never <code>null</code> + */ + private List<View> getAllViewsFor(final EObject eobject) { + final List<View> elementViews = new ArrayList<View>(); + if (null != eobject) { + + final Collection<Setting> settings = CacheAdapter.getInstance().getNonNavigableInverseReferences(eobject); + // get all views representing the feature owner + for (Setting ref : settings) { + if (NotationPackage.eINSTANCE.getView_Element().equals(ref.getEStructuralFeature())) { + View view = (View) ref.getEObject(); + if (view != null) { + elementViews.add(view); + } + } + } + } + return elementViews; + } + + /** + * + * @param request + * the destroy reference request + * @return + * the list of connector to destroy for the request + */ + private List<Connector> findConnectorsToDestroy(final DestroyReferenceRequest request) { + List<Connector> connectorsToDestroy = new ArrayList<Connector>(); + EObject featureOwner = request.getContainer(); + if (null != featureOwner) { + final List<View> featureOwnerViews = getAllViewsFor(featureOwner); + if (checkSourceEdgeToFindConnectorToDestroy()) { + connectorsToDestroy.addAll(findSourceConnectorsToDestroy(request, featureOwnerViews)); + } + if (checkTargetEdgeToFindConnectorToDestroy()) { + connectorsToDestroy.addAll(findTargetConnectorsToDestroy(request, featureOwnerViews)); + } + } + return connectorsToDestroy; + } + + /** + * + * @param request + * the destroy reference request + * @param featureOwnerViews + * the views representing the feature owner + * @return + * the list of connectors linked as source to the views of the feature owner to destroy + */ + private List<Connector> findSourceConnectorsToDestroy(final DestroyReferenceRequest request, final List<View> featureOwnerViews) { + final List<Connector> viewsToDestroy = new ArrayList<Connector>(); + final EObject removedReference = request.getReferencedObject(); + final String visualId = (String) request.getParameter(RequestParameterConstants.VIEW_VISUAL_ID); + if (visualId != null && !visualId.isEmpty() && removedReference != null) + for (View currentView : featureOwnerViews) { + List<?> sourceEdges = currentView.getSourceEdges(); + for (Object current : sourceEdges) { + if (current instanceof Connector) { + Connector conn = (Connector) current; + if (visualId.equals(conn.getType())) { + View target = conn.getTarget(); + EObject model = target.getElement(); + if (removedReference == model) { + viewsToDestroy.add(conn); + } + } + } + } + } + return viewsToDestroy; + } + + /** + * + * @param request + * the destroy reference request + * @param featureOwnerViews + * the views representing the feature owner + * @return + * the list of connectors linked as target to the views of the feature owner to destroy + */ + private List<Connector> findTargetConnectorsToDestroy(final DestroyReferenceRequest request, final List<View> featureOwnerViews) { + final List<Connector> viewsToDestroy = new ArrayList<Connector>(); + final EObject removedReference = request.getReferencedObject(); + final String visualId = (String) request.getParameter(RequestParameterConstants.VIEW_VISUAL_ID); + if (visualId != null && !visualId.isEmpty() && removedReference != null) + for (View currentView : featureOwnerViews) { + final List<?> targetEdgets = currentView.getTargetEdges(); + for (Object current : targetEdgets) { + if (current instanceof Connector) { + Connector conn = (Connector) current; + if (visualId.equals(conn.getType())) { + final View target = conn.getTarget(); + EObject model = target.getElement(); + if (removedReference == model) { + viewsToDestroy.add(conn); + } + } + } + } + } + return viewsToDestroy; + } + + /** + * + * @return + * <code>true</code> if we cross the connector whose the source is connected to the element + */ + abstract protected boolean checkSourceEdgeToFindConnectorToDestroy(); + + /** + * + * @return + * <code>true</code> if we cross the connector whose the target is connected to the element + */ + abstract protected boolean checkTargetEdgeToFindConnectorToDestroy(); + + /** + * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getBeforeDestroyReferenceCommand(org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest) + * + * @param request + * @return + */ + @Override + protected ICommand getBeforeDestroyReferenceCommand(final DestroyReferenceRequest request) { + final CompositeCommand command = new CompositeCommand("Clear Connectors"); // $NON-NLS-0$ + + // 1. get all connectors to destroy + final Collection<Connector> connectorsToDestroy = findConnectorsToDestroy(request); + + if (!connectorsToDestroy.isEmpty()) { + final TransactionalEditingDomain domain = request.getEditingDomain(); + for (View edge : connectorsToDestroy) { + final DestroyElementRequest destroy = new DestroyElementRequest(domain, edge, false); + final Object eHelperContext = destroy.getEditHelperContext(); + final IElementType context = ElementTypeRegistry.getInstance().getElementType(eHelperContext); + if (context != null) { + final ICommand result = context.getEditCommand(destroy); + if (result != null) { + command.add(result); + } + } + } + } + + if (command.isEmpty() || !command.canExecute()) { + return null; + } + return command; + } + +} diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/CommentDestroyAnnotatedElementsEditHelperAdvice.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/CommentDestroyAnnotatedElementsEditHelperAdvice.java new file mode 100644 index 00000000000..7032c7e1309 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/CommentDestroyAnnotatedElementsEditHelperAdvice.java @@ -0,0 +1,70 @@ +/***************************************************************************** + * Copyright (c) 2016 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: + * CEA LIST - Initial API and implementation + * Vincent Lorenzo - bug 492522 + *****************************************************************************/ + +package org.eclipse.papyrus.uml.service.types.helper.advice; + +import java.util.Collections; +import java.util.Map; + +import org.eclipse.emf.ecore.EReference; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; +import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes; +import org.eclipse.uml2.uml.UMLPackage; + +/** + * This helper provides the command to remove an annotated element from a comment + * + */ +public class CommentDestroyAnnotatedElementsEditHelperAdvice extends AbstractReferenceDeleteRelationshipEditHelperAdvice { + + @Override + protected ICommand getBeforeSetCommand(SetRequest request) { + // TODO, here we must manage the case where a set request is sent instead of a destroy reference request, like done for Comment#annotatedElement by the property view. + // Currently, this is the class org.eclipse.papyrus.uml.diagram.sequence.SequenceViewDependentsAdvice which intercept the set request + + // the test for set request is already write, but tagged as invalid test in org.eclipse.papyrus.uml.service.types.tests.deletion.DeleteCommentLinkTest + return super.getBeforeSetCommand(request); + } + + /** + * @see org.eclipse.papyrus.uml.service.types.helper.advice.AbstractReferenceDeleteRelationshipEditHelperAdvice#checkSourceEdgeToFindConnectorToDestroy() + * + * @return + */ + @Override + protected boolean checkSourceEdgeToFindConnectorToDestroy() { + return true; + } + + + /** + * @see org.eclipse.papyrus.uml.service.types.helper.advice.AbstractReferenceDeleteRelationshipEditHelperAdvice#checkTargetEdgeToFindConnectorToDestroy() + * + * @return + */ + @Override + protected boolean checkTargetEdgeToFindConnectorToDestroy() { + return false; + } + + /** + * @see org.eclipse.papyrus.uml.service.types.helper.advice.AbstractReferenceDeleteRelationshipEditHelperAdvice#getFeatureElementTypeToEReferenceMap() + * + * @return + */ + @Override + protected Map<String, EReference> getFeatureElementTypeToEReferenceMap() { + return Collections.singletonMap(UMLElementTypes.COMMENT_ANNOTATEDELEMENTS.getId(), UMLPackage.eINSTANCE.getComment_AnnotatedElement()); + } +} diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/ConstraintDestroyConstrainedElementsEditHelperAdvice.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/ConstraintDestroyConstrainedElementsEditHelperAdvice.java new file mode 100644 index 00000000000..4f0f807bb77 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/ConstraintDestroyConstrainedElementsEditHelperAdvice.java @@ -0,0 +1,71 @@ +/*****************************************************************************
+ * Copyright (c) 2016 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:
+ * CEA LIST - Initial API and implementation
+ * Vincent Lorenzo - bug 493317
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.service.types.helper.advice;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
+import org.eclipse.uml2.uml.UMLPackage;
+
+/**
+ *
+ * This class manages the destruction of the link representing the ConstrainedElement when one of them is removed from the feature
+ *
+ */
+public class ConstraintDestroyConstrainedElementsEditHelperAdvice extends AbstractReferenceDeleteRelationshipEditHelperAdvice {
+
+ @Override
+ protected ICommand getBeforeSetCommand(SetRequest request) {
+ // TODO, here we must manage the case where a set request is sent instead of a destroy reference request, like done for Comment#annotatedElement by the property view.
+ // Currently, this is the class org.eclipse.papyrus.uml.diagram.sequence.SequenceViewDependentsAdvice which intercept the set request
+ return super.getBeforeSetCommand(request);
+ }
+
+
+ /**
+ * @see org.eclipse.papyrus.uml.service.types.helper.advice.AbstractReferenceDeleteRelationshipEditHelperAdvice#getFeatureElementTypeToEReferenceMap()
+ *
+ * @return
+ */
+ @Override
+ protected Map<String, EReference> getFeatureElementTypeToEReferenceMap() {
+ return Collections.singletonMap(UMLElementTypes.CONSTRAINT_CONSTRAINEDELEMENTS.getId(), UMLPackage.eINSTANCE.getConstraint_ConstrainedElement());
+ }
+
+
+ /**
+ * @see org.eclipse.papyrus.uml.service.types.helper.advice.AbstractReferenceDeleteRelationshipEditHelperAdvice#checkSourceEdgeToFindConnectorToDestroy()
+ *
+ * @return
+ */
+ @Override
+ protected boolean checkSourceEdgeToFindConnectorToDestroy() {
+ return true;
+ }
+
+
+ /**
+ * @see org.eclipse.papyrus.uml.service.types.helper.advice.AbstractReferenceDeleteRelationshipEditHelperAdvice#checkTargetEdgeToFindConnectorToDestroy()
+ *
+ * @return
+ */
+ @Override
+ protected boolean checkTargetEdgeToFindConnectorToDestroy() {
+ return false;
+ }
+}
\ No newline at end of file |