Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Tessier2015-01-30 16:38:08 +0000
committerGerrit Code Review @ Eclipse.org2015-01-30 16:38:08 +0000
commit828cb7d2e0023cdb90e4a9b9eca594e76b14de0f (patch)
tree403a9e8d8387866d95dbb63261498d7fb92629ce
parent0fc0c66d0b091a7440fb230478c2353a3565f2be (diff)
parentf52ad5731bda0d11dc8061e92a1e005589e22a04 (diff)
downloadorg.eclipse.papyrus-828cb7d2e0023cdb90e4a9b9eca594e76b14de0f.tar.gz
org.eclipse.papyrus-828cb7d2e0023cdb90e4a9b9eca594e76b14de0f.tar.xz
org.eclipse.papyrus-828cb7d2e0023cdb90e4a9b9eca594e76b14de0f.zip
Merge changes I06cf3cfd,Ibe3678e3 into streams/1.0-maintenance
* changes: 430548: [Constraints] ConstraintLink not show on diagram after drag and drop from Model Explorer https://bugs.eclipse.org/bugs/show_bug.cgi?id=430548 - Add a test on diagram with handler copy/paste 430548: [Constraints] ConstraintLink not show on diagram after drag and drop from Model Explorer https://bugs.eclipse.org/bugs/show_bug.cgi?id=430548
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/policies/ClassDiagramDragDropEditPolicy.java900
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ShowConstraintContextLink.java15
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java4
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/META-INF/MANIFEST.MF71
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.di2
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.notation47
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.uml8
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/AllTests.java70
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/copyPaste/ConstraintPasteStrategyTest.java182
9 files changed, 813 insertions, 486 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/policies/ClassDiagramDragDropEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/policies/ClassDiagramDragDropEditPolicy.java
index 25c6fa77038..93a36d3e90d 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/policies/ClassDiagramDragDropEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/policies/ClassDiagramDragDropEditPolicy.java
@@ -1,417 +1,483 @@
-/*****************************************************************************
- * Copyright (c) 2009 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.clazz.custom.policies;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
-import org.eclipse.gmf.runtime.emf.type.core.IElementType;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.uml.diagram.clazz.custom.helper.AssociationClassHelper;
-import org.eclipse.papyrus.uml.diagram.clazz.custom.helper.ClassLinkMappingHelper;
-import org.eclipse.papyrus.uml.diagram.clazz.custom.helper.ContainmentHelper;
-import org.eclipse.papyrus.uml.diagram.clazz.custom.helper.CustomMultiAssociationHelper;
-import org.eclipse.papyrus.uml.diagram.clazz.custom.helper.InstanceSpecificationLinkHelper;
-import org.eclipse.papyrus.uml.diagram.clazz.custom.helper.MultiDependencyHelper;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.AssociationClassEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.AssociationEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.AssociationNodeEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ClassEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ClassEditPartCN;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.DependencyEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.DependencyNodeEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.EnumerationLiteralEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InstanceSpecificationEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InstanceSpecificationEditPartCN;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InstanceSpecificationLinkEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InterfaceRealizationEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ModelEditPartCN;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ModelEditPartTN;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.NestedClassForClassEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.PackageEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.PackageEditPartCN;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.RedefinableTemplateSignatureEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.SubstitutionEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.UsageEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.part.UMLVisualIDRegistry;
-import org.eclipse.papyrus.uml.diagram.clazz.providers.UMLElementTypes;
-import org.eclipse.papyrus.uml.diagram.common.editpolicies.CommonDiagramDragDropEditPolicy;
-import org.eclipse.uml2.uml.Association;
-import org.eclipse.uml2.uml.AssociationClass;
-import org.eclipse.uml2.uml.Dependency;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.InstanceSpecification;
-import org.eclipse.uml2.uml.PackageableElement;
-
-/**
- * The Class ClassDiagramDragDropEditPolicy.
- */
-public class ClassDiagramDragDropEditPolicy extends CommonDiagramDragDropEditPolicy {
-
- public static final String CONTAINED_CLASS_DROP_TO_COMPARTMENT = "ContainedClassDropToCompartment";
-
- /**
- * Instantiates a new class diagram drag drop edit policy.
- */
- public ClassDiagramDragDropEditPolicy() {
- super(ClassLinkMappingHelper.getInstance());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Set<Integer> getDroppableElementVisualId() {
- Set<Integer> droppableElementsVisualID = new HashSet<Integer>();
- droppableElementsVisualID.add(DependencyNodeEditPart.VISUAL_ID);
- droppableElementsVisualID.add(AssociationEditPart.VISUAL_ID);
- droppableElementsVisualID.add(AssociationClassEditPart.VISUAL_ID);
- droppableElementsVisualID.add(AssociationNodeEditPart.VISUAL_ID);
- droppableElementsVisualID.add(NestedClassForClassEditPart.VISUAL_ID);
- droppableElementsVisualID.add(ClassEditPartCN.VISUAL_ID);
- droppableElementsVisualID.add(PackageEditPartCN.VISUAL_ID);
- droppableElementsVisualID.add(ModelEditPartCN.VISUAL_ID);
- droppableElementsVisualID.add(ModelEditPartTN.VISUAL_ID);
- droppableElementsVisualID.add(ClassEditPart.VISUAL_ID);
- droppableElementsVisualID.add(PackageEditPart.VISUAL_ID);
- droppableElementsVisualID.add(InstanceSpecificationEditPart.VISUAL_ID);
- droppableElementsVisualID.add(InstanceSpecificationLinkEditPart.VISUAL_ID);
- return droppableElementsVisualID;
- }
-
- /**
- * {@inheritedDoc}
- */
- @Override
- protected Command getSpecificDropCommand(DropObjectsRequest dropRequest, Element semanticLink, int nodeVISUALID, int linkVISUALID) {
- // respecify for enumeration because this is also an instancespecification
- if (nodeVISUALID == EnumerationLiteralEditPart.VISUAL_ID) {
- return new ICommandProxy(getDefaultDropNodeCommand(nodeVISUALID, dropRequest.getLocation(), semanticLink));
- }
- if (nodeVISUALID == InstanceSpecificationEditPart.VISUAL_ID || linkVISUALID == InstanceSpecificationLinkEditPart.VISUAL_ID) {
- return dropInstanceSpecification(dropRequest, semanticLink, linkVISUALID);
- }
- if (linkVISUALID == SubstitutionEditPart.VISUAL_ID) {
- return dropAsNormalBinaryLink(dropRequest, semanticLink, linkVISUALID);
- }
- if (linkVISUALID == InterfaceRealizationEditPart.VISUAL_ID) {
- return dropAsNormalBinaryLink(dropRequest, semanticLink, linkVISUALID);
- }
- if (linkVISUALID == AssociationEditPart.VISUAL_ID) {
- return dropAssociation(dropRequest, semanticLink);
- }
- if (linkVISUALID == UsageEditPart.VISUAL_ID) {
- return dropAsNormalBinaryLink(dropRequest, semanticLink, linkVISUALID);
- }
- switch (nodeVISUALID) {
- case DependencyNodeEditPart.VISUAL_ID:
- return dropDependency(dropRequest, semanticLink);
- case AssociationClassEditPart.VISUAL_ID:
- return dropAssociationClass(dropRequest, semanticLink, nodeVISUALID);
- case AssociationNodeEditPart.VISUAL_ID:
- return dropAssociation(dropRequest, semanticLink);
- case NestedClassForClassEditPart.VISUAL_ID:
- case ClassEditPartCN.VISUAL_ID:
- case PackageEditPartCN.VISUAL_ID:
- case ModelEditPartCN.VISUAL_ID:
- return dropChildNodeWithContainmentLink(dropRequest, semanticLink, nodeVISUALID);
- case ModelEditPartTN.VISUAL_ID:
- case ClassEditPart.VISUAL_ID:
- case PackageEditPart.VISUAL_ID:
- return dropTopLevelNodeWithContainmentLink(dropRequest, semanticLink, nodeVISUALID);
- default:
- return UnexecutableCommand.INSTANCE;
- }
- }
-
- /**
- * drop a instance specification as a link or as a node
- *
- * @param dropRequest
- * the drop request
- * @param semanticLink
- * the element
- * @param linkVISUALID
- * the visualID
- * @return the command in charge of the drop
- */
- protected Command dropInstanceSpecification(DropObjectsRequest dropRequest, Element semanticLink, int linkVISUALID) {
- if (semanticLink instanceof InstanceSpecification) {
- if (((InstanceSpecification) semanticLink).getClassifiers().size() > 0) {
- if (((InstanceSpecification) semanticLink).getClassifiers().get(0) instanceof Association) {
- // DROP AS LINK
- List<InstanceSpecification> endTypes = InstanceSpecificationLinkHelper.getEnds(((InstanceSpecification) semanticLink));
- if (endTypes.size() > 0) {
- Element source = endTypes.get(0);
- Element target = endTypes.get(1);
- return new ICommandProxy(dropBinaryLink(new CompositeCommand("drop Instance"), source, target, InstanceSpecificationLinkEditPart.VISUAL_ID, dropRequest.getLocation(), semanticLink));
- }
- }
- }
- // DROP AS A NODE
- EObject graphicalParent = ((GraphicalEditPart) getHost()).resolveSemanticElement();
- // Restrict the default node creation to the following cases:
- // . Take the containment relationship into consideration
- // . Release the constraint when GraphicalParent is a diagram
- // drop into diagram
- if (getHost().getModel() instanceof Diagram) {
- return new ICommandProxy(getDefaultDropNodeCommand(InstanceSpecificationEditPart.VISUAL_ID, dropRequest.getLocation(), semanticLink));
- // drop into another editpart
- } else if ((graphicalParent instanceof Element) && ((Element) graphicalParent).getOwnedElements().contains(semanticLink)) {
- return new ICommandProxy(getDefaultDropNodeCommand(InstanceSpecificationEditPartCN.VISUAL_ID, dropRequest.getLocation(), semanticLink));
- }
- }
- return UnexecutableCommand.INSTANCE;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int getLinkWithClassVisualID(EObject domainElement) {
- return UMLVisualIDRegistry.getLinkWithClassVisualID(domainElement);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int getNodeVisualID(View containerView, EObject domainElement) {
- return UMLVisualIDRegistry.getNodeVisualID(containerView, domainElement);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public IElementType getUMLElementType(int elementID) {
- return UMLElementTypes.getElementType(elementID);
- }
-
- /**
- * this method has in charge to create command for create an association if the number of
- * endtype is superior of 2 a multi association is dropped. if the number of endtype this is
- * binary association that is dropped.
- *
- * @param dropRequest
- * the drop request
- * @param semanticLink
- * the semantic link
- * @param nodeVISUALID
- * the node visualid
- *
- * @return the command
- */
- protected Command dropAssociation(DropObjectsRequest dropRequest, Element semanticLink) {
- Collection<?> endtypes = ClassLinkMappingHelper.getInstance().getSource(semanticLink);
- if (endtypes.size() == 1) {
- Element source = (Element) endtypes.toArray()[0];
- Element target = (Element) endtypes.toArray()[0];
- return new ICommandProxy(dropBinaryLink(new CompositeCommand("drop Association"), source, target, AssociationEditPart.VISUAL_ID, dropRequest.getLocation(), semanticLink));
- }
- if (endtypes.size() == 2) {
- Element source = (Element) endtypes.toArray()[0];
- Element target = (Element) endtypes.toArray()[1];
- return new ICommandProxy(dropBinaryLink(new CompositeCommand("drop Association"), source, target, AssociationEditPart.VISUAL_ID, dropRequest.getLocation(), semanticLink));
- }
- if (endtypes.size() > 2) {
- CustomMultiAssociationHelper associationHelper = new CustomMultiAssociationHelper(getEditingDomain());
- return associationHelper.dropMutliAssociation((Association) semanticLink, getViewer(), getDiagramPreferencesHint(), dropRequest.getLocation(), ((GraphicalEditPart) getHost()).getNotationView());
- }
- return UnexecutableCommand.INSTANCE;
- }
-
- /**
- * this method send a Command that create views for associationClass
- *
- * @param dropRequest
- * the drop request
- * @param semanticLink
- * the semantic link
- * @param nodeVISUALID
- * the node visualid
- *
- * @return the command
- */
- protected Command dropAssociationClass(DropObjectsRequest dropRequest, Element semanticLink, int nodeVISUALID) {
- AssociationClassHelper associationClassHelper = new AssociationClassHelper(getEditingDomain());
- return associationClassHelper.dropAssociationClass((AssociationClass) semanticLink, getViewer(), getDiagramPreferencesHint(), dropRequest.getLocation(), ((GraphicalEditPart) getHost()).getNotationView());
- }
-
- /**
- * this method send a command to create views to display
- *
- * @param dropRequest
- * the drop request
- * @param semanticLink
- * the semantic link
- * @param nodeVISUALID
- * the node visualid
- *
- * @return the command
- */
- protected Command dropDependency(DropObjectsRequest dropRequest, Element semanticLink) {
- Collection<?> sources = ClassLinkMappingHelper.getInstance().getSource(semanticLink);
- Collection<?> targets = ClassLinkMappingHelper.getInstance().getTarget(semanticLink);
- if (sources.size() == 1 && targets.size() == 1) {
- Element source = (Element) sources.toArray()[0];
- Element target = (Element) targets.toArray()[0];
- return new ICommandProxy(dropBinaryLink(new CompositeCommand("drop Dependency"), source, target, DependencyEditPart.VISUAL_ID, dropRequest.getLocation(), semanticLink));
- }
- if (sources.size() > 1 || targets.size() > 1) {
- MultiDependencyHelper dependencyHelper = new MultiDependencyHelper(getEditingDomain(), getCompositeCommandRegistry());
- return dependencyHelper.dropMutliDependency((Dependency) semanticLink, getViewer(), getDiagramPreferencesHint(), dropRequest.getLocation(), ((GraphicalEditPart) getHost()).getNotationView());
- }
- return UnexecutableCommand.INSTANCE;
- }
-
- /**
- * Use to drop a class from the outline to the diagram
- *
- * @param dropRequest
- * is the request for the drop, never be null
- * @param semanticObject
- * is the class dropped
- * @param nodeVISUALID
- * is the visual ID of the class
- * @return a command to execute
- */
- protected Command dropTopLevelNodeWithContainmentLink(DropObjectsRequest dropRequest, Element semanticObject, int nodeVISUALID) {
- ContainmentHelper containmentHelper = new ContainmentHelper(getEditingDomain());
- Element owner = semanticObject.getOwner();
- if (owner == null) {
- return new ICommandProxy(getDefaultDropNodeCommand(nodeVISUALID, dropRequest.getLocation(), semanticObject));
- }
- EditPart ownerEditPart = containmentHelper.findEditPartFor(getViewer().getEditPartRegistry(), owner);
- if (ownerEditPart != null) {
- return containmentHelper.outlineDropContainedClass((PackageableElement) semanticObject, getViewer(), getDiagramPreferencesHint(), dropRequest.getLocation(), ((GraphicalEditPart) getHost()).getNotationView());
- } else {
- return new ICommandProxy(getDefaultDropNodeCommand(nodeVISUALID, dropRequest.getLocation(), semanticObject));
- }
- }
-
- /**
- * Use to drop a class from the diagram to the nestedClassifierCompartment
- *
- * @param dropRequest
- * is the request for the drop, never be null
- * @param droppedElement
- * is the class dropped
- * @param nodeVISUALID
- * is the visual ID of the class
- * @return a command to execute
- */
- protected Command dropChildNodeWithContainmentLink(DropObjectsRequest dropRequest, Element droppedElement, int nodeVISUALID) {
- ContainmentHelper containmentHelper = new ContainmentHelper(getEditingDomain());
- CompositeCommand cc = new CompositeCommand(CONTAINED_CLASS_DROP_TO_COMPARTMENT);
- cc.add(getDefaultDropNodeCommand(nodeVISUALID, dropRequest.getLocation(), droppedElement));
- EObject graphicalParent = ((GraphicalEditPart) getHost()).resolveSemanticElement();
- if (!((droppedElement instanceof Element) && ((Element) graphicalParent).getOwnedElements().contains(droppedElement))) {
- return UnexecutableCommand.INSTANCE;
- }
- if (containmentHelper.findEditPartFor(getViewer().getEditPartRegistry(), droppedElement) != null) {
- EditPart editpart = containmentHelper.findEditPartFor(getViewer().getEditPartRegistry(), droppedElement);
- View droppedView = (View) (editpart.getModel());
- containmentHelper.deleteIncomingContainmentLinksFor(cc, droppedView);
- // Delete the dropped element existing outside the compartment
- cc.add(new DeleteCommand(getEditingDomain(), droppedView));
- }
- return new ICommandProxy(cc);
- }
-
- /**
- * call the mechanism to drop a binary link without specific type
- *
- * @param dropRequest
- * the drop request
- * @param semanticLink
- * the element that is the interfaceRealization
- * @param linkVISUALID
- * the visualID of the interfaceRealization
- * @return the command containing the creation of the view ffor a link
- */
- protected Command dropAsNormalBinaryLink(DropObjectsRequest dropRequest, Element semanticLink, int linkVISUALID) {
- Collection<?> sources = linkmappingHelper.getSource(semanticLink);
- Collection<?> targets = linkmappingHelper.getTarget(semanticLink);
- if (sources.size() == 0 || targets.size() == 0) {
- return UnexecutableCommand.INSTANCE;
- }
- Element source = (Element) sources.toArray()[0];
- Element target = (Element) targets.toArray()[0];
- CompositeCommand cc = new CompositeCommand("");
- dropBinaryLink(cc, source, target, linkVISUALID, dropRequest.getLocation(), semanticLink);
- return new ICommandProxy(cc);
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editpolicies.DiagramDragDropEditPolicy#getDropCommand(org.eclipse.gef.requests.ChangeBoundsRequest)
- *
- */
- @Override
- protected Command getDropCommand(ChangeBoundsRequest request) {
- // this is a drop done by user internal to the diagram
- // prevent from the drop intra diagram of a template signature into the diagram
- Iterator<?> editPartsIter = request.getEditParts().iterator();
- while (editPartsIter.hasNext()) {
- if (editPartsIter.next() instanceof RedefinableTemplateSignatureEditPart) {
- return UnexecutableCommand.INSTANCE;
- }
- }
- // in the case of labelEditPart the command add can launch null pointer exception
- editPartsIter = request.getEditParts().iterator();
- boolean containsLabelEditpart = false;
- while (editPartsIter.hasNext() && !containsLabelEditpart) {
- EditPart currentEditPart = (EditPart) editPartsIter.next();
- if (currentEditPart instanceof ITextAwareEditPart && currentEditPart instanceof IPrimaryEditPart) {
- containsLabelEditpart = true;
- }
- }
- // the addCommand of a label edit part into the diagram raises an null pointer exception.
- // it is due to the label has not constraint, used during the AddCommand
- if (containsLabelEditpart && getHost() instanceof DiagramEditPart) {
- return UnexecutableCommand.INSTANCE;
- } else {
- // normal case
- ChangeBoundsRequest req = new ChangeBoundsRequest(REQ_ADD);
- req.setEditParts(request.getEditParts());
- req.setMoveDelta(request.getMoveDelta());
- req.setSizeDelta(request.getSizeDelta());
- req.setLocation(request.getLocation());
- req.setResizeDirection(request.getResizeDirection());
- Command cmd = getHost().getCommand(req);
- if (cmd == null || !cmd.canExecute()) {
- return getDropObjectsCommand(castToDropObjectsRequest(request));
- }
- return cmd;
- }
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2009 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.clazz.custom.policies;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.commands.wrappers.GMFtoGEFCommandWrapper;
+import org.eclipse.papyrus.uml.diagram.clazz.custom.helper.AssociationClassHelper;
+import org.eclipse.papyrus.uml.diagram.clazz.custom.helper.ClassLinkMappingHelper;
+import org.eclipse.papyrus.uml.diagram.clazz.custom.helper.ContainmentHelper;
+import org.eclipse.papyrus.uml.diagram.clazz.custom.helper.CustomMultiAssociationHelper;
+import org.eclipse.papyrus.uml.diagram.clazz.custom.helper.InstanceSpecificationLinkHelper;
+import org.eclipse.papyrus.uml.diagram.clazz.custom.helper.MultiDependencyHelper;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.AssociationClassEditPart;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.AssociationEditPart;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.AssociationNodeEditPart;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ClassEditPart;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ClassEditPartCN;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ConstraintEditPart;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.DependencyEditPart;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.DependencyNodeEditPart;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.EnumerationLiteralEditPart;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InstanceSpecificationEditPart;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InstanceSpecificationEditPartCN;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InstanceSpecificationLinkEditPart;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InterfaceRealizationEditPart;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ModelEditPartCN;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ModelEditPartTN;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.NestedClassForClassEditPart;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.PackageEditPart;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.PackageEditPartCN;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.RedefinableTemplateSignatureEditPart;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.SubstitutionEditPart;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.UsageEditPart;
+import org.eclipse.papyrus.uml.diagram.clazz.part.UMLVisualIDRegistry;
+import org.eclipse.papyrus.uml.diagram.clazz.providers.UMLElementTypes;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.CommonDiagramDragDropEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.strategy.paste.ShowConstraintContextLink;
+import org.eclipse.uml2.uml.Association;
+import org.eclipse.uml2.uml.AssociationClass;
+import org.eclipse.uml2.uml.Constraint;
+import org.eclipse.uml2.uml.Dependency;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.InstanceSpecification;
+import org.eclipse.uml2.uml.PackageableElement;
+
+/**
+ * The Class ClassDiagramDragDropEditPolicy.
+ */
+public class ClassDiagramDragDropEditPolicy extends CommonDiagramDragDropEditPolicy {
+
+ public static final String CONTAINED_CLASS_DROP_TO_COMPARTMENT = "ContainedClassDropToCompartment";
+
+ /**
+ * Instantiates a new class diagram drag drop edit policy.
+ */
+ public ClassDiagramDragDropEditPolicy() {
+ super(ClassLinkMappingHelper.getInstance());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Set<Integer> getDroppableElementVisualId() {
+ Set<Integer> droppableElementsVisualID = new HashSet<Integer>();
+ droppableElementsVisualID.add(DependencyNodeEditPart.VISUAL_ID);
+ droppableElementsVisualID.add(AssociationEditPart.VISUAL_ID);
+ droppableElementsVisualID.add(AssociationClassEditPart.VISUAL_ID);
+ droppableElementsVisualID.add(AssociationNodeEditPart.VISUAL_ID);
+ droppableElementsVisualID.add(NestedClassForClassEditPart.VISUAL_ID);
+ droppableElementsVisualID.add(ClassEditPartCN.VISUAL_ID);
+ droppableElementsVisualID.add(PackageEditPartCN.VISUAL_ID);
+ droppableElementsVisualID.add(ModelEditPartCN.VISUAL_ID);
+ droppableElementsVisualID.add(ModelEditPartTN.VISUAL_ID);
+ droppableElementsVisualID.add(ClassEditPart.VISUAL_ID);
+ droppableElementsVisualID.add(PackageEditPart.VISUAL_ID);
+ droppableElementsVisualID.add(InstanceSpecificationEditPart.VISUAL_ID);
+ droppableElementsVisualID.add(InstanceSpecificationLinkEditPart.VISUAL_ID);
+ droppableElementsVisualID.add(ConstraintEditPart.VISUAL_ID);
+ return droppableElementsVisualID;
+ }
+
+ /**
+ * {@inheritedDoc}
+ */
+ @Override
+ protected Command getSpecificDropCommand(DropObjectsRequest dropRequest, Element semanticLink, int nodeVISUALID, int linkVISUALID) {
+ // respecify for enumeration because this is also an instancespecification
+ if (nodeVISUALID == EnumerationLiteralEditPart.VISUAL_ID) {
+ return new ICommandProxy(getDefaultDropNodeCommand(nodeVISUALID, dropRequest.getLocation(), semanticLink));
+ }
+ if (nodeVISUALID == InstanceSpecificationEditPart.VISUAL_ID || linkVISUALID == InstanceSpecificationLinkEditPart.VISUAL_ID) {
+ return dropInstanceSpecification(dropRequest, semanticLink, linkVISUALID);
+ }
+ if (linkVISUALID == SubstitutionEditPart.VISUAL_ID) {
+ return dropAsNormalBinaryLink(dropRequest, semanticLink, linkVISUALID);
+ }
+ if (linkVISUALID == InterfaceRealizationEditPart.VISUAL_ID) {
+ return dropAsNormalBinaryLink(dropRequest, semanticLink, linkVISUALID);
+ }
+ if (linkVISUALID == AssociationEditPart.VISUAL_ID) {
+ return dropAssociation(dropRequest, semanticLink);
+ }
+ if (linkVISUALID == UsageEditPart.VISUAL_ID) {
+ return dropAsNormalBinaryLink(dropRequest, semanticLink, linkVISUALID);
+ }
+ switch (nodeVISUALID) {
+ case DependencyNodeEditPart.VISUAL_ID:
+ return dropDependency(dropRequest, semanticLink);
+ case AssociationClassEditPart.VISUAL_ID:
+ return dropAssociationClass(dropRequest, semanticLink, nodeVISUALID);
+ case AssociationNodeEditPart.VISUAL_ID:
+ return dropAssociation(dropRequest, semanticLink);
+ case NestedClassForClassEditPart.VISUAL_ID:
+ case ClassEditPartCN.VISUAL_ID:
+
+ case PackageEditPartCN.VISUAL_ID:
+ case ModelEditPartCN.VISUAL_ID:
+ return dropChildNodeWithContainmentLink(dropRequest, semanticLink, nodeVISUALID);
+ case ModelEditPartTN.VISUAL_ID:
+ case ClassEditPart.VISUAL_ID:
+ case PackageEditPart.VISUAL_ID:
+ return dropTopLevelNodeWithContainmentLink(dropRequest, semanticLink, nodeVISUALID);
+ case ConstraintEditPart.VISUAL_ID:
+ return dropConstraintNode(dropRequest, (Constraint) semanticLink, nodeVISUALID);
+ default:
+ return UnexecutableCommand.INSTANCE;
+ }
+ }
+
+ /**
+ * drop a instance specification as a link or as a node
+ *
+ * @param dropRequest
+ * the drop request
+ * @param semanticLink
+ * the element
+ * @param linkVISUALID
+ * the visualID
+ * @return the command in charge of the drop
+ */
+ protected Command dropInstanceSpecification(DropObjectsRequest dropRequest, Element semanticLink, int linkVISUALID) {
+ if (semanticLink instanceof InstanceSpecification) {
+ if (((InstanceSpecification) semanticLink).getClassifiers().size() > 0) {
+ if (((InstanceSpecification) semanticLink).getClassifiers().get(0) instanceof Association) {
+ // DROP AS LINK
+ List<InstanceSpecification> endTypes = InstanceSpecificationLinkHelper.getEnds(((InstanceSpecification) semanticLink));
+ if (endTypes.size() > 0) {
+ Element source = endTypes.get(0);
+ Element target = endTypes.get(1);
+ return new ICommandProxy(dropBinaryLink(new CompositeCommand("drop Instance"), source, target, InstanceSpecificationLinkEditPart.VISUAL_ID, dropRequest.getLocation(), semanticLink));
+ }
+ }
+ }
+ // DROP AS A NODE
+ EObject graphicalParent = ((GraphicalEditPart) getHost()).resolveSemanticElement();
+ // Restrict the default node creation to the following cases:
+ // . Take the containment relationship into consideration
+ // . Release the constraint when GraphicalParent is a diagram
+ // drop into diagram
+ if (getHost().getModel() instanceof Diagram) {
+ return new ICommandProxy(getDefaultDropNodeCommand(InstanceSpecificationEditPart.VISUAL_ID, dropRequest.getLocation(), semanticLink));
+ // drop into another editpart
+ } else if ((graphicalParent instanceof Element) && ((Element) graphicalParent).getOwnedElements().contains(semanticLink)) {
+ return new ICommandProxy(getDefaultDropNodeCommand(InstanceSpecificationEditPartCN.VISUAL_ID, dropRequest.getLocation(), semanticLink));
+ }
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getLinkWithClassVisualID(EObject domainElement) {
+ return UMLVisualIDRegistry.getLinkWithClassVisualID(domainElement);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getNodeVisualID(View containerView, EObject domainElement) {
+ return UMLVisualIDRegistry.getNodeVisualID(containerView, domainElement);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IElementType getUMLElementType(int elementID) {
+ return UMLElementTypes.getElementType(elementID);
+ }
+
+ /**
+ * this method has in charge to create command for create an association if the number of
+ * endtype is superior of 2 a multi association is dropped. if the number of endtype this is
+ * binary association that is dropped.
+ *
+ * @param dropRequest
+ * the drop request
+ * @param semanticLink
+ * the semantic link
+ * @param nodeVISUALID
+ * the node visualid
+ *
+ * @return the command
+ */
+ protected Command dropAssociation(DropObjectsRequest dropRequest, Element semanticLink) {
+ Collection<?> endtypes = ClassLinkMappingHelper.getInstance().getSource(semanticLink);
+ if (endtypes.size() == 1) {
+ Element source = (Element) endtypes.toArray()[0];
+ Element target = (Element) endtypes.toArray()[0];
+ return new ICommandProxy(dropBinaryLink(new CompositeCommand("drop Association"), source, target, AssociationEditPart.VISUAL_ID, dropRequest.getLocation(), semanticLink));
+ }
+ if (endtypes.size() == 2) {
+ Element source = (Element) endtypes.toArray()[0];
+ Element target = (Element) endtypes.toArray()[1];
+ return new ICommandProxy(dropBinaryLink(new CompositeCommand("drop Association"), source, target, AssociationEditPart.VISUAL_ID, dropRequest.getLocation(), semanticLink));
+ }
+ if (endtypes.size() > 2) {
+ CustomMultiAssociationHelper associationHelper = new CustomMultiAssociationHelper(getEditingDomain());
+ return associationHelper.dropMutliAssociation((Association) semanticLink, getViewer(), getDiagramPreferencesHint(), dropRequest.getLocation(), ((GraphicalEditPart) getHost()).getNotationView());
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ /**
+ * this method send a Command that create views for associationClass
+ *
+ * @param dropRequest
+ * the drop request
+ * @param semanticLink
+ * the semantic link
+ * @param nodeVISUALID
+ * the node visualid
+ *
+ * @return the command
+ */
+ protected Command dropAssociationClass(DropObjectsRequest dropRequest, Element semanticLink, int nodeVISUALID) {
+ AssociationClassHelper associationClassHelper = new AssociationClassHelper(getEditingDomain());
+ return associationClassHelper.dropAssociationClass((AssociationClass) semanticLink, getViewer(), getDiagramPreferencesHint(), dropRequest.getLocation(), ((GraphicalEditPart) getHost()).getNotationView());
+ }
+
+ /**
+ * this method send a command to create views to display
+ *
+ * @param dropRequest
+ * the drop request
+ * @param semanticLink
+ * the semantic link
+ * @param nodeVISUALID
+ * the node visualid
+ *
+ * @return the command
+ */
+ protected Command dropDependency(DropObjectsRequest dropRequest, Element semanticLink) {
+ Collection<?> sources = ClassLinkMappingHelper.getInstance().getSource(semanticLink);
+ Collection<?> targets = ClassLinkMappingHelper.getInstance().getTarget(semanticLink);
+ if (sources.size() == 1 && targets.size() == 1) {
+ Element source = (Element) sources.toArray()[0];
+ Element target = (Element) targets.toArray()[0];
+ return new ICommandProxy(dropBinaryLink(new CompositeCommand("drop Dependency"), source, target, DependencyEditPart.VISUAL_ID, dropRequest.getLocation(), semanticLink));
+ }
+ if (sources.size() > 1 || targets.size() > 1) {
+ MultiDependencyHelper dependencyHelper = new MultiDependencyHelper(getEditingDomain(), getCompositeCommandRegistry());
+ return dependencyHelper.dropMutliDependency((Dependency) semanticLink, getViewer(), getDiagramPreferencesHint(), dropRequest.getLocation(), ((GraphicalEditPart) getHost()).getNotationView());
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ /**
+ * Use to drop a class from the outline to the diagram
+ *
+ * @param dropRequest
+ * is the request for the drop, never be null
+ * @param semanticObject
+ * is the class dropped
+ * @param nodeVISUALID
+ * is the visual ID of the class
+ * @return a command to execute
+ */
+ protected Command dropTopLevelNodeWithContainmentLink(DropObjectsRequest dropRequest, Element semanticObject, int nodeVISUALID) {
+ ContainmentHelper containmentHelper = new ContainmentHelper(getEditingDomain());
+ Element owner = semanticObject.getOwner();
+ if (owner == null) {
+ return new ICommandProxy(getDefaultDropNodeCommand(nodeVISUALID, dropRequest.getLocation(), semanticObject));
+ }
+ EditPart ownerEditPart = containmentHelper.findEditPartFor(getViewer().getEditPartRegistry(), owner);
+ if (ownerEditPart != null) {
+ return containmentHelper.outlineDropContainedClass((PackageableElement) semanticObject, getViewer(), getDiagramPreferencesHint(), dropRequest.getLocation(), ((GraphicalEditPart) getHost()).getNotationView());
+ } else {
+ return new ICommandProxy(getDefaultDropNodeCommand(nodeVISUALID, dropRequest.getLocation(), semanticObject));
+ }
+ }
+
+ /**
+ * Use to drop a class from the diagram to the nestedClassifierCompartment
+ *
+ * @param dropRequest
+ * is the request for the drop, never be null
+ * @param droppedElement
+ * is the class dropped
+ * @param nodeVISUALID
+ * is the visual ID of the class
+ * @return a command to execute
+ */
+ protected Command dropChildNodeWithContainmentLink(DropObjectsRequest dropRequest, Element droppedElement, int nodeVISUALID) {
+ ContainmentHelper containmentHelper = new ContainmentHelper(getEditingDomain());
+ CompositeCommand cc = new CompositeCommand(CONTAINED_CLASS_DROP_TO_COMPARTMENT);
+ cc.add(getDefaultDropNodeCommand(nodeVISUALID, dropRequest.getLocation(), droppedElement));
+ EObject graphicalParent = ((GraphicalEditPart) getHost()).resolveSemanticElement();
+ if (!((droppedElement instanceof Element) && ((Element) graphicalParent).getOwnedElements().contains(droppedElement))) {
+ return UnexecutableCommand.INSTANCE;
+ }
+ if (containmentHelper.findEditPartFor(getViewer().getEditPartRegistry(), droppedElement) != null) {
+ EditPart editpart = containmentHelper.findEditPartFor(getViewer().getEditPartRegistry(), droppedElement);
+ View droppedView = (View) (editpart.getModel());
+ containmentHelper.deleteIncomingContainmentLinksFor(cc, droppedView);
+ // Delete the dropped element existing outside the compartment
+ cc.add(new DeleteCommand(getEditingDomain(), droppedView));
+ }
+ return new ICommandProxy(cc);
+ }
+
+
+ /**
+ * Use to drop a constraint, will also display the contextlink
+ *
+ * @param dropRequest
+ * @param droppedConstraint
+ * @param nodeVISUALID
+ * @return
+ */
+ protected Command dropConstraintNode(DropObjectsRequest dropRequest, Constraint droppedConstraint, int nodeVISUALID) {
+ ICommand dropConstraintCommand = getDefaultDropNodeCommand(nodeVISUALID, dropRequest.getLocation(), droppedConstraint, dropRequest);
+ if (droppedConstraint.getContext() != null) {
+ ShowConstraintContextLink showConstraintContextLink = new ShowConstraintContextLink(getEditingDomain(), (GraphicalEditPart) getHost(), droppedConstraint);
+ dropConstraintCommand = dropConstraintCommand.compose(showConstraintContextLink);
+ }
+ return GMFtoGEFCommandWrapper.wrap(dropConstraintCommand);
+ }
+
+
+
+ /**
+ * call the mechanism to drop a binary link without specific type
+ *
+ * @param dropRequest
+ * the drop request
+ * @param semanticLink
+ * the element that is the interfaceRealization
+ * @param linkVISUALID
+ * the visualID of the interfaceRealization
+ * @return the command containing the creation of the view ffor a link
+ */
+ protected Command dropAsNormalBinaryLink(DropObjectsRequest dropRequest, Element semanticLink, int linkVISUALID) {
+ Collection<?> sources = linkmappingHelper.getSource(semanticLink);
+ Collection<?> targets = linkmappingHelper.getTarget(semanticLink);
+ if (sources.size() == 0 || targets.size() == 0) {
+ return UnexecutableCommand.INSTANCE;
+ }
+ Element source = (Element) sources.toArray()[0];
+ Element target = (Element) targets.toArray()[0];
+ CompositeCommand cc = new CompositeCommand("");
+ dropBinaryLink(cc, source, target, linkVISUALID, dropRequest.getLocation(), semanticLink);
+ return new ICommandProxy(cc);
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editpolicies.DiagramDragDropEditPolicy#getDropCommand(org.eclipse.gef.requests.ChangeBoundsRequest)
+ *
+ */
+ @Override
+ protected Command getDropCommand(ChangeBoundsRequest request) {
+ // this is a drop done by user internal to the diagram
+ // prevent from the drop intra diagram of a template signature into the diagram
+ Iterator<?> editPartsIter = request.getEditParts().iterator();
+ while (editPartsIter.hasNext()) {
+ if (editPartsIter.next() instanceof RedefinableTemplateSignatureEditPart) {
+ return UnexecutableCommand.INSTANCE;
+ }
+ }
+ // in the case of labelEditPart the command add can launch null pointer exception
+ editPartsIter = request.getEditParts().iterator();
+ boolean containsLabelEditpart = false;
+ while (editPartsIter.hasNext() && !containsLabelEditpart) {
+ EditPart currentEditPart = (EditPart) editPartsIter.next();
+ if (currentEditPart instanceof ITextAwareEditPart && currentEditPart instanceof IPrimaryEditPart) {
+ containsLabelEditpart = true;
+ }
+ }
+ // the addCommand of a label edit part into the diagram raises an null pointer exception.
+ // it is due to the label has not constraint, used during the AddCommand
+ if (containsLabelEditpart && getHost() instanceof DiagramEditPart) {
+ return UnexecutableCommand.INSTANCE;
+ } else {
+ // normal case
+ ChangeBoundsRequest req = new ChangeBoundsRequest(REQ_ADD);
+ req.setEditParts(request.getEditParts());
+ req.setMoveDelta(request.getMoveDelta());
+ req.setSizeDelta(request.getSizeDelta());
+ req.setLocation(request.getLocation());
+ req.setResizeDirection(request.getResizeDirection());
+ Command cmd = getHost().getCommand(req);
+ if (cmd == null || !cmd.canExecute()) {
+ return getDropObjectsCommand(castToDropObjectsRequest(request));
+ }
+ return cmd;
+ }
+ }
+
+ /**
+ * @Overrided org.eclipse.papyrus.uml.diagram.common.editpolicies.CommonDiagramDragDropEditPolicy to resolve cause of repeated definition
+ * of attributes shown outside classes when dragged back
+ *
+ * @param hostEP
+ * The host edit part which will be the parent of the new node
+ * @param semanticHint
+ * the semantic hint of the view to create
+ * @param location
+ * the drop location
+ * @param droppedObject
+ * the object to drop
+ * @param request
+ * the drop request (use to test ctrl key)
+ * @return the creation node command
+ */
+ @Override
+ protected ICommand getDefaultDropNodeCommand(EditPart hostEP, String semanticHint, Point absoluteLocation, EObject droppedObject, DropObjectsRequest request) {
+ GraphicalEditPart parent = (GraphicalEditPart) getHost();
+ if (parent instanceof ListCompartmentEditPart) {
+ @SuppressWarnings("unchecked")
+ List<EditPart> allChildren = parent.getChildren();
+ for (EditPart nextChild : allChildren) {
+ if (!(nextChild instanceof GraphicalEditPart)) {
+ continue;
+ }
+ EObject nextChildSemantic = ((GraphicalEditPart) nextChild).resolveSemanticElement();
+ if (nextChildSemantic == droppedObject) {
+ return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
+ }
+ }
+ }
+ return super.getDefaultDropNodeCommand(hostEP, semanticHint, absoluteLocation, droppedObject, request);
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ShowConstraintContextLink.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ShowConstraintContextLink.java
index 5ddc5fb3a67..0e6be93585d 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ShowConstraintContextLink.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/strategy/paste/ShowConstraintContextLink.java
@@ -62,9 +62,22 @@ public class ShowConstraintContextLink extends AbstractTransactionalCommand {
this.constraint = (Constraint) constraintView.getElement();
}
+ /**
+ * Show the <<context>> link between a constraint and its context
+ *
+ * @param domain
+ * @param targetEditPart
+ * @param constraint
+ */
+ public ShowConstraintContextLink(TransactionalEditingDomain domain, GraphicalEditPart targetEditPart, Constraint constraint) {
+ super(domain, "Show Constraint Context Link", null);
+ this.diagramEP = DiagramEditPartsUtil.getDiagramEditPart(targetEditPart);
+ this.constraint = constraint;
+ }
+
/*
* (non-Javadoc)
- *
+ *
* @see
* org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
* org.eclipse.core.runtime.IAdaptable)
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
index de24d1c0d43..3fbafa43d15 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
@@ -530,6 +530,10 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
editPart.getViewer().getSelectionManager().appendSelection(editPart);
}
+ public void deselect(EditPart editPart) {
+ editPart.getViewer().getSelectionManager().deselect(editPart);
+ }
+
public PaletteViewer getPalette() {
return getPalette(getActiveDiagramEditor());
}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/META-INF/MANIFEST.MF
index 99f18232dda..2e7920628c3 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/META-INF/MANIFEST.MF
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/META-INF/MANIFEST.MF
@@ -1,34 +1,37 @@
-Manifest-Version: 1.0
-Require-Bundle: org.eclipse.ui,
- org.eclipse.core.runtime,
- org.eclipse.papyrus.infra.core;bundle-version="1.0.2",
- org.eclipse.papyrus.editor;bundle-version="1.0.2",
- org.eclipse.papyrus.uml.diagram.clazz;bundle-version="1.0.2",
- org.eclipse.gmf.runtime.diagram.ui.resources.editor;bundle-version="1.2.0",
- org.eclipse.papyrus.uml.diagram.common;bundle-version="1.0.2",
- org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.5.0",
- org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.0.2",
- org.eclipse.papyrus.uml.diagram.tests;bundle-version="1.0.2",
- org.eclipse.uml2.uml;bundle-version="4.0.0",
- org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.0.2",
- org.eclipse.papyrus.infra.core.sasheditor;bundle-version="1.0.2",
- org.junit;bundle-version="4.10.0",
- org.eclipse.papyrus.junit.framework;bundle-version="1.0.2",
- org.eclipse.gmf.tooling.runtime,
- org.eclipse.ui.ide;bundle-version="3.10.0",
- org.eclipse.emf.common.ui;bundle-version="2.9.0",
- org.eclipse.papyrus.infra.widgets;bundle-version="1.0.2",
- org.eclipse.papyrus.junit.utils;bundle-version="1.0.2"
-Export-Package: org.eclipse.papyrus.diagram.clazz.test.createFromPalette,
- org.eclipse.papyrus.uml.diagram.clazz.test,
- org.eclipse.papyrus.uml.diagram.clazz.test.canonical,
- org.eclipse.papyrus.uml.diagram.clazz.test.load
-Bundle-Vendor: %providerName
-Bundle-ActivationPolicy: lazy
-Bundle-Version: 1.0.2.qualifier
-Bundle-Name: %pluginName
-Bundle-Localization: plugin
-Bundle-ManifestVersion: 2
-Bundle-Activator: org.eclipse.papyrus.uml.diagram.clazz.test.Activator
-Bundle-SymbolicName: org.eclipse.papyrus.uml.diagram.clazz.tests
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Manifest-Version: 1.0
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.papyrus.infra.core;bundle-version="1.0.2",
+ org.eclipse.papyrus.editor;bundle-version="1.0.2",
+ org.eclipse.papyrus.uml.diagram.clazz;bundle-version="1.0.2",
+ org.eclipse.gmf.runtime.diagram.ui.resources.editor;bundle-version="1.2.0",
+ org.eclipse.papyrus.uml.diagram.common;bundle-version="1.0.2",
+ org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.5.0",
+ org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.0.2",
+ org.eclipse.papyrus.uml.diagram.tests;bundle-version="1.0.2",
+ org.eclipse.uml2.uml;bundle-version="4.0.0",
+ org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.0.2",
+ org.eclipse.papyrus.infra.core.sasheditor;bundle-version="1.0.2",
+ org.junit;bundle-version="4.10.0",
+ org.eclipse.papyrus.junit.framework;bundle-version="1.0.2",
+ org.eclipse.gmf.tooling.runtime,
+ org.eclipse.ui.ide;bundle-version="3.10.0",
+ org.eclipse.emf.common.ui;bundle-version="2.9.0",
+ org.eclipse.papyrus.infra.widgets;bundle-version="1.0.2",
+ org.eclipse.papyrus.junit.utils;bundle-version="1.0.2",
+ org.eclipse.papyrus.infra.emf;bundle-version="1.0.2",
+ org.eclipse.papyrus.infra.services.openelement;bundle-version="1.0.2",
+ org.eclipse.core.expressions
+Export-Package: org.eclipse.papyrus.diagram.clazz.test.createFromPalette,
+ org.eclipse.papyrus.uml.diagram.clazz.test,
+ org.eclipse.papyrus.uml.diagram.clazz.test.canonical,
+ org.eclipse.papyrus.uml.diagram.clazz.test.load
+Bundle-Vendor: %providerName
+Bundle-ActivationPolicy: lazy
+Bundle-Version: 1.0.2.qualifier
+Bundle-Name: %pluginName
+Bundle-Localization: plugin
+Bundle-ManifestVersion: 2
+Bundle-Activator: org.eclipse.papyrus.uml.diagram.clazz.test.Activator
+Bundle-SymbolicName: org.eclipse.papyrus.uml.diagram.clazz.tests
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.di b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.di
new file mode 100644
index 00000000000..bf9abab340f
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.di
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"/>
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.notation b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.notation
new file mode 100644
index 00000000000..c7eb0c853b6
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.notation
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<notation:Diagram xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:style="http://www.eclipse.org/papyrus/infra/viewpoints/policy/style" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_MQtE8ODIEeOARK60pOvVqQ" type="PapyrusUMLClassDiagram" name="ConstraintClassDiagram" measurementUnit="Pixel">
+ <children xmi:type="notation:Shape" xmi:id="_N2U-8ODIEeOARK60pOvVqQ" type="2008">
+ <children xmi:type="notation:DecorationNode" xmi:id="_N2nS0ODIEeOARK60pOvVqQ" type="5029"/>
+ <children xmi:type="notation:BasicCompartment" xmi:id="_N22jYODIEeOARK60pOvVqQ" type="7017">
+ <styles xmi:type="notation:TitleStyle" xmi:id="_N22jYeDIEeOARK60pOvVqQ"/>
+ <styles xmi:type="notation:SortingStyle" xmi:id="_N22jYuDIEeOARK60pOvVqQ"/>
+ <styles xmi:type="notation:FilteringStyle" xmi:id="_N22jY-DIEeOARK60pOvVqQ"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_N22jZODIEeOARK60pOvVqQ"/>
+ </children>
+ <children xmi:type="notation:BasicCompartment" xmi:id="_N22jZeDIEeOARK60pOvVqQ" type="7018">
+ <styles xmi:type="notation:TitleStyle" xmi:id="_N22jZuDIEeOARK60pOvVqQ"/>
+ <styles xmi:type="notation:SortingStyle" xmi:id="_N22jZ-DIEeOARK60pOvVqQ"/>
+ <styles xmi:type="notation:FilteringStyle" xmi:id="_N22jaODIEeOARK60pOvVqQ"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_N22jaeDIEeOARK60pOvVqQ"/>
+ </children>
+ <children xmi:type="notation:BasicCompartment" xmi:id="_N23KcODIEeOARK60pOvVqQ" type="7019">
+ <styles xmi:type="notation:TitleStyle" xmi:id="_N23KceDIEeOARK60pOvVqQ"/>
+ <styles xmi:type="notation:SortingStyle" xmi:id="_N23KcuDIEeOARK60pOvVqQ"/>
+ <styles xmi:type="notation:FilteringStyle" xmi:id="_N23Kc-DIEeOARK60pOvVqQ"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_N23KdODIEeOARK60pOvVqQ"/>
+ </children>
+ <element xmi:type="uml:Class" href="ConstraintPasteStrategy.uml#_N0UMwODIEeOARK60pOvVqQ"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_N2U-8eDIEeOARK60pOvVqQ" x="391" y="110"/>
+ </children>
+ <children xmi:type="notation:Shape" xmi:id="_OQWogODIEeOARK60pOvVqQ" type="2011">
+ <children xmi:type="notation:DecorationNode" xmi:id="_OQXPkODIEeOARK60pOvVqQ" type="5037"/>
+ <children xmi:type="notation:DecorationNode" xmi:id="_OQXPkeDIEeOARK60pOvVqQ" type="5159"/>
+ <element xmi:type="uml:Constraint" href="ConstraintPasteStrategy.uml#_OQJ0MODIEeOARK60pOvVqQ"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_OQWogeDIEeOARK60pOvVqQ" x="78" y="152"/>
+ </children>
+ <styles xmi:type="notation:DiagramStyle" xmi:id="_MQtE8eDIEeOARK60pOvVqQ"/>
+ <styles xmi:type="style:PapyrusViewStyle" xmi:id="_MQtE8uDIEeOARK60pOvVqQ">
+ <owner xmi:type="uml:Model" href="ConstraintPasteStrategy.uml#_ML1zEODIEeOARK60pOvVqQ"/>
+ </styles>
+ <element xmi:type="uml:Model" href="ConstraintPasteStrategy.uml#_ML1zEODIEeOARK60pOvVqQ"/>
+ <edges xmi:type="notation:Connector" xmi:id="_OaMhAODIEeOARK60pOvVqQ" type="8500" source="_OQWogODIEeOARK60pOvVqQ" target="_N2U-8ODIEeOARK60pOvVqQ">
+ <children xmi:type="notation:DecorationNode" xmi:id="_OaNIEODIEeOARK60pOvVqQ" type="8501">
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_OaNIEeDIEeOARK60pOvVqQ" y="15"/>
+ </children>
+ <styles xmi:type="notation:FontStyle" xmi:id="_OaMhAeDIEeOARK60pOvVqQ"/>
+ <element xsi:nil="true"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_OaMhAuDIEeOARK60pOvVqQ" points="[0, 0, -204, 19]$[160, -14, -44, 5]$[204, -14, 0, 5]"/>
+ <sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_OcQ9kODIEeOARK60pOvVqQ" id="(1.0,0.1)"/>
+ <targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_OcQ9keDIEeOARK60pOvVqQ" id="(0.0,0.48)"/>
+ </edges>
+</notation:Diagram>
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.uml b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.uml
new file mode 100644
index 00000000000..29eca5aff8f
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.uml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_ML1zEODIEeOARK60pOvVqQ" name="model">
+ <packagedElement xmi:type="uml:Class" xmi:id="_N0UMwODIEeOARK60pOvVqQ" name="Class1">
+ <ownedRule xmi:type="uml:Constraint" xmi:id="_OQJ0MODIEeOARK60pOvVqQ" name="Constraint1">
+ <specification xmi:type="uml:LiteralString" xmi:id="_OQMQcODIEeOARK60pOvVqQ" value=""/>
+ </ownedRule>
+ </packagedElement>
+</uml:Model>
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/AllTests.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/AllTests.java
index a4cc80b0140..b054c98d517 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/AllTests.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/AllTests.java
@@ -1,34 +1,36 @@
-/*****************************************************************************
- * Copyright (c) 2009 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.clazz.test;
-
-import org.eclipse.papyrus.uml.diagram.clazz.test.canonical.AllCanonicalTests;
-import org.eclipse.papyrus.uml.diagram.clazz.test.legacy.PackageDiagramLegacyTest;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-import org.junit.runners.Suite.SuiteClasses;
-
-/**
- * All tests together.
- */
-@RunWith(Suite.class)
-@SuiteClasses({
-// canonical
-AllCanonicalTests.class,
-PackageDiagramLegacyTest.class
-// load
-//LoadTests.class
-})
-public class AllTests {
-}
+/*****************************************************************************
+ * Copyright (c) 2009 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.clazz.test;
+
+import org.eclipse.papyrus.uml.diagram.clazz.test.canonical.AllCanonicalTests;
+import org.eclipse.papyrus.uml.diagram.clazz.test.copyPaste.ConstraintPasteStrategyTest;
+import org.eclipse.papyrus.uml.diagram.clazz.test.legacy.PackageDiagramLegacyTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+/**
+ * All tests together.
+ */
+@RunWith(Suite.class)
+@SuiteClasses({
+ // canonical
+ AllCanonicalTests.class,
+ PackageDiagramLegacyTest.class,
+ ConstraintPasteStrategyTest.class
+// load
+// LoadTests.class
+})
+public class AllTests {
+}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/copyPaste/ConstraintPasteStrategyTest.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/copyPaste/ConstraintPasteStrategyTest.java
new file mode 100644
index 00000000000..d96b1e2b241
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/copyPaste/ConstraintPasteStrategyTest.java
@@ -0,0 +1,182 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net- bug430548
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.clazz.test.copyPaste;
+
+
+
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.Shape;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.services.openelement.service.OpenElementService;
+import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest;
+import org.eclipse.papyrus.junit.utils.DiagramUtils;
+import org.eclipse.papyrus.junit.utils.HandlerUtils;
+import org.eclipse.papyrus.junit.utils.rules.PapyrusEditorFixture;
+import org.eclipse.papyrus.junit.utils.rules.PluginResource;
+import org.eclipse.papyrus.junit.utils.rules.ShowView;
+import org.eclipse.papyrus.uml.diagram.clazz.custom.edit.part.CustomConstraintEditPart;
+import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ModelEditPart;
+import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.services.IEvaluationService;
+import org.eclipse.uml2.uml.Model;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+
+
+/**
+ * Tests for constraint paste strategy
+ *
+ * @author Benoit Maggi
+ *
+ */
+@PluginResource("model/copyPaste/ConstraintPasteStrategy.di")
+@ShowView(value = "org.eclipse.papyrus.views.modelexplorer.modelexplorer")
+public class ConstraintPasteStrategyTest extends AbstractPapyrusTest {
+
+ @Rule
+ public final PapyrusEditorFixture editorFixture = new PapyrusEditorFixture();
+
+ public static final String COPY_COMMAND_ID = "org.eclipse.ui.edit.copy"; //$NON-NLS-1$
+
+ public static final String PASTE_COMMAND_ID = "org.eclipse.ui.edit.paste"; //$NON-NLS-1$
+
+ public final static String CLASS1_NAME = "Class1"; //$NON-NLS-1$
+
+ public final static String CONSTRAINT_NAME = "Constraint1"; //$NON-NLS-1$
+
+ public final static String DIAGRAM_NAME = "ConstraintClassDiagram"; //$NON-NLS-1$
+
+
+ /**
+ * Test copy constraint in class diagram.
+ *
+ * @throws Exception
+ * the exception
+ */
+ @Test
+ public void testCopyConstraintInClassDiagram() throws Exception {
+
+ // get all semantic element that will handled
+ Model model = (Model) editorFixture.getModel();
+ Assert.assertNotNull("RootModel is null", model);
+
+
+ org.eclipse.uml2.uml.Class class1 = (org.eclipse.uml2.uml.Class) model.getPackagedElement(CLASS1_NAME);
+ org.eclipse.uml2.uml.Constraint constraint = (org.eclipse.uml2.uml.Constraint) class1.getMember(CONSTRAINT_NAME);
+
+ Assert.assertNotNull("Constraint is missing in the model", constraint);
+
+ Diagram mainDiagram = DiagramUtils.getNotationDiagram(editorFixture.getModelSet(), DIAGRAM_NAME);
+ editorFixture.getPageManager().openPage(mainDiagram);
+ Assert.assertEquals("current opened diagram is not the expected one", mainDiagram.getName(), DIAGRAM_NAME);
+
+ Shape constraintView = DiagramUtils.findShape(mainDiagram, CONSTRAINT_NAME);
+ Assert.assertNotNull("Constraint view not present", constraintView);
+
+ Object defaultSelection = getSelectionLikeTestOnModelExplorer();
+ Object defaultSelectionHandler = getSelectionLikeInAbstractGraphicalHandler();
+
+ editorFixture.flushDisplayEvents();
+ Assert.assertNotNull("Constraint TreeElement is null", defaultSelection); //$NON-NLS-1$
+ Assert.assertEquals("TreeElement is not a model", ModelEditPart.class, defaultSelection.getClass());
+ Assert.assertEquals("TreeElement is not a model", ModelEditPart.class, defaultSelectionHandler.getClass());
+
+ EditPart constraintEP = editorFixture.findEditPart(constraint);
+ editorFixture.select(constraintEP);
+
+
+ IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ ISelectionService selectionService = activeWorkbenchWindow.getSelectionService();
+ Object constraintSelection = ((IStructuredSelection) selectionService.getSelection()).getFirstElement();
+
+ // it's working on service selection
+ Assert.assertEquals("TreeElement is not a constraint", CustomConstraintEditPart.class, constraintSelection.getClass());
+
+ ISelection selection = editorFixture.getEditor().getEditorSite().getSelectionProvider().getSelection();
+ Object editorSelection = ((IStructuredSelection) selection).getFirstElement();
+
+ // it's working on editor selection
+ Assert.assertEquals("TreeElement is not a constraint", CustomConstraintEditPart.class, editorSelection.getClass());
+
+ editorFixture.flushDisplayEvents();
+ Object defaultVariableFromLinkHelperSelection = getSelectionLikeInAbstractGraphicalHandler();
+ Assert.assertEquals("TreeElement is not a constraint", CustomConstraintEditPart.class, defaultVariableFromLinkHelperSelection.getClass());
+
+ // Test with OpenElementService
+ OpenElementService openElementService = ServiceUtilsForEObject.getInstance().getService(OpenElementService.class, constraint);
+ openElementService.openSemanticElement(constraint);
+
+ editorFixture.flushDisplayEvents();
+ Object defaultVariableFromOpenElementService = getSelectionLikeInAbstractGraphicalHandler();
+ Assert.assertEquals("TreeElement is not a constraint", CustomConstraintEditPart.class, defaultVariableFromOpenElementService.getClass());
+
+ // Copy
+ IHandler copyHandler = HandlerUtils.getActiveHandlerFor(COPY_COMMAND_ID);
+ Assert.assertTrue("Copy not available", copyHandler.isEnabled()); //$NON-NLS-1$
+ copyHandler.execute(new ExecutionEvent());
+
+ // Select diagram
+ EditPart modelEP = editorFixture.findEditPart(model);
+ editorFixture.deselect(constraintEP);
+ editorFixture.select(modelEP);
+ editorFixture.getPageManager().selectPage(mainDiagram);
+
+ editorFixture.flushDisplayEvents();
+
+ int amountRulesBeforeCopy = class1.getOwnedRules().size();
+
+ // Paste
+ IHandler pasteHandler = HandlerUtils.getActiveHandlerFor(PASTE_COMMAND_ID);
+ Assert.assertTrue("Paste not available", pasteHandler.isEnabled()); //$NON-NLS-1$
+ pasteHandler.execute(new ExecutionEvent());
+
+ editorFixture.flushDisplayEvents();
+
+ // Check that there is a copy of Constraint
+ Assert.assertEquals("The copy failed", amountRulesBeforeCopy + 1, class1.getOwnedRules().size()); //$NON-NLS-1$
+
+ }
+
+ private Object getSelectionLikeInAbstractGraphicalHandler() {
+ IEvaluationService evaluationService = (IEvaluationService) PlatformUI.getWorkbench().getService(IEvaluationService.class);
+ IEvaluationContext currentState = evaluationService.getCurrentState();
+ Object defaultVariable = currentState.getDefaultVariable();
+ if (defaultVariable instanceof List) {
+ List arrayList = (List) defaultVariable;
+ if (!arrayList.isEmpty()) {
+ return arrayList.get(0);
+ }
+ }
+ return defaultVariable;
+ }
+
+ private Object getSelectionLikeTestOnModelExplorer() {
+ IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ ISelectionService selectionService = activeWorkbenchWindow.getSelectionService();
+ return ((IStructuredSelection) selectionService.getSelection()).getFirstElement();
+ }
+
+
+
+}

Back to the top