| 1 | /* |
| 2 | * Copyright 2006 SDQ Research Group, University of Karlsruhe (TH) |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcm.gmf.seff.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.common.core.command.ICompositeCommand; |
| 11 | import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand; |
| 12 | import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand; |
| 13 | import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand; |
| 14 | import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyReferenceCommand; |
| 15 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; |
| 16 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; |
| 17 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest; |
| 18 | import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest; |
| 19 | import org.eclipse.gmf.runtime.notation.Edge; |
| 20 | import org.eclipse.gmf.runtime.notation.Node; |
| 21 | import org.eclipse.gmf.runtime.notation.View; |
| 22 | |
| 23 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.commands.AbstractActionSuccessor_AbstractActionCreateCommand; |
| 24 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.commands.AbstractActionSuccessor_AbstractActionReorientCommand; |
| 25 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.AbstractActionSuccessor_AbstractActionEditPart; |
| 26 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.ExternalCallActionInputVariableUsage2EditPart; |
| 27 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.ExternalCallActionOutputVariableUsage2EditPart; |
| 28 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.VariableUsage2EditPart; |
| 29 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.VariableUsageEditPart; |
| 30 | import de.uka.ipd.sdq.pcm.gmf.seff.part.PalladioComponentModelVisualIDRegistry; |
| 31 | import de.uka.ipd.sdq.pcm.gmf.seff.providers.PalladioComponentModelElementTypes; |
| 32 | |
| 33 | /** |
| 34 | * @generated |
| 35 | */ |
| 36 | public class ExternalCallAction2ItemSemanticEditPolicy extends |
| 37 | PalladioComponentModelBaseItemSemanticEditPolicy { |
| 38 | |
| 39 | /** |
| 40 | * @generated |
| 41 | */ |
| 42 | public ExternalCallAction2ItemSemanticEditPolicy() { |
| 43 | super(PalladioComponentModelElementTypes.ExternalCallAction_3012); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @generated |
| 48 | */ |
| 49 | protected Command getDestroyElementCommand(DestroyElementRequest req) { |
| 50 | View view = (View) getHost().getModel(); |
| 51 | CompositeTransactionalCommand cmd = new CompositeTransactionalCommand( |
| 52 | getEditingDomain(), null); |
| 53 | cmd.setTransactionNestingEnabled(false); |
| 54 | for (Iterator it = view.getTargetEdges().iterator(); it.hasNext();) { |
| 55 | Edge incomingLink = (Edge) it.next(); |
| 56 | if (PalladioComponentModelVisualIDRegistry |
| 57 | .getVisualID(incomingLink) == AbstractActionSuccessor_AbstractActionEditPart.VISUAL_ID) { |
| 58 | DestroyReferenceRequest r = new DestroyReferenceRequest( |
| 59 | incomingLink.getSource().getElement(), null, |
| 60 | incomingLink.getTarget().getElement(), false); |
| 61 | cmd.add(new DestroyReferenceCommand(r)); |
| 62 | cmd.add(new DeleteCommand(getEditingDomain(), incomingLink)); |
| 63 | continue; |
| 64 | } |
| 65 | } |
| 66 | for (Iterator it = view.getSourceEdges().iterator(); it.hasNext();) { |
| 67 | Edge outgoingLink = (Edge) it.next(); |
| 68 | if (PalladioComponentModelVisualIDRegistry |
| 69 | .getVisualID(outgoingLink) == AbstractActionSuccessor_AbstractActionEditPart.VISUAL_ID) { |
| 70 | DestroyReferenceRequest r = new DestroyReferenceRequest( |
| 71 | outgoingLink.getSource().getElement(), null, |
| 72 | outgoingLink.getTarget().getElement(), false); |
| 73 | cmd.add(new DestroyReferenceCommand(r)); |
| 74 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
| 75 | continue; |
| 76 | } |
| 77 | } |
| 78 | EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$ |
| 79 | if (annotation == null) { |
| 80 | // there are indirectly referenced children, need extra commands: false |
| 81 | addDestroyChildNodesCommand(cmd); |
| 82 | addDestroyShortcutsCommand(cmd, view); |
| 83 | // delete host element |
| 84 | cmd.add(new DestroyElementCommand(req)); |
| 85 | } else { |
| 86 | cmd.add(new DeleteCommand(getEditingDomain(), view)); |
| 87 | } |
| 88 | return getGEFWrapper(cmd.reduce()); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * @generated |
| 93 | */ |
| 94 | private void addDestroyChildNodesCommand(ICompositeCommand cmd) { |
| 95 | View view = (View) getHost().getModel(); |
| 96 | for (Iterator nit = view.getChildren().iterator(); nit.hasNext();) { |
| 97 | Node node = (Node) nit.next(); |
| 98 | switch (PalladioComponentModelVisualIDRegistry.getVisualID(node)) { |
| 99 | case ExternalCallActionInputVariableUsage2EditPart.VISUAL_ID: |
| 100 | for (Iterator cit = node.getChildren().iterator(); cit |
| 101 | .hasNext();) { |
| 102 | Node cnode = (Node) cit.next(); |
| 103 | switch (PalladioComponentModelVisualIDRegistry |
| 104 | .getVisualID(cnode)) { |
| 105 | case VariableUsageEditPart.VISUAL_ID: |
| 106 | cmd.add(new DestroyElementCommand( |
| 107 | new DestroyElementRequest(getEditingDomain(), |
| 108 | cnode.getElement(), false))); // directlyOwned: true |
| 109 | // don't need explicit deletion of cnode as parent's view deletion would clean child views as well |
| 110 | // cmd.add(new org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(), cnode)); |
| 111 | break; |
| 112 | } |
| 113 | } |
| 114 | break; |
| 115 | case ExternalCallActionOutputVariableUsage2EditPart.VISUAL_ID: |
| 116 | for (Iterator cit = node.getChildren().iterator(); cit |
| 117 | .hasNext();) { |
| 118 | Node cnode = (Node) cit.next(); |
| 119 | switch (PalladioComponentModelVisualIDRegistry |
| 120 | .getVisualID(cnode)) { |
| 121 | case VariableUsage2EditPart.VISUAL_ID: |
| 122 | cmd.add(new DestroyElementCommand( |
| 123 | new DestroyElementRequest(getEditingDomain(), |
| 124 | cnode.getElement(), false))); // directlyOwned: true |
| 125 | // don't need explicit deletion of cnode as parent's view deletion would clean child views as well |
| 126 | // cmd.add(new org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(), cnode)); |
| 127 | break; |
| 128 | } |
| 129 | } |
| 130 | break; |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * @generated |
| 137 | */ |
| 138 | protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) { |
| 139 | Command command = req.getTarget() == null ? getStartCreateRelationshipCommand(req) |
| 140 | : getCompleteCreateRelationshipCommand(req); |
| 141 | return command != null ? command : super |
| 142 | .getCreateRelationshipCommand(req); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * @generated |
| 147 | */ |
| 148 | protected Command getStartCreateRelationshipCommand( |
| 149 | CreateRelationshipRequest req) { |
| 150 | if (PalladioComponentModelElementTypes.AbstractActionSuccessor_AbstractAction_4001 == req |
| 151 | .getElementType()) { |
| 152 | return getGEFWrapper(new AbstractActionSuccessor_AbstractActionCreateCommand( |
| 153 | req, req.getSource(), req.getTarget())); |
| 154 | } |
| 155 | return null; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * @generated |
| 160 | */ |
| 161 | protected Command getCompleteCreateRelationshipCommand( |
| 162 | CreateRelationshipRequest req) { |
| 163 | if (PalladioComponentModelElementTypes.AbstractActionSuccessor_AbstractAction_4001 == req |
| 164 | .getElementType()) { |
| 165 | return getGEFWrapper(new AbstractActionSuccessor_AbstractActionCreateCommand( |
| 166 | req, req.getSource(), req.getTarget())); |
| 167 | } |
| 168 | return null; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Returns command to reorient EReference based link. New link target or source |
| 173 | * should be the domain model element associated with this node. |
| 174 | * |
| 175 | * @generated |
| 176 | */ |
| 177 | protected Command getReorientReferenceRelationshipCommand( |
| 178 | ReorientReferenceRelationshipRequest req) { |
| 179 | switch (getVisualID(req)) { |
| 180 | case AbstractActionSuccessor_AbstractActionEditPart.VISUAL_ID: |
| 181 | return getGEFWrapper(new AbstractActionSuccessor_AbstractActionReorientCommand( |
| 182 | req)); |
| 183 | } |
| 184 | return super.getReorientReferenceRelationshipCommand(req); |
| 185 | } |
| 186 | |
| 187 | } |