| 1 | /* |
| 2 | * Copyright 2007, SDQ, IPD, University of Karlsruhe |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcm.gmf.usage.edit.policies; |
| 5 | |
| 6 | import java.util.Iterator; |
| 7 | |
| 8 | import org.eclipse.emf.ecore.EAnnotation; |
| 9 | import org.eclipse.gef.commands.Command; |
| 10 | import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand; |
| 11 | import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand; |
| 12 | import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand; |
| 13 | import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyReferenceCommand; |
| 14 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; |
| 15 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; |
| 16 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest; |
| 17 | import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest; |
| 18 | import org.eclipse.gmf.runtime.notation.Edge; |
| 19 | import org.eclipse.gmf.runtime.notation.View; |
| 20 | |
| 21 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.commands.AbstractUserActionSuccessorCreateCommand; |
| 22 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.commands.AbstractUserActionSuccessorReorientCommand; |
| 23 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.AbstractUserActionSuccessorEditPart; |
| 24 | import de.uka.ipd.sdq.pcm.gmf.usage.part.PalladioComponentModelVisualIDRegistry; |
| 25 | import de.uka.ipd.sdq.pcm.gmf.usage.providers.PalladioComponentModelElementTypes; |
| 26 | |
| 27 | /** |
| 28 | * @generated |
| 29 | */ |
| 30 | public class StopItemSemanticEditPolicy extends |
| 31 | PalladioComponentModelBaseItemSemanticEditPolicy { |
| 32 | |
| 33 | /** |
| 34 | * @generated |
| 35 | */ |
| 36 | public StopItemSemanticEditPolicy() { |
| 37 | super(PalladioComponentModelElementTypes.Stop_3002); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @generated |
| 42 | */ |
| 43 | protected Command getDestroyElementCommand(DestroyElementRequest req) { |
| 44 | View view = (View) getHost().getModel(); |
| 45 | CompositeTransactionalCommand cmd = new CompositeTransactionalCommand( |
| 46 | getEditingDomain(), null); |
| 47 | cmd.setTransactionNestingEnabled(false); |
| 48 | for (Iterator it = view.getTargetEdges().iterator(); it.hasNext();) { |
| 49 | Edge incomingLink = (Edge) it.next(); |
| 50 | if (PalladioComponentModelVisualIDRegistry |
| 51 | .getVisualID(incomingLink) == AbstractUserActionSuccessorEditPart.VISUAL_ID) { |
| 52 | DestroyReferenceRequest r = new DestroyReferenceRequest( |
| 53 | incomingLink.getSource().getElement(), null, |
| 54 | incomingLink.getTarget().getElement(), false); |
| 55 | cmd.add(new DestroyReferenceCommand(r)); |
| 56 | cmd.add(new DeleteCommand(getEditingDomain(), incomingLink)); |
| 57 | continue; |
| 58 | } |
| 59 | } |
| 60 | for (Iterator it = view.getSourceEdges().iterator(); it.hasNext();) { |
| 61 | Edge outgoingLink = (Edge) it.next(); |
| 62 | if (PalladioComponentModelVisualIDRegistry |
| 63 | .getVisualID(outgoingLink) == AbstractUserActionSuccessorEditPart.VISUAL_ID) { |
| 64 | DestroyReferenceRequest r = new DestroyReferenceRequest( |
| 65 | outgoingLink.getSource().getElement(), null, |
| 66 | outgoingLink.getTarget().getElement(), false); |
| 67 | cmd.add(new DestroyReferenceCommand(r)); |
| 68 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
| 69 | continue; |
| 70 | } |
| 71 | } |
| 72 | EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$ |
| 73 | if (annotation == null) { |
| 74 | // there are indirectly referenced children, need extra commands: false |
| 75 | addDestroyShortcutsCommand(cmd, view); |
| 76 | // delete host element |
| 77 | cmd.add(new DestroyElementCommand(req)); |
| 78 | } else { |
| 79 | cmd.add(new DeleteCommand(getEditingDomain(), view)); |
| 80 | } |
| 81 | return getGEFWrapper(cmd.reduce()); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * @generated |
| 86 | */ |
| 87 | protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) { |
| 88 | Command command = req.getTarget() == null ? getStartCreateRelationshipCommand(req) |
| 89 | : getCompleteCreateRelationshipCommand(req); |
| 90 | return command != null ? command : super |
| 91 | .getCreateRelationshipCommand(req); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * @generated |
| 96 | */ |
| 97 | protected Command getStartCreateRelationshipCommand( |
| 98 | CreateRelationshipRequest req) { |
| 99 | if (PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002 == req |
| 100 | .getElementType()) { |
| 101 | return getGEFWrapper(new AbstractUserActionSuccessorCreateCommand( |
| 102 | req, req.getSource(), req.getTarget())); |
| 103 | } |
| 104 | return null; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * @generated |
| 109 | */ |
| 110 | protected Command getCompleteCreateRelationshipCommand( |
| 111 | CreateRelationshipRequest req) { |
| 112 | if (PalladioComponentModelElementTypes.AbstractUserActionSuccessor_4002 == req |
| 113 | .getElementType()) { |
| 114 | return getGEFWrapper(new AbstractUserActionSuccessorCreateCommand( |
| 115 | req, req.getSource(), req.getTarget())); |
| 116 | } |
| 117 | return null; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Returns command to reorient EReference based link. New link target or source |
| 122 | * should be the domain model element associated with this node. |
| 123 | * |
| 124 | * @generated |
| 125 | */ |
| 126 | protected Command getReorientReferenceRelationshipCommand( |
| 127 | ReorientReferenceRelationshipRequest req) { |
| 128 | switch (getVisualID(req)) { |
| 129 | case AbstractUserActionSuccessorEditPart.VISUAL_ID: |
| 130 | return getGEFWrapper(new AbstractUserActionSuccessorReorientCommand( |
| 131 | req)); |
| 132 | } |
| 133 | return super.getReorientReferenceRelationshipCommand(req); |
| 134 | } |
| 135 | |
| 136 | } |