X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.ui.workspace.tracker%2Fsrc%2Forg%2Fsimantics%2Fui%2Fworkspace%2Ftracker%2Finternal%2FActivator.java;fp=bundles%2Forg.simantics.ui.workspace.tracker%2Fsrc%2Forg%2Fsimantics%2Fui%2Fworkspace%2Ftracker%2Finternal%2FActivator.java;h=23d593c70001d64297bda5dd037816e44f533722;hp=0000000000000000000000000000000000000000;hb=ad41b9af52c52b5ea1e9d8c6753f4e341ed40d67;hpb=26313671f3eb6e4d7f41b7a3a2505ca47d26273c diff --git a/bundles/org.simantics.ui.workspace.tracker/src/org/simantics/ui/workspace/tracker/internal/Activator.java b/bundles/org.simantics.ui.workspace.tracker/src/org/simantics/ui/workspace/tracker/internal/Activator.java new file mode 100644 index 000000000..23d593c70 --- /dev/null +++ b/bundles/org.simantics.ui.workspace.tracker/src/org/simantics/ui/workspace/tracker/internal/Activator.java @@ -0,0 +1,69 @@ +package org.simantics.ui.workspace.tracker.internal; + +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.ui.preferences.ScopedPreferenceStore; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.util.tracker.ServiceTracker; +import org.simantics.filesystem.services.sizetracker.DirectorySizeService; + +/** + * @author Tuukka Lehtonen + * @since 1.31.0 + */ +public class Activator implements BundleActivator { + + private static Activator instance; + private static BundleContext context; + private ServiceTracker tracker; + private IPreferenceStore preferenceStore; + + static BundleContext getContext() { + return context; + } + + /* + * (non-Javadoc) + * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext bundleContext) throws Exception { + Activator.instance = this; + Activator.context = bundleContext; + tracker = new ServiceTracker<>(bundleContext, DirectorySizeService.class, null); + tracker.open(); + } + + /* + * (non-Javadoc) + * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext bundleContext) throws Exception { + tracker.close(); + Activator.context = null; + Activator.instance = null; + } + + /** + * @return null if service is no longer available + */ + public DirectorySizeService getDirectorySizeService() { + return tracker.getService(); + } + + public BundleContext getBundleContext() { + return context; + } + + public IPreferenceStore getPreferenceStore() { + if (preferenceStore == null) { + preferenceStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, context.getBundle().getSymbolicName()); + } + return preferenceStore; + } + + public static Activator getDefault() { + return instance; + } + +}