| 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.Collection; |
| 7 | import java.util.HashSet; |
| 8 | import java.util.Iterator; |
| 9 | import java.util.LinkedList; |
| 10 | import java.util.List; |
| 11 | import java.util.Set; |
| 12 | |
| 13 | import org.eclipse.emf.ecore.EObject; |
| 14 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy; |
| 15 | import org.eclipse.gmf.runtime.notation.View; |
| 16 | |
| 17 | import de.uka.ipd.sdq.pcm.core.composition.AssemblyContext; |
| 18 | import de.uka.ipd.sdq.pcm.core.entity.EntityPackage; |
| 19 | import de.uka.ipd.sdq.pcm.core.entity.InterfaceProvidingEntity; |
| 20 | import de.uka.ipd.sdq.pcm.core.entity.InterfaceRequiringEntity; |
| 21 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.InfrastructureProvidedRoleEditPart; |
| 22 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.InfrastructureRequiredRoleEditPart; |
| 23 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.OperationProvidedRoleEditPart; |
| 24 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.OperationRequiredRoleEditPart; |
| 25 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.SinkRoleEditPart; |
| 26 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.SourceRoleEditPart; |
| 27 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelDiagramUpdater; |
| 28 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelNodeDescriptor; |
| 29 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelVisualIDRegistry; |
| 30 | |
| 31 | /** |
| 32 | * @generated |
| 33 | */ |
| 34 | public class AssemblyContextCanonicalEditPolicy extends CanonicalEditPolicy { |
| 35 | |
| 36 | /** |
| 37 | * @generated |
| 38 | */ |
| 39 | Set myFeaturesToSynchronize; |
| 40 | |
| 41 | /** |
| 42 | * Get the semantic children of an assembly context. |
| 43 | * |
| 44 | * This has been adopted manually for the composite editor diagram. |
| 45 | * The direct semantic child of an assembly context is the encapsulated component. |
| 46 | * In case of the composite diagram we present the provided and required roles of the |
| 47 | * component to the user instead. For this, the getSemanticChildrenList method collects all roles |
| 48 | * from the encapsulated component. |
| 49 | * |
| 50 | * @return The list of prov. and req. roles of the encapsulated component |
| 51 | * |
| 52 | * @generated not |
| 53 | */ |
| 54 | protected List getSemanticChildrenList() { |
| 55 | List result = new LinkedList(); |
| 56 | EObject modelObject = ((View) getHost().getModel()).getElement(); |
| 57 | AssemblyContext ctx = (AssemblyContext) modelObject; |
| 58 | modelObject = ctx.getEncapsulatedComponent__AssemblyContext(); |
| 59 | View viewObject = (View) getHost().getModel(); |
| 60 | EObject nextValue; |
| 61 | int nodeVID; |
| 62 | if (modelObject != null) { |
| 63 | for (Iterator values = ((InterfaceProvidingEntity) modelObject) |
| 64 | .getProvidedRoles_InterfaceProvidingEntity().iterator(); values |
| 65 | .hasNext();) { |
| 66 | nextValue = (EObject) values.next(); |
| 67 | nodeVID = PalladioComponentModelVisualIDRegistry |
| 68 | .getNodeVisualID(viewObject, nextValue); |
| 69 | // if (OperationProvidedRoleEditPart.VISUAL_ID == nodeVID) { |
| 70 | result.add(nextValue); |
| 71 | // } |
| 72 | } |
| 73 | for (Iterator values = ((InterfaceRequiringEntity) modelObject) |
| 74 | .getRequiredRoles_InterfaceRequiringEntity().iterator(); values |
| 75 | .hasNext();) { |
| 76 | nextValue = (EObject) values.next(); |
| 77 | nodeVID = PalladioComponentModelVisualIDRegistry |
| 78 | .getNodeVisualID(viewObject, nextValue); |
| 79 | // if (OperationRequiredRoleEditPart.VISUAL_ID == nodeVID) { |
| 80 | result.add(nextValue); |
| 81 | // } |
| 82 | } |
| 83 | } |
| 84 | return result; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * @generated |
| 89 | */ |
| 90 | protected boolean isOrphaned(Collection semanticChildren, final View view) { |
| 91 | int visualID = PalladioComponentModelVisualIDRegistry.getVisualID(view); |
| 92 | switch (visualID) { |
| 93 | case OperationProvidedRoleEditPart.VISUAL_ID: |
| 94 | case OperationRequiredRoleEditPart.VISUAL_ID: |
| 95 | case SourceRoleEditPart.VISUAL_ID: |
| 96 | case SinkRoleEditPart.VISUAL_ID: |
| 97 | case InfrastructureProvidedRoleEditPart.VISUAL_ID: |
| 98 | case InfrastructureRequiredRoleEditPart.VISUAL_ID: |
| 99 | if (!semanticChildren.contains(view.getElement())) { |
| 100 | return true; |
| 101 | } |
| 102 | } |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @generated |
| 108 | */ |
| 109 | protected String getDefaultFactoryHint() { |
| 110 | return null; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * @generated |
| 115 | */ |
| 116 | protected Set getFeaturesToSynchronize() { |
| 117 | if (myFeaturesToSynchronize == null) { |
| 118 | myFeaturesToSynchronize = new HashSet(); |
| 119 | myFeaturesToSynchronize |
| 120 | .add(EntityPackage.eINSTANCE |
| 121 | .getInterfaceProvidingEntity_ProvidedRoles_InterfaceProvidingEntity()); |
| 122 | myFeaturesToSynchronize |
| 123 | .add(EntityPackage.eINSTANCE |
| 124 | .getInterfaceRequiringEntity_RequiredRoles_InterfaceRequiringEntity()); |
| 125 | } |
| 126 | return myFeaturesToSynchronize; |
| 127 | } |
| 128 | |
| 129 | } |