]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/Activator.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.diagram.profile / src / org / simantics / diagram / profile / view / Activator.java
1 package org.simantics.diagram.profile.view;\r
2 \r
3 import java.net.URL;\r
4 \r
5 import org.eclipse.ui.plugin.AbstractUIPlugin;\r
6 import org.osgi.framework.BundleContext;\r
7 import org.osgi.util.tracker.ServiceTracker;\r
8 \r
9 public class Activator extends AbstractUIPlugin {\r
10 \r
11     // The plug-in ID\r
12     public static final String    PLUGIN_ID = "org.simantics.diagram.profile";\r
13 \r
14     // The shared instance\r
15     private static Activator      plugin;\r
16 \r
17     private BundleContext         bundleContext;\r
18 \r
19     private ServiceTracker<?, ?>  logTracker;\r
20 \r
21     /**\r
22      * The constructor\r
23      */\r
24     public Activator() {\r
25     }\r
26 \r
27     /* (non-Javadoc)\r
28      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)\r
29      */\r
30     @Override\r
31     public void start(BundleContext context) throws Exception {\r
32         super.start(context);\r
33         this.bundleContext = context;\r
34         plugin = this;\r
35     }\r
36 \r
37     /* (non-Javadoc)\r
38      * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)\r
39      */\r
40     @Override\r
41     public void stop(BundleContext context) throws Exception {\r
42         if (logTracker != null) {\r
43             logTracker.close();\r
44             logTracker = null;\r
45         }\r
46 \r
47         this.bundleContext = null;\r
48         plugin = null;\r
49         super.stop(context);\r
50     }\r
51 \r
52     /**\r
53      * Returns the shared instance\r
54      *\r
55      * @return the shared instance\r
56      */\r
57     public static Activator getDefault() {\r
58         return plugin;\r
59     }\r
60 \r
61     public BundleContext getContext() {\r
62         return bundleContext;\r
63     }\r
64 \r
65     public static URL getDefaultResource(String name) {\r
66         Activator plugin = getDefault();\r
67         if(plugin == null) throw new IllegalStateException("The plugin is not active.");\r
68         return plugin.getBundle().getResource(name);\r
69     }\r
70 \r
71 }\r