1 | /* |
2 | * Copyright 2007, SDQ, IPD, U KA |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.allocation.sheet; |
5 | |
6 | import org.eclipse.core.runtime.IAdaptable; |
7 | import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; |
8 | import org.eclipse.gef.EditPart; |
9 | import org.eclipse.gmf.runtime.notation.View; |
10 | import org.eclipse.jface.viewers.DecoratingLabelProvider; |
11 | import org.eclipse.jface.viewers.IStructuredSelection; |
12 | import org.eclipse.swt.graphics.Image; |
13 | |
14 | import de.uka.ipd.sdq.pcm.gmf.allocation.part.PalladioComponentModelAllocationDiagramEditorPlugin; |
15 | |
16 | /** |
17 | * @generated |
18 | */ |
19 | public class PalladioComponentModelSheetLabelProvider extends |
20 | DecoratingLabelProvider { |
21 | |
22 | /** |
23 | * @generated |
24 | */ |
25 | public PalladioComponentModelSheetLabelProvider() { |
26 | super(new AdapterFactoryLabelProvider( |
27 | PalladioComponentModelAllocationDiagramEditorPlugin |
28 | .getInstance().getItemProvidersAdapterFactory()), null); |
29 | } |
30 | |
31 | /** |
32 | * @generated |
33 | */ |
34 | public String getText(Object element) { |
35 | Object selected = unwrap(element); |
36 | return super.getText(selected); |
37 | } |
38 | |
39 | /** |
40 | * @generated |
41 | */ |
42 | public Image getImage(Object element) { |
43 | return super.getImage(unwrap(element)); |
44 | } |
45 | |
46 | /** |
47 | * @generated |
48 | */ |
49 | private Object unwrap(Object element) { |
50 | if (element instanceof IStructuredSelection) { |
51 | return unwrap(((IStructuredSelection) element).getFirstElement()); |
52 | } |
53 | if (element instanceof EditPart) { |
54 | return unwrapEditPart((EditPart) element); |
55 | } |
56 | if (element instanceof IAdaptable) { |
57 | View view = (View) ((IAdaptable) element).getAdapter(View.class); |
58 | if (view != null) { |
59 | return unwrapView(view); |
60 | } |
61 | } |
62 | return element; |
63 | } |
64 | |
65 | /** |
66 | * @generated |
67 | */ |
68 | private Object unwrapEditPart(EditPart p) { |
69 | if (p.getModel() instanceof View) { |
70 | return unwrapView((View) p.getModel()); |
71 | } |
72 | return p.getModel(); |
73 | } |
74 | |
75 | /** |
76 | * @generated |
77 | */ |
78 | private Object unwrapView(View view) { |
79 | return view.getElement() == null ? view : view.getElement(); |
80 | } |
81 | |
82 | } |