| 1 | /* |
| 2 | * Copyright 2009, SDQ, IPD, Uni Karlsruhe (TH) |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcm.gmf.resource.part; |
| 5 | |
| 6 | import org.eclipse.core.runtime.Platform; |
| 7 | import org.eclipse.emf.ecore.EAnnotation; |
| 8 | import org.eclipse.emf.ecore.EObject; |
| 9 | import org.eclipse.gmf.runtime.notation.Diagram; |
| 10 | import org.eclipse.gmf.runtime.notation.View; |
| 11 | |
| 12 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.CommunicationLinkResourceSpecificationEditPart; |
| 13 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.CommunicationLinkResourceSpecificationFailureProbabilityEditPart; |
| 14 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.CommunicationLinkResourceSpecificationLatencyLabelEditPart; |
| 15 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.CommunicationLinkResourceSpecificationThroughputLabelEditPart; |
| 16 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.LinkingResource2EditPart; |
| 17 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.LinkingResourceEntityNameEditPart; |
| 18 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.LinkingResourceNetworkSwitchCompartmentEditPart; |
| 19 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ProcessingResourceSpecificationActiveResourceTypeLabelEditPart; |
| 20 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ProcessingResourceSpecificationEditPart; |
| 21 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ProcessingResourceSpecificationMTTFEditPart; |
| 22 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ProcessingResourceSpecificationMTTREditPart; |
| 23 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ProcessingResourceSpecificationNumberOfReplicasEditPart; |
| 24 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ProcessingResourceSpecificationProcessingResourceSpecificationCompartmentEditPart; |
| 25 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ProcessingResourceSpecificationSchedulingPolicyEditPart; |
| 26 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ResourceContainerEditPart; |
| 27 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ResourceContainerEntityNameEditPart; |
| 28 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ResourceContainerResourceContainerCompartmentEditPart; |
| 29 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ResourceEnvironmentEditPart; |
| 30 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.WrappingLabel2EditPart; |
| 31 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.WrappingLabelEditPart; |
| 32 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceEnvironment; |
| 33 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceenvironmentPackage; |
| 34 | |
| 35 | /** |
| 36 | * This registry is used to determine which type of visual object should be |
| 37 | * created for the corresponding Diagram, Node, ChildNode or Link represented |
| 38 | * by a domain model object. |
| 39 | * |
| 40 | * @generated |
| 41 | */ |
| 42 | public class PalladioComponentModelVisualIDRegistry { |
| 43 | |
| 44 | /** |
| 45 | * @generated |
| 46 | */ |
| 47 | private static final String DEBUG_KEY = "de.uka.ipd.sdq.pcm.gmf.resource/debug/visualID"; //$NON-NLS-1$ |
| 48 | |
| 49 | /** |
| 50 | * @generated |
| 51 | */ |
| 52 | public static int getVisualID(View view) { |
| 53 | if (view instanceof Diagram) { |
| 54 | if (ResourceEnvironmentEditPart.MODEL_ID.equals(view.getType())) { |
| 55 | return ResourceEnvironmentEditPart.VISUAL_ID; |
| 56 | } else { |
| 57 | return -1; |
| 58 | } |
| 59 | } |
| 60 | return de.uka.ipd.sdq.pcm.gmf.resource.part.PalladioComponentModelVisualIDRegistry |
| 61 | .getVisualID(view.getType()); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @generated |
| 66 | */ |
| 67 | public static String getModelID(View view) { |
| 68 | View diagram = view.getDiagram(); |
| 69 | while (view != diagram) { |
| 70 | EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$ |
| 71 | if (annotation != null) { |
| 72 | return (String) annotation.getDetails().get("modelID"); //$NON-NLS-1$ |
| 73 | } |
| 74 | view = (View) view.eContainer(); |
| 75 | } |
| 76 | return diagram != null ? diagram.getType() : null; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @generated |
| 81 | */ |
| 82 | public static int getVisualID(String type) { |
| 83 | try { |
| 84 | return Integer.parseInt(type); |
| 85 | } catch (NumberFormatException e) { |
| 86 | if (Boolean.TRUE.toString().equalsIgnoreCase( |
| 87 | Platform.getDebugOption(DEBUG_KEY))) { |
| 88 | PalladioComponentModelDiagramEditorPlugin.getInstance() |
| 89 | .logError( |
| 90 | "Unable to parse view type as a visualID number: " |
| 91 | + type); |
| 92 | } |
| 93 | } |
| 94 | return -1; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * @generated |
| 99 | */ |
| 100 | public static String getType(int visualID) { |
| 101 | return String.valueOf(visualID); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * @generated |
| 106 | */ |
| 107 | public static int getDiagramVisualID(EObject domainElement) { |
| 108 | if (domainElement == null) { |
| 109 | return -1; |
| 110 | } |
| 111 | if (ResourceenvironmentPackage.eINSTANCE.getResourceEnvironment() |
| 112 | .isSuperTypeOf(domainElement.eClass()) |
| 113 | && isDiagram((ResourceEnvironment) domainElement)) { |
| 114 | return ResourceEnvironmentEditPart.VISUAL_ID; |
| 115 | } |
| 116 | return -1; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * @generated |
| 121 | */ |
| 122 | public static int getNodeVisualID(View containerView, EObject domainElement) { |
| 123 | if (domainElement == null) { |
| 124 | return -1; |
| 125 | } |
| 126 | String containerModelID = de.uka.ipd.sdq.pcm.gmf.resource.part.PalladioComponentModelVisualIDRegistry |
| 127 | .getModelID(containerView); |
| 128 | if (!ResourceEnvironmentEditPart.MODEL_ID.equals(containerModelID)) { |
| 129 | return -1; |
| 130 | } |
| 131 | int containerVisualID; |
| 132 | if (ResourceEnvironmentEditPart.MODEL_ID.equals(containerModelID)) { |
| 133 | containerVisualID = de.uka.ipd.sdq.pcm.gmf.resource.part.PalladioComponentModelVisualIDRegistry |
| 134 | .getVisualID(containerView); |
| 135 | } else { |
| 136 | if (containerView instanceof Diagram) { |
| 137 | containerVisualID = ResourceEnvironmentEditPart.VISUAL_ID; |
| 138 | } else { |
| 139 | return -1; |
| 140 | } |
| 141 | } |
| 142 | switch (containerVisualID) { |
| 143 | case ResourceContainerResourceContainerCompartmentEditPart.VISUAL_ID: |
| 144 | if (ResourceenvironmentPackage.eINSTANCE |
| 145 | .getProcessingResourceSpecification().isSuperTypeOf( |
| 146 | domainElement.eClass())) { |
| 147 | return ProcessingResourceSpecificationEditPart.VISUAL_ID; |
| 148 | } |
| 149 | break; |
| 150 | case LinkingResourceNetworkSwitchCompartmentEditPart.VISUAL_ID: |
| 151 | if (ResourceenvironmentPackage.eINSTANCE |
| 152 | .getCommunicationLinkResourceSpecification().isSuperTypeOf( |
| 153 | domainElement.eClass())) { |
| 154 | return CommunicationLinkResourceSpecificationEditPart.VISUAL_ID; |
| 155 | } |
| 156 | break; |
| 157 | case ResourceEnvironmentEditPart.VISUAL_ID: |
| 158 | if (ResourceenvironmentPackage.eINSTANCE.getResourceContainer() |
| 159 | .isSuperTypeOf(domainElement.eClass())) { |
| 160 | return ResourceContainerEditPart.VISUAL_ID; |
| 161 | } |
| 162 | if (ResourceenvironmentPackage.eINSTANCE.getLinkingResource() |
| 163 | .isSuperTypeOf(domainElement.eClass())) { |
| 164 | return LinkingResource2EditPart.VISUAL_ID; |
| 165 | } |
| 166 | break; |
| 167 | } |
| 168 | return -1; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * @generated |
| 173 | */ |
| 174 | public static boolean canCreateNode(View containerView, int nodeVisualID) { |
| 175 | String containerModelID = de.uka.ipd.sdq.pcm.gmf.resource.part.PalladioComponentModelVisualIDRegistry |
| 176 | .getModelID(containerView); |
| 177 | if (!ResourceEnvironmentEditPart.MODEL_ID.equals(containerModelID)) { |
| 178 | return false; |
| 179 | } |
| 180 | int containerVisualID; |
| 181 | if (ResourceEnvironmentEditPart.MODEL_ID.equals(containerModelID)) { |
| 182 | containerVisualID = de.uka.ipd.sdq.pcm.gmf.resource.part.PalladioComponentModelVisualIDRegistry |
| 183 | .getVisualID(containerView); |
| 184 | } else { |
| 185 | if (containerView instanceof Diagram) { |
| 186 | containerVisualID = ResourceEnvironmentEditPart.VISUAL_ID; |
| 187 | } else { |
| 188 | return false; |
| 189 | } |
| 190 | } |
| 191 | switch (containerVisualID) { |
| 192 | case ResourceContainerEditPart.VISUAL_ID: |
| 193 | if (ResourceContainerEntityNameEditPart.VISUAL_ID == nodeVisualID) { |
| 194 | return true; |
| 195 | } |
| 196 | if (ResourceContainerResourceContainerCompartmentEditPart.VISUAL_ID == nodeVisualID) { |
| 197 | return true; |
| 198 | } |
| 199 | break; |
| 200 | case LinkingResource2EditPart.VISUAL_ID: |
| 201 | if (LinkingResourceEntityNameEditPart.VISUAL_ID == nodeVisualID) { |
| 202 | return true; |
| 203 | } |
| 204 | if (LinkingResourceNetworkSwitchCompartmentEditPart.VISUAL_ID == nodeVisualID) { |
| 205 | return true; |
| 206 | } |
| 207 | break; |
| 208 | case ProcessingResourceSpecificationEditPart.VISUAL_ID: |
| 209 | if (ProcessingResourceSpecificationMTTFEditPart.VISUAL_ID == nodeVisualID) { |
| 210 | return true; |
| 211 | } |
| 212 | if (ProcessingResourceSpecificationMTTREditPart.VISUAL_ID == nodeVisualID) { |
| 213 | return true; |
| 214 | } |
| 215 | if (ProcessingResourceSpecificationSchedulingPolicyEditPart.VISUAL_ID == nodeVisualID) { |
| 216 | return true; |
| 217 | } |
| 218 | if (ProcessingResourceSpecificationNumberOfReplicasEditPart.VISUAL_ID == nodeVisualID) { |
| 219 | return true; |
| 220 | } |
| 221 | if (WrappingLabelEditPart.VISUAL_ID == nodeVisualID) { |
| 222 | return true; |
| 223 | } |
| 224 | if (ProcessingResourceSpecificationActiveResourceTypeLabelEditPart.VISUAL_ID == nodeVisualID) { |
| 225 | return true; |
| 226 | } |
| 227 | if (ProcessingResourceSpecificationProcessingResourceSpecificationCompartmentEditPart.VISUAL_ID == nodeVisualID) { |
| 228 | return true; |
| 229 | } |
| 230 | break; |
| 231 | case CommunicationLinkResourceSpecificationEditPart.VISUAL_ID: |
| 232 | if (CommunicationLinkResourceSpecificationFailureProbabilityEditPart.VISUAL_ID == nodeVisualID) { |
| 233 | return true; |
| 234 | } |
| 235 | if (CommunicationLinkResourceSpecificationLatencyLabelEditPart.VISUAL_ID == nodeVisualID) { |
| 236 | return true; |
| 237 | } |
| 238 | if (CommunicationLinkResourceSpecificationThroughputLabelEditPart.VISUAL_ID == nodeVisualID) { |
| 239 | return true; |
| 240 | } |
| 241 | if (WrappingLabel2EditPart.VISUAL_ID == nodeVisualID) { |
| 242 | return true; |
| 243 | } |
| 244 | break; |
| 245 | case ResourceContainerResourceContainerCompartmentEditPart.VISUAL_ID: |
| 246 | if (ProcessingResourceSpecificationEditPart.VISUAL_ID == nodeVisualID) { |
| 247 | return true; |
| 248 | } |
| 249 | break; |
| 250 | case LinkingResourceNetworkSwitchCompartmentEditPart.VISUAL_ID: |
| 251 | if (CommunicationLinkResourceSpecificationEditPart.VISUAL_ID == nodeVisualID) { |
| 252 | return true; |
| 253 | } |
| 254 | break; |
| 255 | case ResourceEnvironmentEditPart.VISUAL_ID: |
| 256 | if (ResourceContainerEditPart.VISUAL_ID == nodeVisualID) { |
| 257 | return true; |
| 258 | } |
| 259 | if (LinkingResource2EditPart.VISUAL_ID == nodeVisualID) { |
| 260 | return true; |
| 261 | } |
| 262 | break; |
| 263 | } |
| 264 | return false; |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * @generated |
| 269 | */ |
| 270 | public static int getLinkWithClassVisualID(EObject domainElement) { |
| 271 | if (domainElement == null) { |
| 272 | return -1; |
| 273 | } |
| 274 | return -1; |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * User can change implementation of this method to handle some specific |
| 279 | * situations not covered by default logic. |
| 280 | * |
| 281 | * @generated |
| 282 | */ |
| 283 | private static boolean isDiagram(ResourceEnvironment element) { |
| 284 | return true; |
| 285 | } |
| 286 | |
| 287 | } |