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