]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/internal/Activator.java
Merge remote-tracking branch 'origin/release/1.37.0' into release/1.35.1
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / internal / Activator.java
index 1e7a4d512fae8ba7216410f91c6adec6578416f9..9c56d543578213feaaf8b0e4160a804a295045db 100644 (file)
@@ -1,18 +1,55 @@
-package org.simantics.district.network.ui.internal;\r
-\r
-import org.osgi.framework.BundleActivator;\r
-import org.osgi.framework.BundleContext;\r
-\r
-public class Activator implements BundleActivator {\r
-\r
-    @Override\r
-    public void start(BundleContext context) throws Exception {\r
-\r
-    }\r
-\r
-    @Override\r
-    public void stop(BundleContext context) throws Exception {\r
-\r
-    }\r
-\r
-}\r
+package org.simantics.district.network.ui.internal;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
+import org.simantics.district.network.ui.breakdown.SubgraphProvider;
+import org.simantics.district.route.RouteService;
+
+public class Activator extends AbstractUIPlugin {
+
+    public static final String PLUGIN_ID = "org.simantics.district.network.ui";
+
+    private static Activator instance;
+    private static BundleContext context;
+
+    private ServiceTracker<SubgraphProvider, SubgraphProvider> subgraphProviderTracker;
+    private ServiceTracker<RouteService, RouteService> routeServiceTracker;
+
+    @Override
+    public void start(BundleContext context) throws Exception {
+        Activator.instance = this;
+        Activator.context = context;
+
+        subgraphProviderTracker = new ServiceTracker<>(context, SubgraphProvider.class.getName(), null);
+        subgraphProviderTracker.open();
+        routeServiceTracker = new ServiceTracker<>(context, RouteService.class.getName(), null);
+        routeServiceTracker.open();
+    }
+
+    @Override
+    public void stop(BundleContext context) throws Exception {
+        subgraphProviderTracker.close();
+        routeServiceTracker.close();
+
+        Activator.instance = null;
+        Activator.context = null;
+    }
+
+    public static Activator getInstance() {
+        return instance;
+    }
+
+    public static BundleContext getContext() {
+        return context;
+    }
+
+    public SubgraphProvider[] getSubgraphProviders() {
+        return subgraphProviderTracker.getServices(new SubgraphProvider[0]);
+    }
+
+    public RouteService getRouteService() {
+        return routeServiceTracker.getService();
+    }
+
+}