1 | /* |
2 | * Copyright 2007, SDQ, IPD, Uni Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.composite.sheet; |
5 | |
6 | import org.eclipse.core.runtime.IAdaptable; |
7 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
8 | import org.eclipse.gmf.runtime.notation.View; |
9 | import org.eclipse.jface.viewers.BaseLabelProvider; |
10 | import org.eclipse.jface.viewers.ILabelProvider; |
11 | import org.eclipse.jface.viewers.IStructuredSelection; |
12 | import org.eclipse.swt.graphics.Image; |
13 | |
14 | import de.uka.ipd.sdq.pcm.gmf.composite.navigator.PalladioComponentModelNavigatorGroup; |
15 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelVisualIDRegistry; |
16 | import de.uka.ipd.sdq.pcm.gmf.composite.providers.PalladioComponentModelElementTypes; |
17 | |
18 | /** |
19 | * @generated |
20 | */ |
21 | public class PalladioComponentModelSheetLabelProvider extends BaseLabelProvider |
22 | implements ILabelProvider { |
23 | |
24 | /** |
25 | * @generated |
26 | */ |
27 | public String getText(Object element) { |
28 | element = unwrap(element); |
29 | if (element instanceof PalladioComponentModelNavigatorGroup) { |
30 | return ((PalladioComponentModelNavigatorGroup) element) |
31 | .getGroupName(); |
32 | } |
33 | IElementType etype = getElementType(getView(element)); |
34 | return etype == null ? "" : etype.getDisplayName(); |
35 | } |
36 | |
37 | /** |
38 | * @generated |
39 | */ |
40 | public Image getImage(Object element) { |
41 | IElementType etype = getElementType(getView(unwrap(element))); |
42 | return etype == null ? null : PalladioComponentModelElementTypes |
43 | .getImage(etype); |
44 | } |
45 | |
46 | /** |
47 | * @generated |
48 | */ |
49 | private Object unwrap(Object element) { |
50 | if (element instanceof IStructuredSelection) { |
51 | return ((IStructuredSelection) element).getFirstElement(); |
52 | } |
53 | return element; |
54 | } |
55 | |
56 | /** |
57 | * @generated |
58 | */ |
59 | private View getView(Object element) { |
60 | if (element instanceof View) { |
61 | return (View) element; |
62 | } |
63 | if (element instanceof IAdaptable) { |
64 | return (View) ((IAdaptable) element).getAdapter(View.class); |
65 | } |
66 | return null; |
67 | } |
68 | |
69 | /** |
70 | * @generated |
71 | */ |
72 | private IElementType getElementType(View view) { |
73 | // For intermediate views climb up the containment hierarchy to find the one associated with an element type. |
74 | while (view != null) { |
75 | int vid = PalladioComponentModelVisualIDRegistry.getVisualID(view); |
76 | IElementType etype = PalladioComponentModelElementTypes |
77 | .getElementType(vid); |
78 | if (etype != null) { |
79 | return etype; |
80 | } |
81 | view = view.eContainer() instanceof View ? (View) view.eContainer() |
82 | : null; |
83 | } |
84 | return null; |
85 | } |
86 | |
87 | } |