/***************************************************************************** * Copyright (c) 2010-2011 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: * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation * *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies; 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.emf.type.core.requests.CreateRelationshipRequest; import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; import org.eclipse.papyrus.uml.diagram.composite.custom.edit.command.ConnectorCreateCommand; import org.eclipse.papyrus.uml.diagram.composite.edit.commands.RoleBindingCreateCommand; import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorEditPart; import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes; import org.eclipse.papyrus.uml.service.types.utils.RequestParameterConstants; /** * <pre> * This class provides a custom edit policy used to replace the SEMANTIC_ROLE * generated for the Parameter element (when used in CompositeStructure Diagram) * </pre> */ public class ParameterItemSemanticEditPolicy extends org.eclipse.papyrus.uml.diagram.composite.edit.policies.ParameterItemSemanticEditPolicy { /** * <pre> * Calls a custom creation command to allow the creation of a Connector connected to a Parameter * on its source end. * * {@inheritDoc} * </pre> */ @Override protected Command getStartCreateRelationshipCommand(CreateRelationshipRequest req) { if(UMLElementTypes.Connector_4013 == req.getElementType()) { return getGEFWrapper(new ConnectorCreateCommand(req, req.getSource(), req.getTarget())); } if(UMLElementTypes.Dependency_4017 == req.getElementType()) { return getGEFWrapper(new RoleBindingCreateCommand(req, req.getSource(), req.getTarget())); } return super.getStartCreateRelationshipCommand(req); } /** * <pre> * Calls a custom creation command to allow the creation of a Connector connected to a Parameter * on its target end. * * {@inheritDoc} * </pre> */ @Override protected Command getCompleteCreateRelationshipCommand(CreateRelationshipRequest req) { if(UMLElementTypes.Connector_4013 == req.getElementType()) { return getGEFWrapper(new ConnectorCreateCommand(req, req.getSource(), req.getTarget())); } if(UMLElementTypes.Dependency_4017 == req.getElementType()) { return getGEFWrapper(new RoleBindingCreateCommand(req, req.getSource(), req.getTarget())); } return super.getCompleteCreateRelationshipCommand(req); } @Override protected Command getReorientRelationshipCommand(ReorientRelationshipRequest req) { switch(getVisualID(req)) { case ConnectorEditPart.VISUAL_ID: IElementEditService provider = ElementEditServiceUtils.getCommandProvider(req.getRelationship()); if(provider == null) { return UnexecutableCommand.INSTANCE; } // Add graphical new end View in request parameters View targetView = (View)getHost().getModel(); req.setParameter(RequestParameterConstants.EDGE_REORIENT_REQUEST_END_VIEW, targetView); // Retrieve re-orient command from the Element Edit service ICommand reorientCommand = provider.getEditCommand(req); if(reorientCommand == null) { return UnexecutableCommand.INSTANCE; } return getGEFWrapper(reorientCommand.reduce()); } return super.getReorientRelationshipCommand(req); } }