1 | package org.modelica.mdt.ui; |
---|
2 | |
---|
3 | import org.eclipse.swt.widgets.Display; |
---|
4 | import org.eclipse.ui.plugin.*; |
---|
5 | import org.eclipse.core.runtime.IAdapterFactory; |
---|
6 | import org.eclipse.core.runtime.IAdapterManager; |
---|
7 | import org.eclipse.core.runtime.Platform; |
---|
8 | import org.modelica.mdt.core.IModelicaElement; |
---|
9 | import org.osgi.framework.BundleContext; |
---|
10 | |
---|
11 | /** |
---|
12 | * The main plugin class |
---|
13 | */ |
---|
14 | public class Plugin extends AbstractUIPlugin |
---|
15 | { |
---|
16 | |
---|
17 | /* the shared instance */ |
---|
18 | private static Plugin plugin; |
---|
19 | |
---|
20 | public Plugin() |
---|
21 | { |
---|
22 | plugin = this; |
---|
23 | } |
---|
24 | |
---|
25 | /** |
---|
26 | * This method is called upon plug-in activation |
---|
27 | */ |
---|
28 | public void start(BundleContext context) throws Exception |
---|
29 | { |
---|
30 | super.start(context); |
---|
31 | |
---|
32 | IAdapterManager manager = Platform.getAdapterManager(); |
---|
33 | IAdapterFactory factory = new ModelicaElementAdapterFactory(); |
---|
34 | manager.registerAdapters(factory, IModelicaElement.class); |
---|
35 | } |
---|
36 | |
---|
37 | /** |
---|
38 | * This method is called when the plug-in is stopped |
---|
39 | */ |
---|
40 | public void stop(BundleContext context) throws Exception |
---|
41 | { |
---|
42 | super.stop(context); |
---|
43 | plugin = null; |
---|
44 | } |
---|
45 | |
---|
46 | /** |
---|
47 | * Returns the shared instance. |
---|
48 | */ |
---|
49 | public static Plugin getDefault() |
---|
50 | { |
---|
51 | return plugin; |
---|
52 | } |
---|
53 | |
---|
54 | /** |
---|
55 | * Returns the standard display to be used. The method first checks, if |
---|
56 | * the thread calling this method has an associated display. If so, this |
---|
57 | * display is returned. Otherwise the method returns the default display. |
---|
58 | */ |
---|
59 | public static Display getStandardDisplay() |
---|
60 | { |
---|
61 | Display display; |
---|
62 | display = Display.getCurrent(); |
---|
63 | if (display == null) |
---|
64 | display = Display.getDefault(); |
---|
65 | return display; |
---|
66 | } |
---|
67 | } |
---|