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