]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.route.ui/src/org/simantics/district/route/ui/internal/Activator.java
Initial version of the district network Routes view.
[simantics/district.git] / org.simantics.district.route.ui / src / org / simantics / district / route / ui / internal / Activator.java
1 package org.simantics.district.route.ui.internal;
2
3 import org.eclipse.ui.plugin.AbstractUIPlugin;
4 import org.osgi.framework.BundleContext;
5 import org.osgi.util.tracker.ServiceTracker;
6 import org.simantics.district.route.RouteService;
7
8 /**
9  * The activator class controls the plug-in life cycle
10  */
11 public class Activator extends AbstractUIPlugin {
12
13     // The plug-in ID
14     public static final String PLUGIN_ID = "org.simantics.district.route.ui"; //$NON-NLS-1$
15
16     // The shared instance
17     private static Activator plugin;
18
19     private ServiceTracker<RouteService, ?> routeServiceTracker;
20
21     /*
22      * (non-Javadoc)
23      * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
24      */
25     public void start(BundleContext context) throws Exception {
26         super.start(context);
27         plugin = this;
28
29         // create a tracker and track the service
30         routeServiceTracker = new ServiceTracker<>(context, RouteService.class.getName(), null);
31         routeServiceTracker.open();
32     }
33
34     /*
35      * (non-Javadoc)
36      * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
37      */
38     public void stop(BundleContext context) throws Exception {
39         // close the service tracker
40         routeServiceTracker.close();
41         routeServiceTracker = null;
42
43         plugin = null;
44         super.stop(context);
45     }
46
47     /**
48      * Returns the shared instance
49      *
50      * @return the shared instance
51      */
52     public static Activator getDefault() {
53         return plugin;
54     }
55
56     public RouteService getRouteService() {
57         return (RouteService) routeServiceTracker.getService();
58     }
59
60 }