blob: 598b9dd1c1dc0f7205724f85cc7aa6f6d71acf05 [file] [log] [blame]
//------------------------------------------------------------------------------
// Copyright (c) 2005, 2007 IBM 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:
// IBM Corporation - initial implementation
//------------------------------------------------------------------------------
/**
*
*/
package org.eclipse.epf.diagramming.base.commands;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.gmf.runtime.emf.core.util.PackageUtil;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
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.View;
import org.eclipse.uml2.uml.ActivityNode;
import org.eclipse.uml2.uml.ActivityPartition;
import org.eclipse.uml2.uml.UMLPackage;
/**
* @author Shashidhar Kannoori
*
*/
public class CreateActivityNodeInActivityPartition extends CreateElementCommand {
/**
* @param request
*/
public CreateActivityNodeInActivityPartition(CreateElementRequest request) {
super(request);
// TODO Auto-generated constructor stub
}
/**
*
*/
protected EClass getEClassToEdit() {
return UMLPackage.eINSTANCE.getActivity();
};
/**
* @modified
*/
protected EObject getElementToEdit() {
EObject container = ((CreateElementRequest) getRequest())
.getContainer();
if (container instanceof View) {
container = ((View) container).getElement();
}
if(container instanceof ActivityPartition){
container = container.eContainer();
}
return container;
}
public boolean canExecute() {
return super.canExecute();
}
/**
* (non-Javadoc)
* @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
* @modified
*/
protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
IStatus status = null;
status = super.doExecute(monitor, info);
EObject newElement = getNewElement();
if (newElement instanceof ActivityNode)
{
EObject obj = getOriginalContainer();
if (obj instanceof ActivityPartition) {
// set inpartition
((ActivityNode) newElement).getInPartitions().add(obj);
}
}
return status;
}
/**
* @custom
*/
private EObject getOriginalContainer()
{
return ((CreateElementRequest) getRequest()).getContainer();
}
/**
* Gets the containment feature for the new element.
*
* @return the containment feature
* @modified
*/
protected EReference getContainmentFeature() {
/**
* The containment feature in which the new element will be created.
*/
EReference containmentFeature=null;
if (containmentFeature == null) {
EClass classToEdit = getEClassToEdit();
if (classToEdit != null) {
IElementType type = getElementType();
if (type != null && type.getEClass() != null) {
containmentFeature = PackageUtil.findFeature(classToEdit,
type.getEClass());
}
}
}
return containmentFeature;
}
}