| 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 | import org.eclipse.emf.ecore.EAnnotation; |
| 8 | import org.eclipse.emf.ecore.EObject; |
| 9 | import org.eclipse.gef.commands.Command; |
| 10 | import org.eclipse.gef.commands.UnexecutableCommand; |
| 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.requests.CreateRelationshipRequest; |
| 15 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; |
| 16 | import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest; |
| 17 | import org.eclipse.gmf.runtime.notation.Edge; |
| 18 | import org.eclipse.gmf.runtime.notation.View; |
| 19 | |
| 20 | import de.uka.ipd.sdq.pcm.core.composition.AssemblyContext; |
| 21 | import de.uka.ipd.sdq.pcm.core.composition.ComposedStructure; |
| 22 | import de.uka.ipd.sdq.pcm.core.composition.CompositionPackage; |
| 23 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.AssemblyConnectorTypeLinkCreateCommand; |
| 24 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.AssemblyEventConnectorCreateCommand; |
| 25 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.AssemblyEventConnectorReorientCommand; |
| 26 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.AssemblyEventConnectorEditPart; |
| 27 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelVisualIDRegistry; |
| 28 | import de.uka.ipd.sdq.pcm.gmf.composite.providers.PalladioComponentModelElementTypes; |
| 29 | import de.uka.ipd.sdq.pcm.repository.OperationProvidedRole; |
| 30 | import de.uka.ipd.sdq.pcm.repository.OperationRequiredRole; |
| 31 | import de.uka.ipd.sdq.pcm.repository.SinkRole; |
| 32 | import de.uka.ipd.sdq.pcm.repository.SourceRole; |
| 33 | |
| 34 | /** |
| 35 | * @generated |
| 36 | */ |
| 37 | public class SinkRoleItemSemanticEditPolicy extends |
| 38 | PalladioComponentModelBaseItemSemanticEditPolicy { |
| 39 | |
| 40 | /** |
| 41 | * @generated |
| 42 | */ |
| 43 | public SinkRoleItemSemanticEditPolicy() { |
| 44 | super(PalladioComponentModelElementTypes.SinkRole_3014); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @generated |
| 49 | */ |
| 50 | protected Command getDestroyElementCommand(DestroyElementRequest req) { |
| 51 | View view = (View) getHost().getModel(); |
| 52 | CompositeTransactionalCommand cmd = new CompositeTransactionalCommand( |
| 53 | getEditingDomain(), null); |
| 54 | cmd.setTransactionNestingEnabled(false); |
| 55 | for (Iterator it = view.getTargetEdges().iterator(); it.hasNext();) { |
| 56 | Edge incomingLink = (Edge) it.next(); |
| 57 | if (PalladioComponentModelVisualIDRegistry |
| 58 | .getVisualID(incomingLink) == AssemblyEventConnectorEditPart.VISUAL_ID) { |
| 59 | DestroyElementRequest r = new DestroyElementRequest( |
| 60 | incomingLink.getElement(), false); |
| 61 | cmd.add(new DestroyElementCommand(r)); |
| 62 | cmd.add(new DeleteCommand(getEditingDomain(), incomingLink)); |
| 63 | continue; |
| 64 | } |
| 65 | } |
| 66 | EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$ |
| 67 | if (annotation == null) { |
| 68 | // there are indirectly referenced children, need extra commands: false |
| 69 | addDestroyShortcutsCommand(cmd, view); |
| 70 | // delete host element |
| 71 | cmd.add(new DestroyElementCommand(req)); |
| 72 | } else { |
| 73 | cmd.add(new DeleteCommand(getEditingDomain(), view)); |
| 74 | } |
| 75 | return getGEFWrapper(cmd.reduce()); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Get the create relationship command or null / UnexecutableCommand instance |
| 80 | * if this is not an valid end for the connector creation. |
| 81 | * |
| 82 | * This has been manually adopted to fix this connection for AssemblyEventConnectors |
| 83 | * |
| 84 | * @generated |
| 85 | */ |
| 86 | protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) { |
| 87 | Command command = req.getTarget() == null ? getStartCreateRelationshipCommand(req) |
| 88 | : getCompleteCreateRelationshipCommand(req); |
| 89 | return command != null ? command : super |
| 90 | .getCreateRelationshipCommand(req); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @generated |
| 95 | */ |
| 96 | protected Command getStartCreateRelationshipCommand( |
| 97 | CreateRelationshipRequest req) { |
| 98 | if (PalladioComponentModelElementTypes.AssemblyEventConnector_4007 == req |
| 99 | .getElementType()) { |
| 100 | return null; |
| 101 | } |
| 102 | return null; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Create the command to complete the relationship. |
| 107 | * |
| 108 | * This has manually be adopted to set the container and contexts in the request. |
| 109 | * |
| 110 | * @generated not |
| 111 | */ |
| 112 | protected Command getCompleteCreateRelationshipCommand( |
| 113 | CreateRelationshipRequest req) { |
| 114 | if (PalladioComponentModelElementTypes.AssemblyEventConnector_4007 == req |
| 115 | .getElementType()) { |
| 116 | |
| 117 | return getCompleteCreateRelationshipCommandAssemblyEventConnector(req); |
| 118 | } |
| 119 | return null; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Create the command to complete the relationship. |
| 124 | * |
| 125 | * This has manually be adopted to set the container and contexts in the request. |
| 126 | * |
| 127 | * @param req The request object for this command request |
| 128 | * @return The prepared command. |
| 129 | * |
| 130 | * @generated not |
| 131 | */ |
| 132 | protected Command getCompleteCreateRelationshipCommandAssemblyEventConnector( |
| 133 | CreateRelationshipRequest req) { |
| 134 | |
| 135 | // set the container |
| 136 | ComposedStructure container = (ComposedStructure) getRelationshipContainer( |
| 137 | req.getSource(), CompositionPackage.eINSTANCE |
| 138 | .getComposedStructure(), req.getElementType()); |
| 139 | if (container == null) { |
| 140 | return UnexecutableCommand.INSTANCE; |
| 141 | } |
| 142 | req.setParameter("CONTAINER", container); |
| 143 | |
| 144 | // set the contexts |
| 145 | req.setParameter("SINK_CONTEXT", ((View) getHost().getParent() |
| 146 | .getModel()).getElement()); |
| 147 | |
| 148 | return getGEFWrapper(new AssemblyEventConnectorCreateCommand(req, req |
| 149 | .getSource(), req.getTarget())); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Returns command to reorient EClass based link. New link target or source |
| 154 | * should be the domain model element associated with this node. |
| 155 | * |
| 156 | * @generated |
| 157 | */ |
| 158 | protected Command getReorientRelationshipCommand( |
| 159 | ReorientRelationshipRequest req) { |
| 160 | switch (getVisualID(req)) { |
| 161 | case AssemblyEventConnectorEditPart.VISUAL_ID: |
| 162 | return getGEFWrapper(new AssemblyEventConnectorReorientCommand(req)); |
| 163 | } |
| 164 | return super.getReorientRelationshipCommand(req); |
| 165 | } |
| 166 | |
| 167 | } |