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