Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorptessier2013-12-10 15:26:54 +0000
committerptessier2013-12-10 15:26:54 +0000
commit92a4215c1e816dcd445588a86cbc5c8e08ba519a (patch)
treeb52e12beebbe19e5d355e189532476fc94e2576b /plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src
parentb705a508142f201b19d74973e6efdb87edf3d2de (diff)
downloadorg.eclipse.papyrus-92a4215c1e816dcd445588a86cbc5c8e08ba519a.tar.gz
org.eclipse.papyrus-92a4215c1e816dcd445588a86cbc5c8e08ba519a.tar.xz
org.eclipse.papyrus-92a4215c1e816dcd445588a86cbc5c8e08ba519a.zip
423713: [Sequence] DnD of a class on interaction to create a lifeline
with "represents" https://bugs.eclipse.org/bugs/show_bug.cgi?id=423713
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/lifeline/ClassifierToInteractionDropStrategy.java101
1 files changed, 101 insertions, 0 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/lifeline/ClassifierToInteractionDropStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/lifeline/ClassifierToInteractionDropStrategy.java
new file mode 100644
index 00000000000..73e506bab1e
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/lifeline/ClassifierToInteractionDropStrategy.java
@@ -0,0 +1,101 @@
+/*
+ *
+ */
+package org.eclipse.papyrus.uml.diagram.dnd.lifeline;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.requests.DropRequest;
+import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
+import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.TransactionalDropStrategy;
+import org.eclipse.papyrus.uml.diagram.dnd.Activator;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.uml2.uml.Interaction;
+import org.eclipse.uml2.uml.Lifeline;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.Classifier;
+
+public class ClassifierToInteractionDropStrategy extends TransactionalDropStrategy {
+
+ public String getLabel() {
+ return "Create a Lifeline";
+ }
+
+ public String getDescription() {
+ return "Drop a classifier on an interaction , create the lifeline and type it. This will create a new lifeline, a new Property in the interaction, typed by the dropped classifier. The Lifeline will represent this property." + "It is also possible to drop directly an already existing Property to the lifeline.";
+ }
+
+ public Image getImage() {
+ return null;
+ }
+
+ public String getID() {
+ return Activator.PLUGIN_ID + ".ClassifierToLifeline.represents";
+ }
+
+ @Deprecated
+ public int getPriority() {
+ return 0;
+ }
+
+ @Override
+ protected Command doGetCommand(Request request, EditPart targetEditPart) {
+ EObject targetElement = getTargetSemanticElement(targetEditPart);
+ final Point location;
+ if(!(targetElement instanceof Interaction)) {
+ return null;
+ }
+ if( request instanceof DropObjectsRequest){
+ location=((DropObjectsRequest)request).getLocation();
+ }
+ else{
+ location=new Point(100, 100);
+ }
+ final EditPart interactionEditPart= targetEditPart;
+ final Interaction targetInteraction = (Interaction)targetElement;
+
+ List<EObject> sourceElements = getSourceEObjects(request);
+
+ //The only supported case is "Drop a single classifier on an interaction"
+ if(sourceElements.size() != 1) {
+ return null;
+ }
+
+ EObject sourceElement = sourceElements.get(0);
+ if(sourceElement instanceof Type) {
+ final Type sourceType = (Type)sourceElement;
+
+ Command resultCommand = new Command(getLabel()) {
+
+ @Override
+ public void execute() {
+ Lifeline lifeline= targetInteraction.createLifeline("");
+ Property property = targetInteraction.createOwnedAttribute("", sourceType);
+ lifeline.setRepresents(property);
+ ArrayList<Lifeline> droppedLifelines= new ArrayList<Lifeline>();
+ droppedLifelines.add(lifeline);
+ DropObjectsRequest dropRequest= new DropObjectsRequest();
+ dropRequest.setObjects(droppedLifelines);
+ dropRequest.setLocation(location);
+ Command cmd=interactionEditPart.getCommand(dropRequest);
+ cmd.execute();
+
+
+ }
+ };
+
+ return resultCommand;
+ }
+
+ return null;
+ }
+
+}

Back to the top