1 | /* |
2 | * Copyright 2009, SDQ, IPD, Uni Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.resource.navigator; |
5 | |
6 | import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; |
7 | import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions; |
8 | import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; |
9 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
10 | import org.eclipse.gmf.runtime.notation.View; |
11 | import org.eclipse.jface.resource.ImageDescriptor; |
12 | import org.eclipse.jface.resource.ImageRegistry; |
13 | import org.eclipse.jface.viewers.ITreePathLabelProvider; |
14 | import org.eclipse.jface.viewers.LabelProvider; |
15 | import org.eclipse.jface.viewers.TreePath; |
16 | import org.eclipse.jface.viewers.ViewerLabel; |
17 | import org.eclipse.swt.graphics.Image; |
18 | import org.eclipse.ui.IMemento; |
19 | import org.eclipse.ui.navigator.ICommonContentExtensionSite; |
20 | import org.eclipse.ui.navigator.ICommonLabelProvider; |
21 | |
22 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.CommunicationLinkResourceSpecificationEditPart; |
23 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.CommunicationLinkResourceSpecificationFailureProbabilityEditPart; |
24 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.LinkingResource2EditPart; |
25 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.LinkingResourceConnectedResourceContainers_LinkingResourceEditPart; |
26 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.LinkingResourceEntityNameEditPart; |
27 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ProcessingResourceSpecificationEditPart; |
28 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ProcessingResourceSpecificationMTTFEditPart; |
29 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ResourceContainerEditPart; |
30 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ResourceContainerEntityNameEditPart; |
31 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ResourceEnvironmentEditPart; |
32 | import de.uka.ipd.sdq.pcm.gmf.resource.part.PalladioComponentModelDiagramEditorPlugin; |
33 | import de.uka.ipd.sdq.pcm.gmf.resource.part.PalladioComponentModelVisualIDRegistry; |
34 | import de.uka.ipd.sdq.pcm.gmf.resource.providers.PalladioComponentModelElementTypes; |
35 | import de.uka.ipd.sdq.pcm.gmf.resource.providers.PalladioComponentModelParserProvider; |
36 | import de.uka.ipd.sdq.pcm.resourceenvironment.LinkingResource; |
37 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceEnvironment; |
38 | |
39 | /** |
40 | * @generated |
41 | */ |
42 | public class PalladioComponentModelNavigatorLabelProvider extends LabelProvider |
43 | implements ICommonLabelProvider, ITreePathLabelProvider { |
44 | |
45 | /** |
46 | * @generated |
47 | */ |
48 | static { |
49 | PalladioComponentModelDiagramEditorPlugin |
50 | .getInstance() |
51 | .getImageRegistry() |
52 | .put( |
53 | "Navigator?UnknownElement", ImageDescriptor.getMissingImageDescriptor()); //$NON-NLS-1$ |
54 | PalladioComponentModelDiagramEditorPlugin |
55 | .getInstance() |
56 | .getImageRegistry() |
57 | .put( |
58 | "Navigator?ImageNotFound", ImageDescriptor.getMissingImageDescriptor()); //$NON-NLS-1$ |
59 | } |
60 | |
61 | /** |
62 | * @generated |
63 | */ |
64 | public void updateLabel(ViewerLabel label, TreePath elementPath) { |
65 | Object element = elementPath.getLastSegment(); |
66 | if (element instanceof PalladioComponentModelNavigatorItem |
67 | && !isOwnView(((PalladioComponentModelNavigatorItem) element) |
68 | .getView())) { |
69 | return; |
70 | } |
71 | label.setText(getText(element)); |
72 | label.setImage(getImage(element)); |
73 | } |
74 | |
75 | /** |
76 | * @generated |
77 | */ |
78 | public Image getImage(Object element) { |
79 | if (element instanceof PalladioComponentModelNavigatorGroup) { |
80 | PalladioComponentModelNavigatorGroup group = (PalladioComponentModelNavigatorGroup) element; |
81 | return PalladioComponentModelDiagramEditorPlugin.getInstance() |
82 | .getBundledImage(group.getIcon()); |
83 | } |
84 | |
85 | if (element instanceof PalladioComponentModelNavigatorItem) { |
86 | PalladioComponentModelNavigatorItem navigatorItem = (PalladioComponentModelNavigatorItem) element; |
87 | if (!isOwnView(navigatorItem.getView())) { |
88 | return super.getImage(element); |
89 | } |
90 | return getImage(navigatorItem.getView()); |
91 | } |
92 | |
93 | return super.getImage(element); |
94 | } |
95 | |
96 | /** |
97 | * @generated |
98 | */ |
99 | public Image getImage(View view) { |
100 | switch (PalladioComponentModelVisualIDRegistry.getVisualID(view)) { |
101 | case ResourceEnvironmentEditPart.VISUAL_ID: |
102 | return getImage( |
103 | "Navigator?Diagram?http://sdq.ipd.uka.de/PalladioComponentModel/ResourceEnvironment/4.0?ResourceEnvironment", PalladioComponentModelElementTypes.ResourceEnvironment_1000); //$NON-NLS-1$ |
104 | case ResourceContainerEditPart.VISUAL_ID: |
105 | return getImage( |
106 | "Navigator?TopLevelNode?http://sdq.ipd.uka.de/PalladioComponentModel/ResourceEnvironment/4.0?ResourceContainer", PalladioComponentModelElementTypes.ResourceContainer_2001); //$NON-NLS-1$ |
107 | case LinkingResource2EditPart.VISUAL_ID: |
108 | return getImage( |
109 | "Navigator?TopLevelNode?http://sdq.ipd.uka.de/PalladioComponentModel/ResourceEnvironment/4.0?LinkingResource", PalladioComponentModelElementTypes.LinkingResource_2003); //$NON-NLS-1$ |
110 | case ProcessingResourceSpecificationEditPart.VISUAL_ID: |
111 | return getImage( |
112 | "Navigator?Node?http://sdq.ipd.uka.de/PalladioComponentModel/ResourceEnvironment/4.0?ProcessingResourceSpecification", PalladioComponentModelElementTypes.ProcessingResourceSpecification_3001); //$NON-NLS-1$ |
113 | case CommunicationLinkResourceSpecificationEditPart.VISUAL_ID: |
114 | return getImage( |
115 | "Navigator?Node?http://sdq.ipd.uka.de/PalladioComponentModel/ResourceEnvironment/4.0?CommunicationLinkResourceSpecification", PalladioComponentModelElementTypes.CommunicationLinkResourceSpecification_3002); //$NON-NLS-1$ |
116 | case LinkingResourceConnectedResourceContainers_LinkingResourceEditPart.VISUAL_ID: |
117 | return getImage( |
118 | "Navigator?Link?http://sdq.ipd.uka.de/PalladioComponentModel/ResourceEnvironment/4.0?LinkingResource?connectedResourceContainers_LinkingResource", PalladioComponentModelElementTypes.LinkingResourceConnectedResourceContainers_LinkingResource_4002); //$NON-NLS-1$ |
119 | } |
120 | return getImage("Navigator?UnknownElement", null); //$NON-NLS-1$ |
121 | } |
122 | |
123 | /** |
124 | * @generated |
125 | */ |
126 | private Image getImage(String key, IElementType elementType) { |
127 | ImageRegistry imageRegistry = PalladioComponentModelDiagramEditorPlugin |
128 | .getInstance().getImageRegistry(); |
129 | Image image = imageRegistry.get(key); |
130 | if (image == null |
131 | && elementType != null |
132 | && PalladioComponentModelElementTypes |
133 | .isKnownElementType(elementType)) { |
134 | image = PalladioComponentModelElementTypes.getImage(elementType); |
135 | imageRegistry.put(key, image); |
136 | } |
137 | |
138 | if (image == null) { |
139 | image = imageRegistry.get("Navigator?ImageNotFound"); //$NON-NLS-1$ |
140 | imageRegistry.put(key, image); |
141 | } |
142 | return image; |
143 | } |
144 | |
145 | /** |
146 | * @generated |
147 | */ |
148 | public String getText(Object element) { |
149 | if (element instanceof PalladioComponentModelNavigatorGroup) { |
150 | PalladioComponentModelNavigatorGroup group = (PalladioComponentModelNavigatorGroup) element; |
151 | return group.getGroupName(); |
152 | } |
153 | |
154 | if (element instanceof PalladioComponentModelNavigatorItem) { |
155 | PalladioComponentModelNavigatorItem navigatorItem = (PalladioComponentModelNavigatorItem) element; |
156 | if (!isOwnView(navigatorItem.getView())) { |
157 | return null; |
158 | } |
159 | return getText(navigatorItem.getView()); |
160 | } |
161 | |
162 | return super.getText(element); |
163 | } |
164 | |
165 | /** |
166 | * @generated |
167 | */ |
168 | public String getText(View view) { |
169 | if (view.getElement() != null && view.getElement().eIsProxy()) { |
170 | return getUnresolvedDomainElementProxyText(view); |
171 | } |
172 | switch (PalladioComponentModelVisualIDRegistry.getVisualID(view)) { |
173 | case ResourceEnvironmentEditPart.VISUAL_ID: |
174 | return getResourceEnvironment_1000Text(view); |
175 | case ResourceContainerEditPart.VISUAL_ID: |
176 | return getResourceContainer_2001Text(view); |
177 | case LinkingResource2EditPart.VISUAL_ID: |
178 | return getLinkingResource_2003Text(view); |
179 | case ProcessingResourceSpecificationEditPart.VISUAL_ID: |
180 | return getProcessingResourceSpecification_3001Text(view); |
181 | case CommunicationLinkResourceSpecificationEditPart.VISUAL_ID: |
182 | return getCommunicationLinkResourceSpecification_3002Text(view); |
183 | case LinkingResourceConnectedResourceContainers_LinkingResourceEditPart.VISUAL_ID: |
184 | return getLinkingResourceConnectedResourceContainers_LinkingResource_4002Text(view); |
185 | } |
186 | return getUnknownElementText(view); |
187 | } |
188 | |
189 | /** |
190 | * @generated |
191 | */ |
192 | private String getResourceEnvironment_1000Text(View view) { |
193 | ResourceEnvironment domainModelElement = (ResourceEnvironment) view |
194 | .getElement(); |
195 | if (domainModelElement != null) { |
196 | return domainModelElement.getEntityName(); |
197 | } else { |
198 | PalladioComponentModelDiagramEditorPlugin.getInstance().logError( |
199 | "No domain element for view with visualID = " + 1000); //$NON-NLS-1$ |
200 | return ""; //$NON-NLS-1$ |
201 | } |
202 | } |
203 | |
204 | /** |
205 | * @generated |
206 | */ |
207 | private String getResourceContainer_2001Text(View view) { |
208 | IParser parser = PalladioComponentModelParserProvider |
209 | .getParser( |
210 | PalladioComponentModelElementTypes.ResourceContainer_2001, |
211 | view.getElement() != null ? view.getElement() : view, |
212 | PalladioComponentModelVisualIDRegistry |
213 | .getType(ResourceContainerEntityNameEditPart.VISUAL_ID)); |
214 | if (parser != null) { |
215 | return parser.getPrintString(new EObjectAdapter( |
216 | view.getElement() != null ? view.getElement() : view), |
217 | ParserOptions.NONE.intValue()); |
218 | } else { |
219 | PalladioComponentModelDiagramEditorPlugin.getInstance().logError( |
220 | "Parser was not found for label " + 5001); //$NON-NLS-1$ |
221 | return ""; //$NON-NLS-1$ |
222 | } |
223 | } |
224 | |
225 | /** |
226 | * @generated |
227 | */ |
228 | private String getLinkingResource_2003Text(View view) { |
229 | IParser parser = PalladioComponentModelParserProvider.getParser( |
230 | PalladioComponentModelElementTypes.LinkingResource_2003, view |
231 | .getElement() != null ? view.getElement() : view, |
232 | PalladioComponentModelVisualIDRegistry |
233 | .getType(LinkingResourceEntityNameEditPart.VISUAL_ID)); |
234 | if (parser != null) { |
235 | return parser.getPrintString(new EObjectAdapter( |
236 | view.getElement() != null ? view.getElement() : view), |
237 | ParserOptions.NONE.intValue()); |
238 | } else { |
239 | PalladioComponentModelDiagramEditorPlugin.getInstance().logError( |
240 | "Parser was not found for label " + 5012); //$NON-NLS-1$ |
241 | return ""; //$NON-NLS-1$ |
242 | } |
243 | } |
244 | |
245 | /** |
246 | * @generated |
247 | */ |
248 | private String getProcessingResourceSpecification_3001Text(View view) { |
249 | IParser parser = PalladioComponentModelParserProvider |
250 | .getParser( |
251 | PalladioComponentModelElementTypes.ProcessingResourceSpecification_3001, |
252 | view.getElement() != null ? view.getElement() : view, |
253 | PalladioComponentModelVisualIDRegistry |
254 | .getType(ProcessingResourceSpecificationMTTFEditPart.VISUAL_ID)); |
255 | if (parser != null) { |
256 | return parser.getPrintString(new EObjectAdapter( |
257 | view.getElement() != null ? view.getElement() : view), |
258 | ParserOptions.NONE.intValue()); |
259 | } else { |
260 | PalladioComponentModelDiagramEditorPlugin.getInstance().logError( |
261 | "Parser was not found for label " + 5002); //$NON-NLS-1$ |
262 | return ""; //$NON-NLS-1$ |
263 | } |
264 | } |
265 | |
266 | /** |
267 | * @generated |
268 | */ |
269 | private String getCommunicationLinkResourceSpecification_3002Text(View view) { |
270 | IParser parser = PalladioComponentModelParserProvider |
271 | .getParser( |
272 | PalladioComponentModelElementTypes.CommunicationLinkResourceSpecification_3002, |
273 | view.getElement() != null ? view.getElement() : view, |
274 | PalladioComponentModelVisualIDRegistry |
275 | .getType(CommunicationLinkResourceSpecificationFailureProbabilityEditPart.VISUAL_ID)); |
276 | if (parser != null) { |
277 | return parser.getPrintString(new EObjectAdapter( |
278 | view.getElement() != null ? view.getElement() : view), |
279 | ParserOptions.NONE.intValue()); |
280 | } else { |
281 | PalladioComponentModelDiagramEditorPlugin.getInstance().logError( |
282 | "Parser was not found for label " + 5005); //$NON-NLS-1$ |
283 | return ""; //$NON-NLS-1$ |
284 | } |
285 | } |
286 | |
287 | /** |
288 | * @generated |
289 | */ |
290 | private String getLinkingResourceConnectedResourceContainers_LinkingResource_4002Text( |
291 | View view) { |
292 | return ""; //$NON-NLS-1$ |
293 | } |
294 | |
295 | /** |
296 | * @generated |
297 | */ |
298 | private String getUnknownElementText(View view) { |
299 | return "<UnknownElement Visual_ID = " + view.getType() + ">"; //$NON-NLS-1$ //$NON-NLS-2$ |
300 | } |
301 | |
302 | /** |
303 | * @generated |
304 | */ |
305 | private String getUnresolvedDomainElementProxyText(View view) { |
306 | return "<Unresolved domain element Visual_ID = " + view.getType() + ">"; //$NON-NLS-1$ //$NON-NLS-2$ |
307 | } |
308 | |
309 | /** |
310 | * @generated |
311 | */ |
312 | public void init(ICommonContentExtensionSite aConfig) { |
313 | } |
314 | |
315 | /** |
316 | * @generated |
317 | */ |
318 | public void restoreState(IMemento aMemento) { |
319 | } |
320 | |
321 | /** |
322 | * @generated |
323 | */ |
324 | public void saveState(IMemento aMemento) { |
325 | } |
326 | |
327 | /** |
328 | * @generated |
329 | */ |
330 | public String getDescription(Object anElement) { |
331 | return null; |
332 | } |
333 | |
334 | /** |
335 | * @generated |
336 | */ |
337 | private boolean isOwnView(View view) { |
338 | return ResourceEnvironmentEditPart.MODEL_ID |
339 | .equals(PalladioComponentModelVisualIDRegistry.getModelID(view)); |
340 | } |
341 | |
342 | } |