001: /**
002: *
003: */package newprocess.diagram.cust.operation;
004:
005: import java.util.Iterator;
006: import java.util.List;
007:
008: import newprocess.diagram.edit.parts.AsyncActivityAsyncActivityPostconditionCompartmentEditPart;
009: import newprocess.diagram.edit.parts.AsyncActivityAsyncActivityPreconditionCompartmentEditPart;
010: import newprocess.diagram.edit.parts.AsyncActivityEditPart;
011: import newprocess.diagram.edit.parts.ConditionTermEditPart;
012: import newprocess.diagram.edit.parts.Expression4EditPart;
013: import newprocess.diagram.edit.parts.Expression5EditPart;
014:
015: import org.eclipse.emf.transaction.TransactionalEditingDomain;
016: import org.eclipse.gef.EditPart;
017: import org.eclipse.gef.RequestConstants;
018: import org.eclipse.gef.commands.Command;
019: import org.eclipse.gef.commands.CommandStack;
020: import org.eclipse.gef.requests.GroupRequest;
021: import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
022: import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper;
023: import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
024:
025: /**
026: * @author sh
027: *
028: */
029: public class AsyncActivityDeleteOperation {
030: /**
031: * Delete all terms, if possible
032: * @param host
033: * @author sh
034: */
035: public void doExecute(EditPart host) {
036: // exit if the host is not an AsyncActivity
037: if (host instanceof AsyncActivityEditPart == false)
038: return;
039:
040: List childs = host.getChildren();
041: for (Iterator iterator = childs.iterator(); iterator.hasNext();) {
042: EditPart childEP = (EditPart) iterator.next();
043: // deleting the terms of the precondition
044: if (childEP instanceof AsyncActivityAsyncActivityPreconditionCompartmentEditPart) {
045: AsyncActivityAsyncActivityPreconditionCompartmentEditPart preEP = (AsyncActivityAsyncActivityPreconditionCompartmentEditPart) childEP;
046: List exprEP = preEP.getChildren();
047: for (Iterator iterator2 = exprEP.iterator(); iterator2
048: .hasNext();) {
049: EditPart exprChildEP = (EditPart) iterator2.next();
050: if (exprChildEP instanceof Expression4EditPart) {
051: Expression4EditPart expr4EP = (Expression4EditPart) exprChildEP;
052: List termsEP = expr4EP.getChildren();
053: for (Iterator iterator3 = termsEP.iterator(); iterator3
054: .hasNext();) {
055: EditPart termsChildEP = (EditPart) iterator3
056: .next();
057: if (termsChildEP instanceof ConditionTermEditPart)
058: deleteTerms(termsChildEP, host);
059: }
060: }
061: }
062: }
063:
064: // deleting the terms of the postconditon
065: if (childEP instanceof AsyncActivityAsyncActivityPostconditionCompartmentEditPart) {
066: AsyncActivityAsyncActivityPostconditionCompartmentEditPart postEP = (AsyncActivityAsyncActivityPostconditionCompartmentEditPart) childEP;
067: List exprEP = postEP.getChildren();
068: for (Iterator iterator2 = exprEP.iterator(); iterator2
069: .hasNext();) {
070: EditPart exprChildEP = (EditPart) iterator2.next();
071: if (exprChildEP instanceof Expression5EditPart) {
072: Expression5EditPart expr4EP = (Expression5EditPart) exprChildEP;
073: List termsEP = expr4EP.getChildren();
074: for (Iterator iterator3 = termsEP.iterator(); iterator3
075: .hasNext();) {
076: EditPart termsChildEP = (EditPart) iterator3
077: .next();
078: if (termsChildEP instanceof ConditionTermEditPart)
079: deleteTerms(termsChildEP, host);
080: }
081: }
082: }
083: }
084: }
085: }
086:
087: private void deleteTerms(EditPart termEP, EditPart host) {
088: // create the request, fetch the command and execute it
089: GroupRequest req = new GroupRequest(RequestConstants.REQ_DELETE);
090: req.setEditParts(termEP);
091: TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) host)
092: .getEditingDomain();
093: EditCommandRequestWrapper semReq = new EditCommandRequestWrapper(
094: new DestroyElementRequest(editingDomain, false), req
095: .getExtendedData());
096: Command command = termEP.getCommand(semReq);
097: if (command != null && command.canExecute()) {
098: CommandStack stack = host.getViewer().getEditDomain()
099: .getCommandStack();
100: stack.execute(command);
101: }
102: }
103: }
|