blob: b98f032e5aefe4b2670803e820a03a9787fecfa8 [file] [log] [blame]
package org.eclipse.uml2.diagram.csd.edit.policies;
import java.util.Iterator;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.uml2.diagram.csd.edit.commands.AssociationCreateCommand;
import org.eclipse.uml2.diagram.csd.edit.commands.AssociationReorientCommand;
import org.eclipse.uml2.diagram.csd.edit.commands.ConstraintConstrainedElementCreateCommand;
import org.eclipse.uml2.diagram.csd.edit.commands.ConstraintConstrainedElementReorientCommand;
import org.eclipse.uml2.diagram.csd.edit.commands.DependencyCreateCommand;
import org.eclipse.uml2.diagram.csd.edit.commands.DependencyReorientCommand;
import org.eclipse.uml2.diagram.csd.edit.commands.InterfaceRealizationCreateCommand;
import org.eclipse.uml2.diagram.csd.edit.commands.InterfaceRealizationReorientCommand;
import org.eclipse.uml2.diagram.csd.edit.commands.Port3CreateCommand;
import org.eclipse.uml2.diagram.csd.edit.commands.UsageCreateCommand;
import org.eclipse.uml2.diagram.csd.edit.commands.UsageReorientCommand;
import org.eclipse.uml2.diagram.csd.edit.parts.AssociationEditPart;
import org.eclipse.uml2.diagram.csd.edit.parts.ClassClass_contentsEditPart;
import org.eclipse.uml2.diagram.csd.edit.parts.ConstraintConstrainedElementEditPart;
import org.eclipse.uml2.diagram.csd.edit.parts.DependencyEditPart;
import org.eclipse.uml2.diagram.csd.edit.parts.InterfaceRealizationEditPart;
import org.eclipse.uml2.diagram.csd.edit.parts.Port3EditPart;
import org.eclipse.uml2.diagram.csd.edit.parts.Property3EditPart;
import org.eclipse.uml2.diagram.csd.edit.parts.UsageEditPart;
import org.eclipse.uml2.diagram.csd.part.UMLVisualIDRegistry;
import org.eclipse.uml2.diagram.csd.providers.UMLElementTypes;
import org.eclipse.uml2.uml.UMLPackage;
/**
* @generated
*/
public class Class3ItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy {
/**
* @generated
*/
protected Command getCreateCommand(CreateElementRequest req) {
if (UMLElementTypes.Port_3017 == req.getElementType()) {
if (req.getContainmentFeature() == null) {
req.setContainmentFeature(UMLPackage.eINSTANCE.getStructuredClassifier_OwnedAttribute());
}
return getGEFWrapper(new Port3CreateCommand(req));
}
return super.getCreateCommand(req);
}
/**
* @generated
*/
protected Command getDestroyElementCommand(DestroyElementRequest req) {
CompoundCommand cc = getDestroyEdgesCommand();
addDestroyChildNodesCommand(cc);
addDestroyShortcutsCommand(cc);
View view = (View) getHost().getModel();
if (view.getEAnnotation("Shortcut") != null) { //$NON-NLS-1$
req.setElementToDestroy(view);
}
cc.add(getGEFWrapper(new DestroyElementCommand(req)));
return cc.unwrap();
}
/**
* @generated
*/
protected void addDestroyChildNodesCommand(CompoundCommand cmd) {
View view = (View) getHost().getModel();
EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
if (annotation != null) {
return;
}
for (Iterator it = view.getChildren().iterator(); it.hasNext();) {
Node node = (Node) it.next();
switch (UMLVisualIDRegistry.getVisualID(node)) {
case Port3EditPart.VISUAL_ID:
cmd.add(getDestroyElementCommand(node));
break;
case ClassClass_contentsEditPart.VISUAL_ID:
for (Iterator cit = node.getChildren().iterator(); cit.hasNext();) {
Node cnode = (Node) cit.next();
switch (UMLVisualIDRegistry.getVisualID(cnode)) {
case Property3EditPart.VISUAL_ID:
cmd.add(getDestroyElementCommand(cnode));
break;
}
}
break;
}
}
}
/**
* @generated
*/
protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
Command command = req.getTarget() == null ? getStartCreateRelationshipCommand(req) : getCompleteCreateRelationshipCommand(req);
return command != null ? command : super.getCreateRelationshipCommand(req);
}
/**
* @generated
*/
protected Command getStartCreateRelationshipCommand(CreateRelationshipRequest req) {
if (UMLElementTypes.Dependency_4006 == req.getElementType()) {
return getGEFWrapper(new DependencyCreateCommand(req, req.getSource(), req.getTarget()));
}
if (UMLElementTypes.InterfaceRealization_4007 == req.getElementType()) {
return getGEFWrapper(new InterfaceRealizationCreateCommand(req, req.getSource(), req.getTarget()));
}
if (UMLElementTypes.Usage_4008 == req.getElementType()) {
return getGEFWrapper(new UsageCreateCommand(req, req.getSource(), req.getTarget()));
}
if (UMLElementTypes.Association_4011 == req.getElementType()) {
return getGEFWrapper(new AssociationCreateCommand(req, req.getSource(), req.getTarget()));
}
if (UMLElementTypes.ConstraintConstrainedElement_4012 == req.getElementType()) {
return null;
}
return null;
}
/**
* @generated
*/
protected Command getCompleteCreateRelationshipCommand(CreateRelationshipRequest req) {
if (UMLElementTypes.Dependency_4006 == req.getElementType()) {
return getGEFWrapper(new DependencyCreateCommand(req, req.getSource(), req.getTarget()));
}
if (UMLElementTypes.InterfaceRealization_4007 == req.getElementType()) {
return null;
}
if (UMLElementTypes.Usage_4008 == req.getElementType()) {
return getGEFWrapper(new UsageCreateCommand(req, req.getSource(), req.getTarget()));
}
if (UMLElementTypes.Association_4011 == req.getElementType()) {
return getGEFWrapper(new AssociationCreateCommand(req, req.getSource(), req.getTarget()));
}
if (UMLElementTypes.ConstraintConstrainedElement_4012 == req.getElementType()) {
return getGEFWrapper(new ConstraintConstrainedElementCreateCommand(req, req.getSource(), req.getTarget()));
}
return null;
}
/**
* Returns command to reorient EClass based link. New link target or source
* should be the domain model element associated with this node.
*
* @generated
*/
protected Command getReorientRelationshipCommand(ReorientRelationshipRequest req) {
switch (getVisualID(req)) {
case DependencyEditPart.VISUAL_ID:
return getGEFWrapper(new DependencyReorientCommand(req));
case InterfaceRealizationEditPart.VISUAL_ID:
return getGEFWrapper(new InterfaceRealizationReorientCommand(req));
case UsageEditPart.VISUAL_ID:
return getGEFWrapper(new UsageReorientCommand(req));
case AssociationEditPart.VISUAL_ID:
return getGEFWrapper(new AssociationReorientCommand(req));
}
return super.getReorientRelationshipCommand(req);
}
/**
* Returns command to reorient EReference based link. New link target or source
* should be the domain model element associated with this node.
*
* @generated
*/
protected Command getReorientReferenceRelationshipCommand(ReorientReferenceRelationshipRequest req) {
switch (getVisualID(req)) {
case ConstraintConstrainedElementEditPart.VISUAL_ID:
return getGEFWrapper(new ConstraintConstrainedElementReorientCommand(req));
}
return super.getReorientReferenceRelationshipCommand(req);
}
}