1 | /* |
2 | *Copyright 2007, SDQ, IPD, U KA |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.allocation.providers; |
5 | |
6 | import org.eclipse.core.runtime.IAdaptable; |
7 | import org.eclipse.emf.ecore.EClass; |
8 | import org.eclipse.emf.ecore.EObject; |
9 | import org.eclipse.gmf.runtime.diagram.core.providers.AbstractViewProvider; |
10 | import org.eclipse.gmf.runtime.notation.View; |
11 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
12 | import org.eclipse.gmf.runtime.emf.type.core.IHintedType; |
13 | import de.uka.ipd.sdq.pcm.gmf.allocation.edit.parts.AllocationComponentLabelEditPart; |
14 | import de.uka.ipd.sdq.pcm.gmf.allocation.edit.parts.AllocationContextEditPart; |
15 | import de.uka.ipd.sdq.pcm.gmf.allocation.edit.parts.AllocationContextEntityNameEditPart; |
16 | import de.uka.ipd.sdq.pcm.gmf.allocation.edit.parts.AllocationEditPart; |
17 | import de.uka.ipd.sdq.pcm.gmf.allocation.edit.parts.ResourceContainerAllocationCompartmentEditPart; |
18 | import de.uka.ipd.sdq.pcm.gmf.allocation.edit.parts.ResourceContainerEditPart; |
19 | import de.uka.ipd.sdq.pcm.gmf.allocation.edit.parts.ResourceContainerEntityNameEditPart; |
20 | |
21 | import de.uka.ipd.sdq.pcm.gmf.allocation.part.PalladioComponentModelVisualIDRegistry; |
22 | |
23 | import de.uka.ipd.sdq.pcm.gmf.allocation.view.factories.AllocationComponentLabelViewFactory; |
24 | import de.uka.ipd.sdq.pcm.gmf.allocation.view.factories.AllocationContextEntityNameViewFactory; |
25 | import de.uka.ipd.sdq.pcm.gmf.allocation.view.factories.AllocationContextViewFactory; |
26 | import de.uka.ipd.sdq.pcm.gmf.allocation.view.factories.AllocationViewFactory; |
27 | import de.uka.ipd.sdq.pcm.gmf.allocation.view.factories.ResourceContainerAllocationCompartmentViewFactory; |
28 | import de.uka.ipd.sdq.pcm.gmf.allocation.view.factories.ResourceContainerEntityNameViewFactory; |
29 | import de.uka.ipd.sdq.pcm.gmf.allocation.view.factories.ResourceContainerViewFactory; |
30 | |
31 | /** |
32 | * @generated |
33 | */ |
34 | public class PalladioComponentModelViewProvider extends AbstractViewProvider { |
35 | |
36 | /** |
37 | * @generated |
38 | */ |
39 | protected Class getDiagramViewClass(IAdaptable semanticAdapter, |
40 | String diagramKind) { |
41 | EObject semanticElement = getSemanticElement(semanticAdapter); |
42 | if (AllocationEditPart.MODEL_ID.equals(diagramKind) |
43 | && PalladioComponentModelVisualIDRegistry |
44 | .getDiagramVisualID(semanticElement) != -1) { |
45 | return AllocationViewFactory.class; |
46 | } |
47 | return null; |
48 | } |
49 | |
50 | /** |
51 | * @generated |
52 | */ |
53 | protected Class getNodeViewClass(IAdaptable semanticAdapter, |
54 | View containerView, String semanticHint) { |
55 | if (containerView == null) { |
56 | return null; |
57 | } |
58 | IElementType elementType = getSemanticElementType(semanticAdapter); |
59 | EObject domainElement = getSemanticElement(semanticAdapter); |
60 | int visualID; |
61 | if (semanticHint == null) { |
62 | // Semantic hint is not specified. Can be a result of call from CanonicalEditPolicy. |
63 | // In this situation there should be NO elementType, visualID will be determined |
64 | // by VisualIDRegistry.getNodeVisualID() for domainElement. |
65 | if (elementType != null || domainElement == null) { |
66 | return null; |
67 | } |
68 | visualID = PalladioComponentModelVisualIDRegistry.getNodeVisualID( |
69 | containerView, domainElement); |
70 | } else { |
71 | visualID = PalladioComponentModelVisualIDRegistry |
72 | .getVisualID(semanticHint); |
73 | if (elementType != null) { |
74 | // Semantic hint is specified together with element type. |
75 | // Both parameters should describe exactly the same diagram element. |
76 | // In addition we check that visualID returned by VisualIDRegistry.getNodeVisualID() for |
77 | // domainElement (if specified) is the same as in element type. |
78 | if (!PalladioComponentModelElementTypes |
79 | .isKnownElementType(elementType) |
80 | || (!(elementType instanceof IHintedType))) { |
81 | return null; // foreign element type |
82 | } |
83 | String elementTypeHint = ((IHintedType) elementType) |
84 | .getSemanticHint(); |
85 | if (!semanticHint.equals(elementTypeHint)) { |
86 | return null; // if semantic hint is specified it should be the same as in element type |
87 | } |
88 | if (domainElement != null |
89 | && visualID != PalladioComponentModelVisualIDRegistry |
90 | .getNodeVisualID(containerView, domainElement)) { |
91 | return null; // visual id for node EClass should match visual id from element type |
92 | } |
93 | } else { |
94 | // Element type is not specified. Domain element should be present (except pure design elements). |
95 | // This method is called with EObjectAdapter as parameter from: |
96 | // - ViewService.createNode(View container, EObject eObject, String type, PreferencesHint preferencesHint) |
97 | // - generated ViewFactory.decorateView() for parent element |
98 | if (!AllocationEditPart.MODEL_ID |
99 | .equals(PalladioComponentModelVisualIDRegistry |
100 | .getModelID(containerView))) { |
101 | return null; // foreign diagram |
102 | } |
103 | switch (visualID) { |
104 | case ResourceContainerEditPart.VISUAL_ID: |
105 | case AllocationContextEditPart.VISUAL_ID: |
106 | if (domainElement == null |
107 | || visualID != PalladioComponentModelVisualIDRegistry |
108 | .getNodeVisualID(containerView, |
109 | domainElement)) { |
110 | return null; // visual id in semantic hint should match visual id for domain element |
111 | } |
112 | break; |
113 | case ResourceContainerEntityNameEditPart.VISUAL_ID: |
114 | case ResourceContainerAllocationCompartmentEditPart.VISUAL_ID: |
115 | if (ResourceContainerEditPart.VISUAL_ID != PalladioComponentModelVisualIDRegistry |
116 | .getVisualID(containerView) |
117 | || containerView.getElement() != domainElement) { |
118 | return null; // wrong container |
119 | } |
120 | break; |
121 | case AllocationContextEntityNameEditPart.VISUAL_ID: |
122 | case AllocationComponentLabelEditPart.VISUAL_ID: |
123 | if (AllocationContextEditPart.VISUAL_ID != PalladioComponentModelVisualIDRegistry |
124 | .getVisualID(containerView) |
125 | || containerView.getElement() != domainElement) { |
126 | return null; // wrong container |
127 | } |
128 | break; |
129 | default: |
130 | return null; |
131 | } |
132 | } |
133 | } |
134 | return getNodeViewClass(containerView, visualID); |
135 | } |
136 | |
137 | /** |
138 | * @generated |
139 | */ |
140 | protected Class getNodeViewClass(View containerView, int visualID) { |
141 | if (containerView == null |
142 | || !PalladioComponentModelVisualIDRegistry.canCreateNode( |
143 | containerView, visualID)) { |
144 | return null; |
145 | } |
146 | switch (visualID) { |
147 | case ResourceContainerEditPart.VISUAL_ID: |
148 | return ResourceContainerViewFactory.class; |
149 | case ResourceContainerEntityNameEditPart.VISUAL_ID: |
150 | return ResourceContainerEntityNameViewFactory.class; |
151 | case AllocationContextEditPart.VISUAL_ID: |
152 | return AllocationContextViewFactory.class; |
153 | case AllocationContextEntityNameEditPart.VISUAL_ID: |
154 | return AllocationContextEntityNameViewFactory.class; |
155 | case AllocationComponentLabelEditPart.VISUAL_ID: |
156 | return AllocationComponentLabelViewFactory.class; |
157 | case ResourceContainerAllocationCompartmentEditPart.VISUAL_ID: |
158 | return ResourceContainerAllocationCompartmentViewFactory.class; |
159 | } |
160 | return null; |
161 | } |
162 | |
163 | /** |
164 | * @generated |
165 | */ |
166 | protected Class getEdgeViewClass(IAdaptable semanticAdapter, |
167 | View containerView, String semanticHint) { |
168 | IElementType elementType = getSemanticElementType(semanticAdapter); |
169 | if (!PalladioComponentModelElementTypes.isKnownElementType(elementType) |
170 | || (!(elementType instanceof IHintedType))) { |
171 | return null; // foreign element type |
172 | } |
173 | String elementTypeHint = ((IHintedType) elementType).getSemanticHint(); |
174 | if (elementTypeHint == null) { |
175 | return null; // our hint is visual id and must be specified |
176 | } |
177 | if (semanticHint != null && !semanticHint.equals(elementTypeHint)) { |
178 | return null; // if semantic hint is specified it should be the same as in element type |
179 | } |
180 | int visualID = PalladioComponentModelVisualIDRegistry |
181 | .getVisualID(elementTypeHint); |
182 | EObject domainElement = getSemanticElement(semanticAdapter); |
183 | if (domainElement != null |
184 | && visualID != PalladioComponentModelVisualIDRegistry |
185 | .getLinkWithClassVisualID(domainElement)) { |
186 | return null; // visual id for link EClass should match visual id from element type |
187 | } |
188 | return getEdgeViewClass(visualID); |
189 | } |
190 | |
191 | /** |
192 | * @generated |
193 | */ |
194 | protected Class getEdgeViewClass(int visualID) { |
195 | switch (visualID) { |
196 | } |
197 | return null; |
198 | } |
199 | |
200 | /** |
201 | * @generated |
202 | */ |
203 | private IElementType getSemanticElementType(IAdaptable semanticAdapter) { |
204 | if (semanticAdapter == null) { |
205 | return null; |
206 | } |
207 | return (IElementType) semanticAdapter.getAdapter(IElementType.class); |
208 | } |
209 | |
210 | } |