| 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.emf.ecore.EObject; |
| 10 | import org.eclipse.gef.commands.Command; |
| 11 | import org.eclipse.gef.commands.UnexecutableCommand; |
| 12 | import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand; |
| 13 | import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand; |
| 14 | import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand; |
| 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.ReorientRelationshipRequest; |
| 18 | import org.eclipse.gmf.runtime.notation.Edge; |
| 19 | import org.eclipse.gmf.runtime.notation.View; |
| 20 | |
| 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.AssemblyInfrastructureConnectorCreateCommand; |
| 24 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.AssemblyInfrastructureConnectorReorientCommand; |
| 25 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.AssemblyInfrastructureConnectorEditPart; |
| 26 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelVisualIDRegistry; |
| 27 | import de.uka.ipd.sdq.pcm.gmf.composite.providers.PalladioComponentModelElementTypes; |
| 28 | import de.uka.ipd.sdq.pcm.repository.InfrastructureRequiredRole; |
| 29 | import de.uka.ipd.sdq.pcm.repository.SourceRole; |
| 30 | |
| 31 | /** |
| 32 | * @generated |
| 33 | */ |
| 34 | public class InfrastructureRequiredRoleItemSemanticEditPolicy extends |
| 35 | PalladioComponentModelBaseItemSemanticEditPolicy { |
| 36 | |
| 37 | /** |
| 38 | * @generated |
| 39 | */ |
| 40 | public InfrastructureRequiredRoleItemSemanticEditPolicy() { |
| 41 | super( |
| 42 | PalladioComponentModelElementTypes.InfrastructureRequiredRole_3016); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @generated |
| 47 | */ |
| 48 | protected Command getDestroyElementCommand(DestroyElementRequest req) { |
| 49 | View view = (View) getHost().getModel(); |
| 50 | CompositeTransactionalCommand cmd = new CompositeTransactionalCommand( |
| 51 | getEditingDomain(), null); |
| 52 | cmd.setTransactionNestingEnabled(false); |
| 53 | for (Iterator it = view.getSourceEdges().iterator(); it.hasNext();) { |
| 54 | Edge outgoingLink = (Edge) it.next(); |
| 55 | if (PalladioComponentModelVisualIDRegistry |
| 56 | .getVisualID(outgoingLink) == AssemblyInfrastructureConnectorEditPart.VISUAL_ID) { |
| 57 | DestroyElementRequest r = new DestroyElementRequest( |
| 58 | outgoingLink.getElement(), false); |
| 59 | cmd.add(new DestroyElementCommand(r)); |
| 60 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
| 61 | continue; |
| 62 | } |
| 63 | } |
| 64 | EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$ |
| 65 | if (annotation == null) { |
| 66 | // there are indirectly referenced children, need extra commands: false |
| 67 | addDestroyShortcutsCommand(cmd, view); |
| 68 | // delete host element |
| 69 | cmd.add(new DestroyElementCommand(req)); |
| 70 | } else { |
| 71 | cmd.add(new DeleteCommand(getEditingDomain(), view)); |
| 72 | } |
| 73 | return getGEFWrapper(cmd.reduce()); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @generated |
| 78 | */ |
| 79 | protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) { |
| 80 | Command command = req.getTarget() == null ? getStartCreateRelationshipCommand(req) |
| 81 | : getCompleteCreateRelationshipCommand(req); |
| 82 | return command != null ? command : super |
| 83 | .getCreateRelationshipCommand(req); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * @generated not |
| 88 | */ |
| 89 | protected Command getStartCreateRelationshipCommand( |
| 90 | CreateRelationshipRequest req) { |
| 91 | if (PalladioComponentModelElementTypes.AssemblyInfrastructureConnector_4008 == req |
| 92 | .getElementType()) { |
| 93 | EObject sourceEObject = req.getSource(); |
| 94 | if (false == sourceEObject instanceof InfrastructureRequiredRole) { |
| 95 | return UnexecutableCommand.INSTANCE; |
| 96 | } |
| 97 | InfrastructureRequiredRole source = (InfrastructureRequiredRole) sourceEObject; |
| 98 | ComposedStructure container = (ComposedStructure) getRelationshipContainer( |
| 99 | source, CompositionPackage.eINSTANCE.getComposedStructure(), |
| 100 | req.getElementType()); |
| 101 | if (container == null) { |
| 102 | return UnexecutableCommand.INSTANCE; |
| 103 | } |
| 104 | if (!PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
| 105 | .canCreateAssemblyInfrastructureConnector_4008(container, source, null)) { |
| 106 | return UnexecutableCommand.INSTANCE; |
| 107 | } |
| 108 | // added to provide assembly context in addition to source and target role |
| 109 | req.setParameter("SOURCE_ASSEMBLY_CONTEXT", ((View) getHost().getParent() |
| 110 | .getModel()).getElement()); |
| 111 | |
| 112 | return new Command() { |
| 113 | }; |
| 114 | } |
| 115 | return null; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * @generated |
| 120 | */ |
| 121 | protected Command getCompleteCreateRelationshipCommand( |
| 122 | CreateRelationshipRequest req) { |
| 123 | if (PalladioComponentModelElementTypes.AssemblyInfrastructureConnector_4008 == req |
| 124 | .getElementType()) { |
| 125 | return null; |
| 126 | } |
| 127 | return null; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Returns command to reorient EClass based link. New link target or source |
| 132 | * should be the domain model element associated with this node. |
| 133 | * |
| 134 | * @generated |
| 135 | */ |
| 136 | protected Command getReorientRelationshipCommand( |
| 137 | ReorientRelationshipRequest req) { |
| 138 | switch (getVisualID(req)) { |
| 139 | case AssemblyInfrastructureConnectorEditPart.VISUAL_ID: |
| 140 | return getGEFWrapper(new AssemblyInfrastructureConnectorReorientCommand( |
| 141 | req)); |
| 142 | } |
| 143 | return super.getReorientRelationshipCommand(req); |
| 144 | } |
| 145 | |
| 146 | } |