1 | /* |
2 | *Copyright 2007, SDQ, IPD, Uni Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.composite.part; |
5 | |
6 | import java.util.ArrayList; |
7 | import java.util.List; |
8 | |
9 | import org.eclipse.core.runtime.IPath; |
10 | import org.eclipse.core.runtime.IStatus; |
11 | import org.eclipse.core.runtime.Path; |
12 | import org.eclipse.core.runtime.Platform; |
13 | import org.eclipse.core.runtime.Status; |
14 | import org.eclipse.emf.common.notify.AdapterFactory; |
15 | import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; |
16 | import org.eclipse.emf.edit.provider.ComposedAdapterFactory; |
17 | import org.eclipse.emf.edit.provider.IItemLabelProvider; |
18 | import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory; |
19 | import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory; |
20 | import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry; |
21 | import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint; |
22 | import org.eclipse.jface.resource.ImageDescriptor; |
23 | import org.eclipse.swt.graphics.Image; |
24 | import org.eclipse.ui.plugin.AbstractUIPlugin; |
25 | import org.osgi.framework.BundleContext; |
26 | |
27 | import de.uka.ipd.sdq.identifier.provider.IdentifierItemProviderAdapterFactory; |
28 | import de.uka.ipd.sdq.pcm.allocation.provider.AllocationItemProviderAdapterFactory; |
29 | import de.uka.ipd.sdq.pcm.core.composition.provider.CompositionItemProviderAdapterFactory; |
30 | |
31 | import de.uka.ipd.sdq.pcm.core.entity.provider.EntityItemProviderAdapterFactory; |
32 | import de.uka.ipd.sdq.pcm.core.provider.CoreItemProviderAdapterFactory; |
33 | import de.uka.ipd.sdq.pcm.parameter.provider.ParameterItemProviderAdapterFactory; |
34 | import de.uka.ipd.sdq.pcm.protocol.provider.ProtocolItemProviderAdapterFactory; |
35 | import de.uka.ipd.sdq.pcm.provider.PcmItemProviderAdapterFactory; |
36 | import de.uka.ipd.sdq.pcm.qosannotations.provider.QosannotationsItemProviderAdapterFactory; |
37 | import de.uka.ipd.sdq.pcm.qosannotations.qos_performance.provider.Qos_performanceItemProviderAdapterFactory; |
38 | import de.uka.ipd.sdq.pcm.qosannotations.qos_reliability.provider.Qos_reliabilityItemProviderAdapterFactory; |
39 | import de.uka.ipd.sdq.pcm.reliability.provider.ReliabilityItemProviderAdapterFactory; |
40 | import de.uka.ipd.sdq.pcm.repository.provider.RepositoryItemProviderAdapterFactory; |
41 | import de.uka.ipd.sdq.pcm.resourceenvironment.provider.ResourceenvironmentItemProviderAdapterFactory; |
42 | import de.uka.ipd.sdq.pcm.resourcetype.provider.ResourcetypeItemProviderAdapterFactory; |
43 | import de.uka.ipd.sdq.pcm.seff.provider.SeffItemProviderAdapterFactory; |
44 | import de.uka.ipd.sdq.pcm.seff.seff_performance.provider.Seff_performanceItemProviderAdapterFactory; |
45 | import de.uka.ipd.sdq.pcm.seff.seff_reliability.provider.Seff_reliabilityItemProviderAdapterFactory; |
46 | import de.uka.ipd.sdq.pcm.subsystem.provider.SubsystemItemProviderAdapterFactory; |
47 | import de.uka.ipd.sdq.pcm.system.provider.SystemItemProviderAdapterFactory; |
48 | import de.uka.ipd.sdq.pcm.usagemodel.provider.UsagemodelItemProviderAdapterFactory; |
49 | import de.uka.ipd.sdq.pcmbench.ui.provider.PalladioItemProviderAdapterFactory; |
50 | import de.uka.ipd.sdq.probfunction.provider.ProbfunctionItemProviderAdapterFactory; |
51 | import de.uka.ipd.sdq.stoex.provider.StoexItemProviderAdapterFactory; |
52 | import de.uka.ipd.sdq.units.provider.UnitsItemProviderAdapterFactory; |
53 | |
54 | /** |
55 | * @generated |
56 | */ |
57 | public class PalladioComponentModelComposedStructureDiagramEditorPlugin extends |
58 | AbstractUIPlugin { |
59 | |
60 | /** |
61 | * @generated |
62 | */ |
63 | public static final String ID = "de.uka.ipd.sdq.pcm.gmf.composite"; //$NON-NLS-1$ |
64 | |
65 | /** |
66 | * @generated |
67 | */ |
68 | public static final PreferencesHint DIAGRAM_PREFERENCES_HINT = new PreferencesHint( |
69 | ID); |
70 | |
71 | /** |
72 | * @generated |
73 | */ |
74 | private static PalladioComponentModelComposedStructureDiagramEditorPlugin instance; |
75 | |
76 | /** |
77 | * @generated not |
78 | */ |
79 | private AdapterFactory adapterFactory; |
80 | |
81 | /** |
82 | * @generated |
83 | */ |
84 | private PalladioComponentModelDocumentProvider documentProvider; |
85 | |
86 | /** |
87 | * @generated |
88 | */ |
89 | public PalladioComponentModelComposedStructureDiagramEditorPlugin() { |
90 | } |
91 | |
92 | /** |
93 | * @generated |
94 | */ |
95 | public void start(BundleContext context) throws Exception { |
96 | super.start(context); |
97 | instance = this; |
98 | PreferencesHint.registerPreferenceStore(DIAGRAM_PREFERENCES_HINT, |
99 | getPreferenceStore()); |
100 | adapterFactory = createAdapterFactory(); |
101 | } |
102 | |
103 | /** |
104 | * @generated not |
105 | */ |
106 | public void stop(BundleContext context) throws Exception { |
107 | ((PalladioItemProviderAdapterFactory) adapterFactory).dispose(); |
108 | adapterFactory = null; |
109 | instance = null; |
110 | super.stop(context); |
111 | } |
112 | |
113 | /** |
114 | * @generated |
115 | */ |
116 | public static PalladioComponentModelComposedStructureDiagramEditorPlugin getInstance() { |
117 | return instance; |
118 | } |
119 | |
120 | /** |
121 | * @generated not |
122 | */ |
123 | protected AdapterFactory createAdapterFactory() { |
124 | List factories = new ArrayList(); |
125 | fillItemProviderFactories(factories); |
126 | ComposedAdapterFactory caf = new ComposedAdapterFactory(factories) { |
127 | |
128 | @Override |
129 | public ComposeableAdapterFactory getRootAdapterFactory() { |
130 | // TODO Auto-generated method stub |
131 | return (PalladioItemProviderAdapterFactory) adapterFactory; |
132 | } |
133 | |
134 | }; |
135 | return new PalladioItemProviderAdapterFactory(caf); |
136 | } |
137 | |
138 | /** |
139 | * @generated |
140 | */ |
141 | protected void fillItemProviderFactories(List factories) { |
142 | factories.add(new PcmItemProviderAdapterFactory()); |
143 | factories.add(new CoreItemProviderAdapterFactory()); |
144 | factories.add(new EntityItemProviderAdapterFactory()); |
145 | factories.add(new CompositionItemProviderAdapterFactory()); |
146 | factories.add(new UsagemodelItemProviderAdapterFactory()); |
147 | factories.add(new RepositoryItemProviderAdapterFactory()); |
148 | factories.add(new ResourcetypeItemProviderAdapterFactory()); |
149 | factories.add(new ProtocolItemProviderAdapterFactory()); |
150 | factories.add(new ParameterItemProviderAdapterFactory()); |
151 | factories.add(new ReliabilityItemProviderAdapterFactory()); |
152 | factories.add(new SeffItemProviderAdapterFactory()); |
153 | factories |
154 | .add(new de.uka.ipd.sdq.pcm.seff.seff_performance.provider.Seff_performanceItemProviderAdapterFactory()); |
155 | factories |
156 | .add(new de.uka.ipd.sdq.pcm.seff.seff_reliability.provider.Seff_reliabilityItemProviderAdapterFactory()); |
157 | factories.add(new QosannotationsItemProviderAdapterFactory()); |
158 | factories |
159 | .add(new de.uka.ipd.sdq.pcm.qosannotations.qos_performance.provider.Qos_performanceItemProviderAdapterFactory()); |
160 | factories |
161 | .add(new de.uka.ipd.sdq.pcm.qosannotations.qos_reliability.provider.Qos_reliabilityItemProviderAdapterFactory()); |
162 | factories.add(new SystemItemProviderAdapterFactory()); |
163 | factories.add(new ResourceenvironmentItemProviderAdapterFactory()); |
164 | factories.add(new AllocationItemProviderAdapterFactory()); |
165 | factories.add(new SubsystemItemProviderAdapterFactory()); |
166 | factories.add(new IdentifierItemProviderAdapterFactory()); |
167 | factories.add(new ProbfunctionItemProviderAdapterFactory()); |
168 | factories.add(new StoexItemProviderAdapterFactory()); |
169 | factories.add(new UnitsItemProviderAdapterFactory()); |
170 | factories.add(new ResourceItemProviderAdapterFactory()); |
171 | factories.add(new ReflectiveItemProviderAdapterFactory()); |
172 | } |
173 | |
174 | /** |
175 | * @generated |
176 | */ |
177 | public AdapterFactory getItemProvidersAdapterFactory() { |
178 | return adapterFactory; |
179 | } |
180 | |
181 | /** |
182 | * @generated |
183 | */ |
184 | public ImageDescriptor getItemImageDescriptor(Object item) { |
185 | IItemLabelProvider labelProvider = (IItemLabelProvider) adapterFactory |
186 | .adapt(item, IItemLabelProvider.class); |
187 | if (labelProvider != null) { |
188 | return ExtendedImageRegistry.getInstance().getImageDescriptor( |
189 | labelProvider.getImage(item)); |
190 | } |
191 | return null; |
192 | } |
193 | |
194 | /** |
195 | * Returns an image descriptor for the image file at the given |
196 | * plug-in relative path. |
197 | * |
198 | * @generated |
199 | * @param path the path |
200 | * @return the image descriptor |
201 | */ |
202 | public static ImageDescriptor getBundledImageDescriptor(String path) { |
203 | return AbstractUIPlugin.imageDescriptorFromPlugin(ID, path); |
204 | } |
205 | |
206 | /** |
207 | * Respects images residing in any plug-in. If path is relative, |
208 | * then this bundle is looked up for the image, otherwise, for absolute |
209 | * path, first segment is taken as id of plug-in with image |
210 | * |
211 | * @generated |
212 | * @param path the path to image, either absolute (with plug-in id as first segment), or relative for bundled images |
213 | * @return the image descriptor |
214 | */ |
215 | public static ImageDescriptor findImageDescriptor(String path) { |
216 | final IPath p = new Path(path); |
217 | if (p.isAbsolute() && p.segmentCount() > 1) { |
218 | return AbstractUIPlugin.imageDescriptorFromPlugin(p.segment(0), p |
219 | .removeFirstSegments(1).makeAbsolute().toString()); |
220 | } else { |
221 | return getBundledImageDescriptor(p.makeAbsolute().toString()); |
222 | } |
223 | } |
224 | |
225 | /** |
226 | * Returns string from plug-in's resource bundle |
227 | * @generated |
228 | */ |
229 | public static String getString(String key) { |
230 | return Platform.getResourceString(getInstance().getBundle(), "%" + key); //$NON-NLS-1$ |
231 | } |
232 | |
233 | /** |
234 | * Returns an image for the image file at the given plug-in relative path. |
235 | * Client do not need to dispose this image. Images will be disposed automatically. |
236 | * |
237 | * @generated |
238 | * @param path the path |
239 | * @return image instance |
240 | */ |
241 | public Image getBundledImage(String path) { |
242 | Image image = getImageRegistry().get(path); |
243 | if (image == null) { |
244 | getImageRegistry().put(path, getBundledImageDescriptor(path)); |
245 | image = getImageRegistry().get(path); |
246 | } |
247 | return image; |
248 | } |
249 | |
250 | /** |
251 | * @generated |
252 | */ |
253 | public PalladioComponentModelDocumentProvider getDocumentProvider() { |
254 | if (documentProvider == null) { |
255 | documentProvider = new PalladioComponentModelDocumentProvider(); |
256 | } |
257 | return documentProvider; |
258 | } |
259 | |
260 | /** |
261 | * @generated |
262 | */ |
263 | public void logError(String error) { |
264 | logError(error, null); |
265 | } |
266 | |
267 | /** |
268 | * @param throwable actual error or null could be passed |
269 | * @generated |
270 | */ |
271 | public void logError(String error, Throwable throwable) { |
272 | if (error == null && throwable != null) { |
273 | error = throwable.getMessage(); |
274 | } |
275 | getLog() |
276 | .log( |
277 | new Status( |
278 | IStatus.ERROR, |
279 | PalladioComponentModelComposedStructureDiagramEditorPlugin.ID, |
280 | IStatus.OK, error, throwable)); |
281 | debug(error, throwable); |
282 | } |
283 | |
284 | /** |
285 | * @generated |
286 | */ |
287 | public void logInfo(String message) { |
288 | logInfo(message, null); |
289 | } |
290 | |
291 | /** |
292 | * @param throwable actual error or null could be passed |
293 | * @generated |
294 | */ |
295 | public void logInfo(String message, Throwable throwable) { |
296 | if (message == null && throwable != null) { |
297 | message = throwable.getMessage(); |
298 | } |
299 | getLog() |
300 | .log( |
301 | new Status( |
302 | IStatus.INFO, |
303 | PalladioComponentModelComposedStructureDiagramEditorPlugin.ID, |
304 | IStatus.OK, message, throwable)); |
305 | debug(message, throwable); |
306 | } |
307 | |
308 | /** |
309 | * @generated |
310 | */ |
311 | private void debug(String message, Throwable throwable) { |
312 | if (!isDebugging()) { |
313 | return; |
314 | } |
315 | if (message != null) { |
316 | System.err.println(message); |
317 | } |
318 | if (throwable != null) { |
319 | throwable.printStackTrace(); |
320 | } |
321 | } |
322 | } |