]> gerrit.simantics Code Review - simantics/platform.git/blob
23d593c70001d64297bda5dd037816e44f533722
[simantics/platform.git] /
1 package org.simantics.ui.workspace.tracker.internal;
2
3 import org.eclipse.core.runtime.preferences.InstanceScope;
4 import org.eclipse.jface.preference.IPreferenceStore;
5 import org.eclipse.ui.preferences.ScopedPreferenceStore;
6 import org.osgi.framework.BundleActivator;
7 import org.osgi.framework.BundleContext;
8 import org.osgi.util.tracker.ServiceTracker;
9 import org.simantics.filesystem.services.sizetracker.DirectorySizeService;
10
11 /**
12  * @author Tuukka Lehtonen
13  * @since 1.31.0
14  */
15 public class Activator implements BundleActivator {
16
17         private static Activator instance;
18         private static BundleContext context;
19         private ServiceTracker<DirectorySizeService, DirectorySizeService> tracker;
20         private IPreferenceStore preferenceStore;
21
22         static BundleContext getContext() {
23                 return context;
24         }
25
26         /*
27          * (non-Javadoc)
28          * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
29          */
30         public void start(BundleContext bundleContext) throws Exception {
31                 Activator.instance = this;
32                 Activator.context = bundleContext;
33                 tracker = new ServiceTracker<>(bundleContext, DirectorySizeService.class, null);
34                 tracker.open();
35         }
36
37         /*
38          * (non-Javadoc)
39          * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
40          */
41         public void stop(BundleContext bundleContext) throws Exception {
42                 tracker.close();
43                 Activator.context = null;
44                 Activator.instance = null;
45         }
46
47         /**
48          * @return <code>null</code> if service is no longer available
49          */
50         public DirectorySizeService getDirectorySizeService() {
51                 return tracker.getService();
52         }
53
54         public BundleContext getBundleContext() {
55                 return context;
56         }
57
58         public IPreferenceStore getPreferenceStore() {
59                 if (preferenceStore == null) {
60                         preferenceStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, context.getBundle().getSymbolicName());
61                 }
62                 return preferenceStore;
63         }
64
65         public static Activator getDefault() {
66                 return instance;
67         }
68
69 }