01: package newprocess.diagram.cust.operation;
02:
03: import java.util.Iterator;
04: import java.util.List;
05:
06: import newprocess.diagram.edit.parts.AndOperatorEditPart;
07: import newprocess.diagram.edit.parts.ConditionTermEditPart;
08: import newprocess.diagram.edit.parts.OperatorTermSubTermEditPart;
09: import newprocess.diagram.edit.parts.OrOperatorEditPart;
10:
11: import org.eclipse.emf.transaction.TransactionalEditingDomain;
12: import org.eclipse.gef.EditPart;
13: import org.eclipse.gef.commands.Command;
14: import org.eclipse.gef.commands.CommandStack;
15: import org.eclipse.gef.requests.GroupRequest;
16: import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
17: import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper;
18: import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
19: import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
20:
21: /**
22: * This class is responsible for deleting the Operator and all linked terms
23: * @author sh
24: */
25: public class OperatorTermChainDeleteOperation {
26: /**
27: *
28: * @param host
29: */
30: public void doExecute(EditPart host) {
31:
32: // fetch all outgoing connections to the term
33: // an operator has a single incoming an multible outgoing links
34: // exit if the host is not a Operator
35: List<OperatorTermSubTermEditPart> sources = null;
36: if (host instanceof OrOperatorEditPart) {
37: sources = ((OrOperatorEditPart) host)
38: .getSourceConnections();
39: } else if (host instanceof AndOperatorEditPart) {
40: sources = ((AndOperatorEditPart) host)
41: .getSourceConnections();
42: } else
43: return;
44:
45: if (sources == null || sources.isEmpty())
46: return;
47:
48: Iterator<OperatorTermSubTermEditPart> it = sources.iterator();
49: while (it.hasNext()) {
50: OperatorTermSubTermEditPart subtermEP = it.next();
51:
52: if (subtermEP.getTarget() instanceof ConditionTermEditPart == false)
53: continue;
54: ConditionTermEditPart termEP = (ConditionTermEditPart) subtermEP
55: .getTarget();
56:
57: // create the delet request
58: GroupRequest req = new GroupRequest(
59: RequestConstants.REQ_DELETE);
60: req.setEditParts(termEP);
61:
62: // wrapp the request into a RequestWrapper
63: TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) host)
64: .getEditingDomain();
65: EditCommandRequestWrapper semReq = new EditCommandRequestWrapper(
66: new DestroyElementRequest(editingDomain, false),
67: req.getExtendedData());
68:
69: // fetch the command and execute it
70: Command command = termEP.getCommand(semReq);
71: if (command != null && command.canExecute()) {
72: CommandStack stack = host.getViewer().getEditDomain()
73: .getCommandStack();
74: stack.execute(command);
75: }
76: }
77: }
78: }
|