01: package newprocess.diagram.cust.operation;
02:
03: import java.util.Iterator;
04: import java.util.List;
05:
06: import newprocess.diagram.edit.parts.ConditionTermEditPart;
07: import newprocess.diagram.edit.parts.EventEditPart;
08: import newprocess.diagram.edit.parts.EventEventPostconditionCompartmentEditPart;
09: import newprocess.diagram.edit.parts.Expression6EditPart;
10:
11: import org.eclipse.emf.transaction.TransactionalEditingDomain;
12: import org.eclipse.gef.EditPart;
13: import org.eclipse.gef.RequestConstants;
14: import org.eclipse.gef.commands.Command;
15: import org.eclipse.gef.commands.CommandStack;
16: import org.eclipse.gef.requests.GroupRequest;
17: import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
18: import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper;
19: import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
20:
21: /**
22: * @author sh
23: *
24: */
25: public class EventDeleteOperation {
26: /**
27: * Delete all terms, if possible
28: * @param host
29: * @author sh
30: */
31: public void doExecute(EditPart host) {
32: // exit if the host is not an Event
33: if (host instanceof EventEditPart == false)
34: return;
35:
36: List childs = host.getChildren();
37: for (Iterator iterator = childs.iterator(); iterator.hasNext();) {
38: EditPart childEP = (EditPart) iterator.next();
39: // deleting the terms of the postcondition
40: if (childEP instanceof EventEventPostconditionCompartmentEditPart) {
41: EventEventPostconditionCompartmentEditPart postEP = (EventEventPostconditionCompartmentEditPart) childEP;
42: List exprEP = postEP.getChildren();
43: for (Iterator iterator2 = exprEP.iterator(); iterator2
44: .hasNext();) {
45: EditPart exprChildEP = (EditPart) iterator2.next();
46: if (exprChildEP instanceof Expression6EditPart) {
47: Expression6EditPart expr4EP = (Expression6EditPart) exprChildEP;
48: List termsEP = expr4EP.getChildren();
49: for (Iterator iterator3 = termsEP.iterator(); iterator3
50: .hasNext();) {
51: EditPart termsChildEP = (EditPart) iterator3
52: .next();
53: if (termsChildEP instanceof ConditionTermEditPart)
54: deleteTerms(termsChildEP, host);
55: }
56: }
57: }
58: }
59: }
60: }
61:
62: private void deleteTerms(EditPart termEP, EditPart host) {
63: // create the request, fetch the command and execute it
64: GroupRequest req = new GroupRequest(RequestConstants.REQ_DELETE);
65: req.setEditParts(termEP);
66: TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) host)
67: .getEditingDomain();
68: EditCommandRequestWrapper semReq = new EditCommandRequestWrapper(
69: new DestroyElementRequest(editingDomain, false), req
70: .getExtendedData());
71: Command command = termEP.getCommand(semReq);
72: if (command != null && command.canExecute()) {
73: CommandStack stack = host.getViewer().getEditDomain()
74: .getCommandStack();
75: stack.execute(command);
76: }
77: }
78: }
|