| 1 | /* |
| 2 | * Copyright 2007, SDQ, IPD, Uni Karlsruhe (TH) |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcm.gmf.composite.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.requests.CreateRelationshipRequest; |
| 14 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; |
| 15 | import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest; |
| 16 | import org.eclipse.gmf.runtime.notation.Edge; |
| 17 | import org.eclipse.gmf.runtime.notation.View; |
| 18 | |
| 19 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.AssemblyConnectorCreateCommand; |
| 20 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.AssemblyConnectorReorientCommand; |
| 21 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.ProvidedDelegationConnectorCreateCommand; |
| 22 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.ProvidedDelegationConnectorReorientCommand; |
| 23 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.AssemblyConnectorEditPart; |
| 24 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.ProvidedDelegationConnectorEditPart; |
| 25 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelVisualIDRegistry; |
| 26 | import de.uka.ipd.sdq.pcm.gmf.composite.providers.PalladioComponentModelElementTypes; |
| 27 | |
| 28 | /** |
| 29 | * Semantic Edit Policy for Operation Provided Role Delegation connectors. |
| 30 | * |
| 31 | * This edit policy has to ensure that operation provided delegation connectors |
| 32 | * can not connect system provided roles with system provided roles again. |
| 33 | * |
| 34 | * @generated |
| 35 | */ |
| 36 | public class OperationProvidedRole2ItemSemanticEditPolicy extends |
| 37 | PalladioComponentModelBaseItemSemanticEditPolicy { |
| 38 | |
| 39 | /** |
| 40 | * @generated |
| 41 | */ |
| 42 | public OperationProvidedRole2ItemSemanticEditPolicy() { |
| 43 | super(PalladioComponentModelElementTypes.OperationProvidedRole_3011); |
| 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) == AssemblyConnectorEditPart.VISUAL_ID) { |
| 58 | DestroyElementRequest r = new DestroyElementRequest( |
| 59 | incomingLink.getElement(), false); |
| 60 | cmd.add(new DestroyElementCommand(r)); |
| 61 | cmd.add(new DeleteCommand(getEditingDomain(), incomingLink)); |
| 62 | continue; |
| 63 | } |
| 64 | if (PalladioComponentModelVisualIDRegistry |
| 65 | .getVisualID(incomingLink) == ProvidedDelegationConnectorEditPart.VISUAL_ID) { |
| 66 | DestroyElementRequest r = new DestroyElementRequest( |
| 67 | incomingLink.getElement(), false); |
| 68 | cmd.add(new DestroyElementCommand(r)); |
| 69 | cmd.add(new DeleteCommand(getEditingDomain(), incomingLink)); |
| 70 | continue; |
| 71 | } |
| 72 | } |
| 73 | for (Iterator it = view.getSourceEdges().iterator(); it.hasNext();) { |
| 74 | Edge outgoingLink = (Edge) it.next(); |
| 75 | if (PalladioComponentModelVisualIDRegistry |
| 76 | .getVisualID(outgoingLink) == ProvidedDelegationConnectorEditPart.VISUAL_ID) { |
| 77 | DestroyElementRequest r = new DestroyElementRequest( |
| 78 | outgoingLink.getElement(), false); |
| 79 | cmd.add(new DestroyElementCommand(r)); |
| 80 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
| 81 | continue; |
| 82 | } |
| 83 | } |
| 84 | EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$ |
| 85 | if (annotation == null) { |
| 86 | // there are indirectly referenced children, need extra commands: false |
| 87 | addDestroyShortcutsCommand(cmd, view); |
| 88 | // delete host element |
| 89 | cmd.add(new DestroyElementCommand(req)); |
| 90 | } else { |
| 91 | cmd.add(new DeleteCommand(getEditingDomain(), view)); |
| 92 | } |
| 93 | return getGEFWrapper(cmd.reduce()); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @generated |
| 98 | */ |
| 99 | protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) { |
| 100 | Command command = req.getTarget() == null ? getStartCreateRelationshipCommand(req) |
| 101 | : getCompleteCreateRelationshipCommand(req); |
| 102 | return command != null ? command : super |
| 103 | .getCreateRelationshipCommand(req); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @generated |
| 108 | */ |
| 109 | protected Command getStartCreateRelationshipCommand( |
| 110 | CreateRelationshipRequest req) { |
| 111 | if (PalladioComponentModelElementTypes.AssemblyConnector_4004 == req |
| 112 | .getElementType()) { |
| 113 | return null; |
| 114 | } |
| 115 | if (PalladioComponentModelElementTypes.ProvidedDelegationConnector_4006 == req |
| 116 | .getElementType()) { |
| 117 | return getGEFWrapper(new ProvidedDelegationConnectorCreateCommand( |
| 118 | req, req.getSource(), req.getTarget())); |
| 119 | } |
| 120 | return null; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * @generated not |
| 125 | */ |
| 126 | protected Command getCompleteCreateRelationshipCommand( |
| 127 | CreateRelationshipRequest req) { |
| 128 | return null; |
| 129 | // if (PalladioComponentModelElementTypes.AssemblyConnector_4004 == req |
| 130 | // .getElementType()) { |
| 131 | // return getGEFWrapper(new AssemblyConnectorCreateCommand(req, req |
| 132 | // .getSource(), req.getTarget())); |
| 133 | // } |
| 134 | // if (PalladioComponentModelElementTypes.ProvidedDelegationConnector_4006 == req |
| 135 | // .getElementType()) { |
| 136 | // return getGEFWrapper(new ProvidedDelegationConnectorCreateCommand( |
| 137 | // req, req.getSource(), req.getTarget())); |
| 138 | // } |
| 139 | // return null; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Returns command to reorient EClass based link. New link target or source |
| 144 | * should be the domain model element associated with this node. |
| 145 | * |
| 146 | * @generated |
| 147 | */ |
| 148 | protected Command getReorientRelationshipCommand( |
| 149 | ReorientRelationshipRequest req) { |
| 150 | switch (getVisualID(req)) { |
| 151 | case AssemblyConnectorEditPart.VISUAL_ID: |
| 152 | return getGEFWrapper(new AssemblyConnectorReorientCommand(req)); |
| 153 | case ProvidedDelegationConnectorEditPart.VISUAL_ID: |
| 154 | return getGEFWrapper(new ProvidedDelegationConnectorReorientCommand( |
| 155 | req)); |
| 156 | } |
| 157 | return super.getReorientRelationshipCommand(req); |
| 158 | } |
| 159 | |
| 160 | } |