Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-02-21 11:24:33 -0500
committercletavernie2012-02-21 11:24:33 -0500
commitb9efd33191fe47cf43db7acda23ccf9dd7505756 (patch)
treeadb4b1c2085cc0da5122ad0302b70b5eb1b239b2 /plugins
parentb41ca4b90a30f657c4057c05a30b1775709d4ce8 (diff)
downloadorg.eclipse.papyrus-b9efd33191fe47cf43db7acda23ccf9dd7505756.tar.gz
org.eclipse.papyrus-b9efd33191fe47cf43db7acda23ccf9dd7505756.tar.xz
org.eclipse.papyrus-b9efd33191fe47cf43db7acda23ccf9dd7505756.zip
364827: [Sequence Diagram] - Synchronous messages creation
https://bugs.eclipse.org/bugs/show_bug.cgi?id=364827
Diffstat (limited to 'plugins')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/command/PromptCreateElementAndNodeCommand.java131
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/ElementCreationWithMessageEditPolicy.java47
2 files changed, 155 insertions, 23 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/command/PromptCreateElementAndNodeCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/command/PromptCreateElementAndNodeCommand.java
new file mode 100644
index 00000000000..8ab9c8eeb4a
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/command/PromptCreateElementAndNodeCommand.java
@@ -0,0 +1,131 @@
+package org.eclipse.papyrus.uml.diagram.sequence.command;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.CompoundCommand;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.ui.commands.CreateOrSelectElementCommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest.ConnectionViewDescriptor;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.ActionExecutionSpecificationEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.BehaviorExecutionSpecificationEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.part.Messages;
+import org.eclipse.papyrus.uml.diagram.sequence.part.UMLVisualIDRegistry;
+import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
+import org.eclipse.papyrus.uml.diagram.sequence.util.SequenceRequestConstant;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.uml2.uml.InteractionFragment;
+
+public class PromptCreateElementAndNodeCommand extends
+ CreateOrSelectElementCommand {
+ private static final List<IElementType> executionTypes = new ArrayList<IElementType>();
+ static {
+ executionTypes.add(UMLElementTypes.ActionExecutionSpecification_3006);
+ executionTypes.add(UMLElementTypes.BehaviorExecutionSpecification_3003);
+ }
+ private final CompoundCommand command;
+ private TransactionalEditingDomain editingDomain;
+ private ConnectionViewDescriptor descriptor;
+ private ShapeNodeEditPart targetEP;
+ private EObject target;
+ private Point location;
+ private InteractionFragment container;
+
+
+ public PromptCreateElementAndNodeCommand(Command createCommand,
+ TransactionalEditingDomain editingDomain,
+ ConnectionViewDescriptor descriptor, ShapeNodeEditPart targetEP,
+ EObject target, Point location, InteractionFragment container) {
+ super(Display.getCurrent().getActiveShell(), executionTypes);
+ this.editingDomain = editingDomain;
+ this.descriptor = descriptor;
+ this.targetEP = targetEP;
+ this.target = target;
+ this.location = location;
+ this.container = container;
+ command = new CompoundCommand();
+ command.add(createCommand);
+ }
+
+ protected CommandResult doExecuteWithResult(
+ IProgressMonitor progressMonitor, IAdaptable info)
+ throws ExecutionException {
+ CommandResult cmdResult = super.doExecuteWithResult(progressMonitor,
+ info);
+ if (!cmdResult.getStatus().isOK()) {
+ return cmdResult;
+ }
+ IHintedType connectionType = (IHintedType) cmdResult.getReturnValue();
+
+ CreateElementAndNodeCommand createExecutionSpecificationCommand = new CreateElementAndNodeCommand(
+ editingDomain, (ShapeNodeEditPart) targetEP, target,
+ connectionType, location);
+ createExecutionSpecificationCommand.putCreateElementRequestParameter(
+ SequenceRequestConstant.INTERACTIONFRAGMENT_CONTAINER,
+ container);
+ command.add(createExecutionSpecificationCommand);
+
+ // put the anchor at the top of the figure
+ ChangeEdgeTargetCommand changeTargetCommand = new ChangeEdgeTargetCommand(
+ editingDomain, createExecutionSpecificationCommand, descriptor,
+ "(0.5, 0.0)");
+ command.add(new ICommandProxy(changeTargetCommand));
+
+ command.execute();
+
+ return CommandResult.newOKCommandResult(descriptor);
+ }
+
+ public boolean canUndo() {
+ return command != null && command.canUndo();
+ }
+
+ protected CommandResult doRedoWithResult(IProgressMonitor progressMonitor,
+ IAdaptable info) throws ExecutionException {
+ if (command != null) {
+ command.redo();
+ }
+ return super.doRedoWithResult(progressMonitor, info);
+ }
+
+ protected CommandResult doUndoWithResult(IProgressMonitor progressMonitor,
+ IAdaptable info) throws ExecutionException {
+ if (command != null) {
+ command.undo();
+ }
+ return super.doUndoWithResult(progressMonitor, info);
+ }
+
+ protected ILabelProvider getLabelProvider() {
+ return new LabelProvider() {
+
+ @Override
+ public String getText(Object object) {
+ if (object instanceof IHintedType) {
+ IHintedType elementType = (IHintedType) object;
+ switch (UMLVisualIDRegistry.getVisualID(elementType
+ .getSemanticHint())) {
+ case ActionExecutionSpecificationEditPart.VISUAL_ID:
+ return Messages.createActionExecutionSpecification2CreationTool_title;
+ case BehaviorExecutionSpecificationEditPart.VISUAL_ID:
+ return Messages.createBehaviorExecutionSpecification3CreationTool_title;
+ }
+ }
+ return super.getText(object);
+ }
+ };
+
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/ElementCreationWithMessageEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/ElementCreationWithMessageEditPolicy.java
index 52c0ca3c905..ad21298ec28 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/ElementCreationWithMessageEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/ElementCreationWithMessageEditPolicy.java
@@ -17,7 +17,6 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.requests.CreateConnectionRequest;
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
@@ -26,12 +25,10 @@ import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewAndElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.uml.diagram.sequence.command.ChangeEdgeTargetCommand;
-import org.eclipse.papyrus.uml.diagram.sequence.command.CreateElementAndNodeCommand;
+import org.eclipse.papyrus.uml.diagram.sequence.command.PromptCreateElementAndNodeCommand;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.ActionExecutionSpecificationEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.BehaviorExecutionSpecificationEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
-import org.eclipse.papyrus.uml.diagram.sequence.util.SequenceRequestConstant;
import org.eclipse.papyrus.uml.diagram.sequence.util.SequenceUtil;
import org.eclipse.uml2.uml.ExecutionSpecification;
import org.eclipse.uml2.uml.InteractionFragment;
@@ -49,12 +46,12 @@ public class ElementCreationWithMessageEditPolicy extends LifelineChildGraphical
@Override
protected Command getConnectionCompleteCommand(CreateConnectionRequest request) {
- CompoundCommand compound = new CompoundCommand();
+// CompoundCommand compound = new CompoundCommand();
Command command = super.getConnectionCompleteCommand(request);
if(command != null && command.canExecute()) {
- compound.add(command);
+// compound.add(command);
if(request instanceof CreateConnectionViewAndElementRequest) {
CreateConnectionViewAndElementRequest viewRequest = (CreateConnectionViewAndElementRequest)request;
@@ -70,34 +67,38 @@ public class ElementCreationWithMessageEditPolicy extends LifelineChildGraphical
InteractionFragment ift = SequenceUtil.findInteractionFragmentContainerAt(viewRequest.getLocation(), getHost());
// retrieve the good execution specification type using the source of the message
- IHintedType elementType = null;
- if(request.getSourceEditPart() instanceof ActionExecutionSpecificationEditPart) {
- elementType = (IHintedType)UMLElementTypes.ActionExecutionSpecification_3006;
- } else if(request.getSourceEditPart() instanceof BehaviorExecutionSpecificationEditPart) {
- elementType = (IHintedType)UMLElementTypes.BehaviorExecutionSpecification_3003;
- }
-
if(target instanceof ExecutionSpecification) {
// retrieve its associated lifeline
targetEP = targetEP.getParent();
target = ViewUtil.resolveSemanticElement((View)targetEP.getModel());
}
-
- if(elementType != null) {
- CreateElementAndNodeCommand createExecutionSpecificationCommand = new CreateElementAndNodeCommand(getEditingDomain(), (ShapeNodeEditPart)targetEP, target, elementType, request.getLocation());
- createExecutionSpecificationCommand.putCreateElementRequestParameter(SequenceRequestConstant.INTERACTIONFRAGMENT_CONTAINER, ift);
- compound.add(createExecutionSpecificationCommand);
-
- // put the anchor at the top of the figure
- ChangeEdgeTargetCommand changeTargetCommand = new ChangeEdgeTargetCommand(getEditingDomain(), createExecutionSpecificationCommand, viewRequest.getConnectionViewDescriptor(), "(0.5, 0.0)");
- compound.add(new ICommandProxy(changeTargetCommand));
+ EditPart sourceEditPart = request.getSourceEditPart();
+ if (sourceEditPart instanceof ActionExecutionSpecificationEditPart || sourceEditPart instanceof BehaviorExecutionSpecificationEditPart) {
+ return new ICommandProxy(new PromptCreateElementAndNodeCommand(command, getEditingDomain(),viewRequest.getConnectionViewDescriptor(),(ShapeNodeEditPart) targetEP, target, request.getLocation(), ift));
}
+// IHintedType elementType = null;
+// if(sourceEditPart instanceof ActionExecutionSpecificationEditPart) {
+// elementType = (IHintedType)UMLElementTypes.ActionExecutionSpecification_3006;
+// } else if(request.getSourceEditPart() instanceof BehaviorExecutionSpecificationEditPart) {
+// elementType = (IHintedType)UMLElementTypes.BehaviorExecutionSpecification_3003;
+// }
+//
+//
+// if(elementType != null) {
+// CreateElementAndNodeCommand createExecutionSpecificationCommand = new CreateElementAndNodeCommand(getEditingDomain(), (ShapeNodeEditPart)targetEP, target, elementType, request.getLocation());
+// createExecutionSpecificationCommand.putCreateElementRequestParameter(SequenceRequestConstant.INTERACTIONFRAGMENT_CONTAINER, ift);
+// compound.add(createExecutionSpecificationCommand);
+//
+// // put the anchor at the top of the figure
+// ChangeEdgeTargetCommand changeTargetCommand = new ChangeEdgeTargetCommand(getEditingDomain(), createExecutionSpecificationCommand, viewRequest.getConnectionViewDescriptor(), "(0.5, 0.0)");
+// compound.add(new ICommandProxy(changeTargetCommand));
+// }
}
}
}
}
- return compound;
+ return command;
}
private static String getSyncMessageHint() {

Back to the top