]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.network.ui/src/org/simantics/district/network/ui/internal/Activator.java
9c56d543578213feaaf8b0e4160a804a295045db
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / internal / Activator.java
1 package org.simantics.district.network.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.network.ui.breakdown.SubgraphProvider;
7 import org.simantics.district.route.RouteService;
8
9 public class Activator extends AbstractUIPlugin {
10
11     public static final String PLUGIN_ID = "org.simantics.district.network.ui";
12
13     private static Activator instance;
14     private static BundleContext context;
15
16     private ServiceTracker<SubgraphProvider, SubgraphProvider> subgraphProviderTracker;
17     private ServiceTracker<RouteService, RouteService> routeServiceTracker;
18
19     @Override
20     public void start(BundleContext context) throws Exception {
21         Activator.instance = this;
22         Activator.context = context;
23
24         subgraphProviderTracker = new ServiceTracker<>(context, SubgraphProvider.class.getName(), null);
25         subgraphProviderTracker.open();
26         routeServiceTracker = new ServiceTracker<>(context, RouteService.class.getName(), null);
27         routeServiceTracker.open();
28     }
29
30     @Override
31     public void stop(BundleContext context) throws Exception {
32         subgraphProviderTracker.close();
33         routeServiceTracker.close();
34
35         Activator.instance = null;
36         Activator.context = null;
37     }
38
39     public static Activator getInstance() {
40         return instance;
41     }
42
43     public static BundleContext getContext() {
44         return context;
45     }
46
47     public SubgraphProvider[] getSubgraphProviders() {
48         return subgraphProviderTracker.getServices(new SubgraphProvider[0]);
49     }
50
51     public RouteService getRouteService() {
52         return routeServiceTracker.getService();
53     }
54
55 }