01: /**
02: *
03: */package diagram.commands;
04:
05: import org.eclipse.emf.ecore.EObject;
06: import org.eclipse.emf.transaction.TransactionalEditingDomain;
07: import org.eclipse.gef.EditPart;
08: import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
09: import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
10: import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
11: import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditDomain;
12: import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
13: import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
14:
15: /**
16: * Deletes an EMF EnvEntry model Object.
17: *
18: * @author sh
19: */
20: public class DeleteCommand {
21:
22: /**
23: * Deletes a model element.
24: *
25: * @param editPart the EditPart to destroy
26: * @param elementToDestroy the model object to destroy
27: */
28: public void executeRemoveCommand(EditPart editPart,
29: EObject elementToDestroy) {
30: TransactionalEditingDomain writeEditingDomain = null;
31: IDiagramEditDomain diagramEditDomain = null;
32:
33: if (editPart instanceof DiagramEditPart) {
34: diagramEditDomain = ((DiagramEditPart) editPart)
35: .getDiagramEditDomain();
36: writeEditingDomain = ((DiagramEditPart) editPart)
37: .getEditingDomain();
38: }
39: if (editPart instanceof ShapeNodeEditPart) {
40: diagramEditDomain = ((ShapeNodeEditPart) editPart)
41: .getDiagramEditDomain();
42: writeEditingDomain = ((ShapeNodeEditPart) editPart)
43: .getEditingDomain();
44: }
45:
46: DestroyElementRequest desReq = new DestroyElementRequest(
47: writeEditingDomain, elementToDestroy, false);
48: DestroyElementCommand desCom = new DestroyElementCommand(desReq);
49: ICommandProxy proxy = new ICommandProxy(desCom);
50: diagramEditDomain.getDiagramCommandStack().execute(proxy);
51: }
52: }
|