package org.eclipse.gmf.examples.eclipsecon.library.diagram.edit.policies;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gmf.examples.eclipsecon.library.diagram.edit.parts.AuthorEditPart;
import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper;
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.gmf.runtime.notation.View;
/**
* @generated
*/
public class AuthorItemSemanticEditPolicy extends
Library07BaseItemSemanticEditPolicy {
/**
* @generated
*/
protected Command getDestroyElementCommand(DestroyElementRequest req) {
CompoundCommand cc = new CompoundCommand();
Collection allEdges = new ArrayList();
View view = (View) getHost().getModel();
allEdges.addAll(view.getSourceEdges());
allEdges.addAll(view.getTargetEdges());
for (Iterator it = allEdges.iterator(); it.hasNext();) {
Edge nextEdge = (Edge) it.next();
EditPart nextEditPart = (EditPart) getHost().getViewer()
.getEditPartRegistry().get(nextEdge);
EditCommandRequestWrapper editCommandRequest = new EditCommandRequestWrapper(
new DestroyElementRequest(((AuthorEditPart) getHost())
.getEditingDomain(), req.isConfirmationRequired()),
Collections.EMPTY_MAP);
cc.add(nextEditPart.getCommand(editCommandRequest));
}
cc.add(getMSLWrapper(new DestroyElementCommand(req) {
protected EObject getElementToDestroy() {
View view = (View) getHost().getModel();
EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
if (annotation != null) {
return view;
}
return super.getElementToDestroy();
}
}));
return cc;
}
}