01: package newprocess.diagram.cust.operation;
02:
03: import java.util.Iterator;
04: import java.util.List;
05:
06: import newprocess.diagram.edit.parts.ConditionProxyEditPart;
07: import newprocess.diagram.edit.parts.ConditionTermEditPart;
08:
09: import org.eclipse.emf.transaction.TransactionalEditingDomain;
10: import org.eclipse.gef.EditPart;
11: import org.eclipse.gef.commands.Command;
12: import org.eclipse.gef.commands.CommandStack;
13: import org.eclipse.gef.requests.GroupRequest;
14: import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
15: import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
16: import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper;
17: import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
18: import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
19:
20: /**
21: * This class is responsible for deleting the Proxy and all linked terms
22: * @author sh
23: */
24: public class ConditionProxyChainDeleteOperation {
25:
26: /**
27: * Delete a chain, if possible
28: * @param host
29: * @author sh
30: */
31: public void doExecute(EditPart host) {
32: // exit if the host is not a Proxy
33: if (host instanceof ConditionProxyEditPart == false)
34: return;
35:
36: // fetch all incoming connections to the proxy
37: ConditionProxyEditPart proxyEP = (ConditionProxyEditPart) host;
38: List<ConnectionNodeEditPart> targets = proxyEP
39: .getTargetConnections();
40: if (targets == null || targets.isEmpty())
41: return;
42:
43: // delete link by deleting their terms.
44: Iterator<ConnectionNodeEditPart> it = targets.iterator();
45: while (it.hasNext()) {
46:
47: // get the next term of actual link
48: EditPart part = it.next().getSource();
49: if (part instanceof ConditionTermEditPart) {
50: ConditionTermEditPart portEP = (ConditionTermEditPart) part;
51:
52: // create the request, fetch the command and execute it
53: GroupRequest req = new GroupRequest(
54: RequestConstants.REQ_DELETE);
55: req.setEditParts(portEP);
56: TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) host)
57: .getEditingDomain();
58: EditCommandRequestWrapper semReq = new EditCommandRequestWrapper(
59: new DestroyElementRequest(editingDomain, false),
60: req.getExtendedData());
61: Command command = portEP.getCommand(semReq);
62: if (command != null && command.canExecute()) {
63: CommandStack stack = host.getViewer()
64: .getEditDomain().getCommandStack();
65: stack.execute(command);
66: }
67: }
68: }
69: }
70: }
|