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;
12 * @author Tuukka Lehtonen
15 public class Activator implements BundleActivator {
17 private static Activator instance;
18 private static BundleContext context;
19 private ServiceTracker<DirectorySizeService, DirectorySizeService> tracker;
20 private IPreferenceStore preferenceStore;
22 static BundleContext getContext() {
28 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
30 public void start(BundleContext bundleContext) throws Exception {
31 Activator.instance = this;
32 Activator.context = bundleContext;
33 tracker = new ServiceTracker<>(bundleContext, DirectorySizeService.class, null);
39 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
41 public void stop(BundleContext bundleContext) throws Exception {
43 Activator.context = null;
44 Activator.instance = null;
48 * @return <code>null</code> if service is no longer available
50 public DirectorySizeService getDirectorySizeService() {
51 return tracker.getService();
54 public BundleContext getBundleContext() {
58 public IPreferenceStore getPreferenceStore() {
59 if (preferenceStore == null) {
60 preferenceStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, context.getBundle().getSymbolicName());
62 return preferenceStore;
65 public static Activator getDefault() {