1 package org.simantics.ui.workspace.tracker.internal;
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;
13 * @author Tuukka Lehtonen
16 public class Activator implements BundleActivator {
18 private static Activator instance;
19 private static BundleContext context;
20 private ServiceTracker<DirectorySizeService, DirectorySizeService> tracker;
21 private IPreferenceStore preferenceStore;
23 static BundleContext getContext() {
29 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
31 public void start(BundleContext bundleContext) throws Exception {
32 Activator.instance = this;
33 Activator.context = bundleContext;
34 tracker = new ServiceTracker<>(bundleContext, DirectorySizeService.class, null);
40 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
42 public void stop(BundleContext bundleContext) throws Exception {
44 Activator.context = null;
45 Activator.instance = null;
49 * @return <code>null</code> if service is no longer available
51 public DirectorySizeService getDirectorySizeService() {
52 return tracker.getService();
55 public BundleContext getBundleContext() {
59 public IPreferenceStore getPreferenceStore() {
60 if (preferenceStore == null) {
61 preferenceStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, IWorkspaceSizeTrackerConstants.P_NODE);
63 return preferenceStore;
66 public static Activator getDefault() {