/***************************************************************************** * Copyright (c) 2012 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: * CEA LIST - Initial API and implementation * *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.usecase.edit.policies; import org.eclipse.emf.ecore.EObject; import org.eclipse.gef.commands.Command; import org.eclipse.gef.commands.UnexecutableCommand; import org.eclipse.gmf.runtime.common.core.command.ICommand; import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; 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.papyrus.infra.services.edit.service.ElementEditServiceUtils; import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; import org.eclipse.papyrus.uml.diagram.usecase.edit.commands.AbstractionCreateCommand; import org.eclipse.papyrus.uml.diagram.usecase.edit.commands.AssociationCreateCommand; import org.eclipse.papyrus.uml.diagram.usecase.edit.commands.AssociationReorientCommand; import org.eclipse.papyrus.uml.diagram.usecase.edit.commands.CommentAnnotatedElementCreateCommand; import org.eclipse.papyrus.uml.diagram.usecase.edit.commands.CommentAnnotatedElementReorientCommand; import org.eclipse.papyrus.uml.diagram.usecase.edit.commands.ConstraintConstrainedElementCreateCommand; import org.eclipse.papyrus.uml.diagram.usecase.edit.commands.ConstraintConstrainedElementReorientCommand; import org.eclipse.papyrus.uml.diagram.usecase.edit.commands.DependencyCreateCommand; import org.eclipse.papyrus.uml.diagram.usecase.edit.commands.GeneralizationCreateCommand; import org.eclipse.papyrus.uml.diagram.usecase.edit.commands.PackageImportCreateCommand; import org.eclipse.papyrus.uml.diagram.usecase.edit.commands.RealizationCreateCommand; import org.eclipse.papyrus.uml.diagram.usecase.edit.commands.UsageCreateCommand; import org.eclipse.papyrus.uml.diagram.usecase.edit.parts.AbstractionEditPart; import org.eclipse.papyrus.uml.diagram.usecase.edit.parts.AssociationEditPart; import org.eclipse.papyrus.uml.diagram.usecase.edit.parts.CommentAnnotatedElementEditPart; import org.eclipse.papyrus.uml.diagram.usecase.edit.parts.ConstraintConstrainedElementEditPart; import org.eclipse.papyrus.uml.diagram.usecase.edit.parts.DependencyEditPart; import org.eclipse.papyrus.uml.diagram.usecase.edit.parts.GeneralizationEditPart; import org.eclipse.papyrus.uml.diagram.usecase.edit.parts.PackageImportEditPart; import org.eclipse.papyrus.uml.diagram.usecase.edit.parts.RealizationEditPart; import org.eclipse.papyrus.uml.diagram.usecase.edit.parts.UsageEditPart; import org.eclipse.papyrus.uml.diagram.usecase.providers.UMLElementTypes; /** * @generated */ public class SubjectItemSemanticEditPolicyTN extends UMLBaseItemSemanticEditPolicy { /** * @generated */ public SubjectItemSemanticEditPolicyTN() { super(UMLElementTypes.Classifier_2015); } /** * @generated */ protected Command getDestroyElementCommand(DestroyElementRequest req) { EObject selectedEObject = req.getElementToDestroy(); IElementEditService provider = ElementEditServiceUtils.getCommandProvider(selectedEObject); if(provider != null) { // Retrieve delete command from the Element Edit service ICommand deleteCommand = provider.getEditCommand(req); if(deleteCommand != null) { return new ICommandProxy(deleteCommand); } } return UnexecutableCommand.INSTANCE; } /** * @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.Generalization_4010 == req.getElementType()) { return getGEFWrapper(new GeneralizationCreateCommand(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; } if(UMLElementTypes.Dependency_4013 == req.getElementType()) { return getGEFWrapper(new DependencyCreateCommand(req, req.getSource(), req.getTarget())); } if(UMLElementTypes.CommentAnnotatedElement_4014 == req.getElementType()) { return null; } if(UMLElementTypes.Abstraction_4015 == req.getElementType()) { return getGEFWrapper(new AbstractionCreateCommand(req, req.getSource(), req.getTarget())); } if(UMLElementTypes.Usage_4016 == req.getElementType()) { return getGEFWrapper(new UsageCreateCommand(req, req.getSource(), req.getTarget())); } if(UMLElementTypes.Realization_4017 == req.getElementType()) { return getGEFWrapper(new RealizationCreateCommand(req, req.getSource(), req.getTarget())); } if(UMLElementTypes.PackageImport_4019 == req.getElementType()) { return getGEFWrapper(new PackageImportCreateCommand(req, req.getSource(), req.getTarget())); } return null; } /** * @generated */ protected Command getCompleteCreateRelationshipCommand(CreateRelationshipRequest req) { if(UMLElementTypes.Generalization_4010 == req.getElementType()) { return getGEFWrapper(new GeneralizationCreateCommand(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())); } if(UMLElementTypes.Dependency_4013 == req.getElementType()) { return getGEFWrapper(new DependencyCreateCommand(req, req.getSource(), req.getTarget())); } if(UMLElementTypes.CommentAnnotatedElement_4014 == req.getElementType()) { return getGEFWrapper(new CommentAnnotatedElementCreateCommand(req, req.getSource(), req.getTarget())); } if(UMLElementTypes.Abstraction_4015 == req.getElementType()) { return getGEFWrapper(new AbstractionCreateCommand(req, req.getSource(), req.getTarget())); } if(UMLElementTypes.Usage_4016 == req.getElementType()) { return getGEFWrapper(new UsageCreateCommand(req, req.getSource(), req.getTarget())); } if(UMLElementTypes.Realization_4017 == req.getElementType()) { return getGEFWrapper(new RealizationCreateCommand(req, req.getSource(), req.getTarget())); } if(UMLElementTypes.PackageImport_4019 == req.getElementType()) { return null; } 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 GeneralizationEditPart.VISUAL_ID: case DependencyEditPart.VISUAL_ID: case AbstractionEditPart.VISUAL_ID: case UsageEditPart.VISUAL_ID: case RealizationEditPart.VISUAL_ID: case PackageImportEditPart.VISUAL_ID: IElementEditService provider = ElementEditServiceUtils.getCommandProvider(req.getRelationship()); if(provider == null) { return UnexecutableCommand.INSTANCE; } // Retrieve re-orient command from the Element Edit service ICommand reorientCommand = provider.getEditCommand(req); if(reorientCommand == null) { return UnexecutableCommand.INSTANCE; } return getGEFWrapper(reorientCommand.reduce()); 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)); case CommentAnnotatedElementEditPart.VISUAL_ID: return getGEFWrapper(new CommentAnnotatedElementReorientCommand(req)); } return super.getReorientReferenceRelationshipCommand(req); } }