package es.tid.cim.diagram.edit.commands;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.resource.Resource;
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 es.tid.cim.CIM_Model;
import es.tid.cim.CimFactory;
import es.tid.cim.ServiceAccessURI;
/**
* @generated
*/
public class ServiceAccessURICreateCommand extends CreateElementCommand {
/**
* @generated
*/
public ServiceAccessURICreateCommand(CreateElementRequest req) {
super(req);
}
/**
* @generated
*/
protected EObject getElementToEdit() {
EObject container = ((CreateElementRequest) getRequest())
.getContainer();
if (container instanceof View) {
container = ((View) container).getElement();
}
return container;
}
/**
* @generated
*/
public boolean canExecute() {
if (getEClass() != null) {
return getEClass().isSuperTypeOf(getEClassToEdit());
}
return true;
}
/**
* @generated
*/
protected EReference getContainmentFeature() {
return null;
}
/**
* @generated
*/
protected EObject doDefaultElementCreation() {
// Uncomment to put "phantom" objects into the diagram file.
// org.eclipse.emf.ecore.resource.Resource resource =
// ((org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest) getRequest()).getContainer().eResource();
// if (resource == null) {
// return null;
// }
Resource resource = getElementToEdit().eResource();
ServiceAccessURI newElement = CimFactory.eINSTANCE
.createServiceAccessURI();
//resource.getContents().add(newElement);
((CIM_Model) getElementToEdit()).getElements().add(newElement);
return newElement;
}
}