blob: baebd939db962ea35e66cf300478b35fee8c51ba [file] [log] [blame]
/**
*
*/
package org.eclipse.epf.diagramming.base.commands;
import java.util.Collection;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.FeatureMapUtil;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.uml2.uml.Activity;
import org.eclipse.uml2.uml.UMLPackage;
/**
* @author Shashidhar Kannoori
*
*/
public class UpdateActivityCommand extends EditElementCommand {
public UpdateActivityCommand(CreateElementRequest req) {
super(req.getLabel(), req.getContainer(), req);
}
/**
* @param label
* @param elementToEdit
* @param request
*/
public UpdateActivityCommand(String label, EObject elementToEdit,
CreateElementRequest request) {
super(label, elementToEdit, request);
}
/* (non-Javadoc)
* @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
*/
protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
IAdaptable info) throws ExecutionException {
CreateElementRequest req = (CreateElementRequest)getRequest();
EObject value = req.getNewElement();
EStructuralFeature feature = UMLPackage.eINSTANCE.getActivity_Node();
if (FeatureMapUtil.isMany(getElementToEdit(), feature)) {
((Collection) getElementToEdit().eGet(feature)).add(value);
} else {
getElementToEdit().eSet(feature, value);
}
return CommandResult.newOKCommandResult();
}
public boolean canExecute() {
// TODO Auto-generated method stub
//return super.canExecute();
return true;
}
protected EObject getElementToEdit() {
// TODO Auto-generated method stub
//return super.getElementToEdit();
CreateElementRequest req = (CreateElementRequest)getRequest();
EObject obj = req.getContainer();
EObject parent = obj.eContainer();
while(!(parent instanceof Activity)){
parent = parent.eContainer();
}
return parent;
}
}