1 | package de.uka.ipd.sdq.pcmbench.tabs; |
2 | import org.eclipse.emf.common.notify.Notification; |
3 | import org.eclipse.emf.ecore.EObject; |
4 | import org.eclipse.emf.edit.provider.ComposedAdapterFactory; |
5 | import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory; |
6 | import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory; |
7 | import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; |
8 | import org.eclipse.jface.viewers.ILabelProvider; |
9 | import org.eclipse.jface.viewers.ILabelProviderListener; |
10 | import org.eclipse.jface.viewers.IStructuredSelection; |
11 | import org.eclipse.jface.viewers.LabelProvider; |
12 | import org.eclipse.swt.graphics.Image; |
13 | |
14 | import de.uka.ipd.sdq.pcm.core.entity.Entity; |
15 | import de.uka.ipd.sdq.pcm.repository.provider.RepositoryItemProviderAdapterFactory; |
16 | import de.uka.ipd.sdq.pcm.seff.provider.SeffItemProviderAdapterFactory; |
17 | |
18 | |
19 | /** |
20 | * @author Snowball |
21 | * An Label Provider (see the EMF bible for details on LabelProvider) for the labels of the heading |
22 | * of any single tab sheet. |
23 | * This label provider mostly delegates the calls to it to the generated |
24 | * LabelProvider in the PCM.Edit plugin. |
25 | */ |
26 | public class PropertyLabelProvider |
27 | extends LabelProvider |
28 | implements |
29 | ILabelProvider { |
30 | |
31 | private ComposedAdapterFactory adapterFactory; |
32 | |
33 | private AdapterFactoryLabelProvider labelProvider = null; |
34 | |
35 | /** |
36 | * Constructor. Sets up a LabelProvider by using an adapter factory |
37 | * provided by the generated PCM.Edit plugin |
38 | */ |
39 | public PropertyLabelProvider() { |
40 | super(); |
41 | adapterFactory = new ComposedAdapterFactory(); |
42 | adapterFactory |
43 | .addAdapterFactory(new ResourceItemProviderAdapterFactory()); |
44 | adapterFactory |
45 | .addAdapterFactory(new RepositoryItemProviderAdapterFactory()); |
46 | adapterFactory |
47 | .addAdapterFactory(new SeffItemProviderAdapterFactory()); |
48 | adapterFactory |
49 | .addAdapterFactory(new ReflectiveItemProviderAdapterFactory()); |
50 | labelProvider = new AdapterFactoryLabelProvider(adapterFactory) |
51 | { |
52 | |
53 | /* (non-Javadoc) |
54 | * @see org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider#notifyChanged(org.eclipse.emf.common.notify.Notification) |
55 | */ |
56 | @Override |
57 | public void notifyChanged(Notification notification) { |
58 | super.notifyChanged(notification); |
59 | fireLabelProviderChanged(); |
60 | } |
61 | |
62 | }; |
63 | |
64 | } |
65 | |
66 | /* (non-Javadoc) |
67 | * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) |
68 | * GetImage is delegated to the PCM.Edit label provider |
69 | */ |
70 | @Override |
71 | public Image getImage(Object element) { |
72 | if (element instanceof IStructuredSelection) { |
73 | IStructuredSelection selection = (IStructuredSelection) element; |
74 | if (selection.getFirstElement() instanceof EObject) { |
75 | EObject selectedObject = (EObject) selection.getFirstElement(); |
76 | return labelProvider.getImage(selectedObject); |
77 | } |
78 | } |
79 | return super.getImage(element); |
80 | } |
81 | |
82 | /* (non-Javadoc) |
83 | * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) |
84 | * GetText delegated to the PCM.Edit LabelProvider. If the object is an |
85 | * entity we change the label to include the UUID of the object |
86 | */ |
87 | @Override |
88 | public String getText(Object element) { |
89 | if (element instanceof IStructuredSelection) { |
90 | IStructuredSelection selection = (IStructuredSelection) element; |
91 | if (selection.getFirstElement() instanceof EObject) { |
92 | EObject selectedObject = (EObject) selection.getFirstElement(); |
93 | String result = labelProvider.getText(selectedObject); |
94 | if (selectedObject instanceof Entity) |
95 | { |
96 | Entity e = (Entity)selectedObject; |
97 | result = e.getEntityName() + " [ID: " + e.getId() +"]"; |
98 | } |
99 | return result; |
100 | } |
101 | } |
102 | return super.getText(element); |
103 | } |
104 | |
105 | @Override |
106 | public void dispose() { |
107 | labelProvider.dispose(); |
108 | } |
109 | |
110 | /* (non-Javadoc) |
111 | * @see org.eclipse.jface.viewers.LabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener) |
112 | */ |
113 | @Override |
114 | public void addListener(ILabelProviderListener listener) { |
115 | super.addListener(listener); |
116 | labelProvider.addListener(listener); |
117 | } |
118 | |
119 | /* (non-Javadoc) |
120 | * @see org.eclipse.jface.viewers.LabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener) |
121 | */ |
122 | @Override |
123 | public void removeListener(ILabelProviderListener listener) { |
124 | labelProvider.removeListener(listener); |
125 | super.removeListener(listener); |
126 | } |
127 | |
128 | } |