]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/Activator.java
Merge commit 'a2a4242'
[simantics/platform.git] / bundles / org.simantics.db.procore / src / fi / vtt / simantics / procore / internal / Activator.java
1 package fi.vtt.simantics.procore.internal;
2
3 import org.eclipse.core.runtime.IPath;
4 import org.eclipse.core.runtime.IStatus;
5 import org.eclipse.core.runtime.Platform;
6 import org.osgi.framework.Bundle;
7 import org.osgi.framework.BundleActivator;
8 import org.osgi.framework.BundleContext;
9 import org.simantics.db.common.utils.Logger;
10
11 /**
12  * A bundle activator for org.simantics.db.procore that takes care of
13  * automatically finding a proper place for storing virtual graph files within
14  * the bundle metadata locations.
15  *
16  * @author Tuukka Lehtonen
17  */
18 public class Activator implements BundleActivator {
19
20     public static final String PLUGIN_ID = "org.simantics.db.procore";
21
22     // The shared instance
23     private static Activator plugin;
24
25     private Bundle bundle;
26
27     @Override
28     public void start(BundleContext context) throws Exception {
29         IPath stateLocation = Platform.getStateLocation(context.getBundle());
30         StaticSessionProperties.virtualGraphStoragePath = stateLocation.toFile();
31         this.bundle = context.getBundle();
32         plugin = this;
33     }
34
35     @Override
36     public void stop(BundleContext context) throws Exception {
37         this.bundle = null;
38         plugin = null;
39         StaticSessionProperties.virtualGraphStoragePath = null;
40     }
41
42     /**
43      * Returns the shared instance
44      *
45      * @return the shared instance
46      */
47     public static Activator getDefault() {
48         return plugin;
49     }
50
51     /**
52      * @return
53      */
54     public static void log(IStatus status) {
55         Activator a = getDefault();
56         if (a != null) {
57             // In OSGi environment
58             Platform.getLog(a.bundle).log(status);
59         } else {
60             Logger.defaultLogError(status.getMessage(), status.getException());
61         }
62     }
63
64 }