/***************************************************************************** * Copyright (c) 2009 Atos Origin. * * * 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: * Atos Origin - Initial API and implementation * *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.activity.edit.policies; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.gef.commands.Command; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.emf.type.core.IElementType; import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest; import org.eclipse.gmf.runtime.emf.type.core.requests.DuplicateElementsRequest; import org.eclipse.gmf.runtime.notation.Diagram; import org.eclipse.papyrus.infra.extendedtypes.types.IExtendedHintedElementType; import org.eclipse.papyrus.infra.extendedtypes.util.ElementTypeUtils; import org.eclipse.papyrus.uml.diagram.activity.edit.commands.ActivityCreateCommand; import org.eclipse.papyrus.uml.diagram.activity.providers.UMLElementTypes; import org.eclipse.papyrus.uml.diagram.common.commands.DuplicateNamedElementCommand; /** * @generated */ public class ActivityDiagramItemSemanticEditPolicy extends UMLBaseItemSemanticEditPolicy { /** * @generated */ public ActivityDiagramItemSemanticEditPolicy() { super(UMLElementTypes.Package_1000); } /** * @generated */ protected Command getCreateCommand(CreateElementRequest req) { IElementType requestElementType = req.getElementType(); if(requestElementType == null) { return super.getCreateCommand(req); } IElementType baseElementType = requestElementType; boolean isExtendedType = false; if(requestElementType instanceof IExtendedHintedElementType) { baseElementType = ElementTypeUtils.getClosestDiagramType(requestElementType); if(baseElementType != null) { isExtendedType = true; } else { // no reference element type ID. using the closest super element type to give more opportunities, but can lead to bugs. baseElementType = ElementTypeUtils.findClosestNonExtendedElementType((IExtendedHintedElementType)requestElementType); isExtendedType = true; } } if(UMLElementTypes.Activity_2001 == baseElementType) { if(isExtendedType) { return getExtendedTypeCreationCommand(req, (IExtendedHintedElementType)requestElementType); } return getGEFWrapper(new ActivityCreateCommand(req)); } return super.getCreateCommand(req); } /** * @generated */ protected Command getDuplicateCommand(DuplicateElementsRequest req) { TransactionalEditingDomain editingDomain = ((IGraphicalEditPart)getHost()).getEditingDomain(); Diagram currentDiagram = null; if(getHost() instanceof IGraphicalEditPart) { currentDiagram = ((IGraphicalEditPart)getHost()).getNotationView().getDiagram(); } return getGEFWrapper(new DuplicateAnythingCommand(editingDomain, req, currentDiagram)); } /** * @generated */ private static class DuplicateAnythingCommand extends DuplicateNamedElementCommand { private Diagram diagram; /** * @generated */ public DuplicateAnythingCommand(TransactionalEditingDomain editingDomain, DuplicateElementsRequest req, Diagram currentDiagram) { super(editingDomain, req.getLabel(), req.getElementsToBeDuplicated(), req.getAllDuplicatedElementsMap(), currentDiagram); this.diagram = currentDiagram; } } }