diff options
Diffstat (limited to 'uml/org.eclipse.papyrus.diagram.activity/src/org/eclipse/papyrus/diagram/activity/edit/commands/OpaqueActionCreateCommand.java')
-rw-r--r-- | uml/org.eclipse.papyrus.diagram.activity/src/org/eclipse/papyrus/diagram/activity/edit/commands/OpaqueActionCreateCommand.java | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/uml/org.eclipse.papyrus.diagram.activity/src/org/eclipse/papyrus/diagram/activity/edit/commands/OpaqueActionCreateCommand.java b/uml/org.eclipse.papyrus.diagram.activity/src/org/eclipse/papyrus/diagram/activity/edit/commands/OpaqueActionCreateCommand.java new file mode 100644 index 00000000000..7086883ff35 --- /dev/null +++ b/uml/org.eclipse.papyrus.diagram.activity/src/org/eclipse/papyrus/diagram/activity/edit/commands/OpaqueActionCreateCommand.java @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2007 Borland Software Corporation 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: + * Sergey Gribovsky (Borland) - initial API and implementation + * Francisco Javier Cano Mu�oz (Prodevelop) + * Marc Gil Sendra (Prodevelop) + */ +package org.eclipse.papyrus.diagram.activity.edit.commands; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand; +import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.diagram.activity.edit.commands.helpers.ActivityPartitionActivity; +import org.eclipse.papyrus.diagram.activity.part.UMLDiagramEditorPlugin; +import org.eclipse.papyrus.diagram.activity.providers.ElementInitializers; +import org.eclipse.papyrus.diagram.common.util.MultiDiagramUtil; +import org.eclipse.uml2.uml.Activity; +import org.eclipse.uml2.uml.ActivityPartition; +import org.eclipse.uml2.uml.OpaqueAction; +import org.eclipse.uml2.uml.UMLPackage; + + +/** + * @generated + */ +public class OpaqueActionCreateCommand extends CreateElementCommand { + + /** + * @generated + */ + private EClass eClass = null; + + /** + * @generated + */ + private EObject eObject = null; + + /** + * @generated + */ + public OpaqueActionCreateCommand(CreateElementRequest req, EObject eObject) { + super(req); + this.eObject = eObject; + this.eClass = eObject != null ? eObject.eClass() : null; + } + + /** + * @generated + */ + public static OpaqueActionCreateCommand create(CreateElementRequest req, EObject eObject) { + return new OpaqueActionCreateCommand(req, eObject); + } + + /** + * @generated + */ + public OpaqueActionCreateCommand(CreateElementRequest req) { + super(req); + } + + /** + * Modified to return the nearest <Activity> + * + * @generated NOT + */ + @Override + protected EObject getElementToEdit() { + EObject container = ((CreateElementRequest) getRequest()).getContainer(); + if (container instanceof View) { + container = ((View) container).getElement(); + } + // fjcano : we have to return the nearest activity. + if (container instanceof ActivityPartition) { + return ActivityPartitionActivity.getActivityPartitionActivity((ActivityPartition) container); + } + return container; + } + + /** + * @generated + */ + @Override + protected EClass getEClassToEdit() { + + EObject eObject = getElementToEdit(); + if (eObject != null) { + return eObject.eClass(); + } + if (eClass != null) { + return eClass; + } + return UMLPackage.eINSTANCE.getActivity(); + } + + /** + * @generated + */ + protected Diagram getDiagramFromRequest() { + if (getRequest().getParameters().get(MultiDiagramUtil.BelongToDiagramSource) != null) { + Object parameter = getRequest().getParameters().get(MultiDiagramUtil.BelongToDiagramSource); + if (parameter instanceof Diagram) { + return (Diagram) parameter; + } + } + return null; + } + + /** + * @generated + */ + @Override + protected EObject doDefaultElementCreation() { + OpaqueAction newElement = (OpaqueAction) super.doDefaultElementCreation(); + if (newElement != null) { + Activity owner = (Activity) getElementToEdit(); + owner.getNodes().add(newElement); + + ElementInitializers.init_OpaqueAction_2014(newElement); + Diagram diagram = getDiagramFromRequest(); + if (diagram != null) { + MultiDiagramUtil.AddEAnnotationReferenceToDiagram(diagram, newElement); + } else { + MultiDiagramUtil.addEAnnotationReferenceToDiagram(UMLDiagramEditorPlugin.getInstance(), newElement); + } + } + return newElement; + } +} |