package org.eclipse.uml2.diagram.timing.edit.policies;
import java.util.Iterator;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.uml2.diagram.timing.edit.commands.DBlockCreateCommand;
import org.eclipse.uml2.diagram.timing.edit.parts.DBlockEditPart;
import org.eclipse.uml2.diagram.timing.model.timingd.TimingDPackage;
import org.eclipse.uml2.diagram.timing.part.TimingDVisualIDRegistry;
import org.eclipse.uml2.diagram.timing.providers.TimingDElementTypes;
/**
* @generated
*/
public class DFrameItemSemanticEditPolicy extends TimingDBaseItemSemanticEditPolicy {
/**
* @generated
*/
public DFrameItemSemanticEditPolicy() {
super(TimingDElementTypes.DFrame_2001);
}
/**
* @generated
*/
protected Command getCreateCommand(CreateElementRequest req) {
if (TimingDElementTypes.DBlock_3001 == req.getElementType()) {
if (req.getContainmentFeature() == null) {
req.setContainmentFeature(TimingDPackage.eINSTANCE.getDFrame_Blocks());
}
return getGEFWrapper(new DBlockCreateCommand(req));
}
return super.getCreateCommand(req);
}
/**
* @generated
*/
protected Command getDestroyElementCommand(DestroyElementRequest req) {
CompoundCommand cc = getDestroyEdgesCommand();
addDestroyChildNodesCommand(cc);
addDestroyShortcutsCommand(cc);
View view = (View) getHost().getModel();
if (view.getEAnnotation("Shortcut") != null) { //$NON-NLS-1$
req.setElementToDestroy(view);
}
cc.add(getGEFWrapper(new DestroyElementCommand(req)));
return cc.unwrap();
}
/**
* @generated
*/
protected void addDestroyChildNodesCommand(CompoundCommand cmd) {
View view = (View) getHost().getModel();
EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
if (annotation != null) {
return;
}
for (Iterator it = view.getChildren().iterator(); it.hasNext();) {
Node node = (Node) it.next();
switch (TimingDVisualIDRegistry.getVisualID(node)) {
case DBlockEditPart.VISUAL_ID:
cmd.add(getDestroyElementCommand(node));
break;
}
}
}
}