1
|
package eu.etaxonomy.taxeditor;
|
2
|
|
3
|
import org.apache.log4j.Logger;
|
4
|
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
5
|
import org.osgi.framework.Bundle;
|
6
|
import org.osgi.framework.BundleContext;
|
7
|
import org.osgi.framework.ServiceReference;
|
8
|
import org.osgi.service.packageadmin.PackageAdmin;
|
9
|
|
10
|
/**
|
11
|
* The activator class controls the plug-in life cycle
|
12
|
*/
|
13
|
public class TaxonomicEditorPlugin extends AbstractUIPlugin {
|
14
|
private static final Logger logger = Logger
|
15
|
.getLogger(TaxonomicEditorPlugin.class);
|
16
|
|
17
|
// The plug-in ID
|
18
|
public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.application";
|
19
|
|
20
|
// The shared instance
|
21
|
private static TaxonomicEditorPlugin plugin;
|
22
|
|
23
|
private PackageAdmin packageAdmin;
|
24
|
|
25
|
private ServiceReference packageAdminRef;
|
26
|
|
27
|
private BundleContext bundleContext;
|
28
|
|
29
|
/**
|
30
|
* The constructor
|
31
|
*/
|
32
|
public TaxonomicEditorPlugin() {
|
33
|
}
|
34
|
|
35
|
/*
|
36
|
* (non-Javadoc)
|
37
|
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
|
38
|
*/
|
39
|
public void start(BundleContext context) throws Exception {
|
40
|
super.start(context);
|
41
|
plugin = this;
|
42
|
|
43
|
bundleContext = context;
|
44
|
|
45
|
// this should enable automatic updating. Not working at the moment
|
46
|
packageAdminRef = bundleContext.getServiceReference(PackageAdmin.class.getName());
|
47
|
packageAdmin = (PackageAdmin) bundleContext.getService(packageAdminRef);
|
48
|
|
49
|
// XXX start up the p2 infrastructure. Normally the p2 UI class library does
|
50
|
// this, but we are running without UI.
|
51
|
getBundle("org.eclipse.equinox.p2.exemplarysetup").start(Bundle.START_TRANSIENT); //$NON-NLS-1$
|
52
|
getBundle("org.eclipse.equinox.frameworkadmin.equinox").start(Bundle.START_TRANSIENT); //$NON-NLS-1$
|
53
|
getBundle("org.eclipse.equinox.simpleconfigurator.manipulator").start(Bundle.START_TRANSIENT); //$NON-NLS-1$
|
54
|
|
55
|
logger.debug("Taxonomic Editor started.");
|
56
|
}
|
57
|
|
58
|
private Bundle getBundle(String symbolicName) {
|
59
|
if (packageAdmin == null)
|
60
|
return null;
|
61
|
Bundle[] bundles = packageAdmin.getBundles(symbolicName, null);
|
62
|
if (bundles == null)
|
63
|
return null;
|
64
|
// Return the first bundle that is not installed or uninstalled
|
65
|
for (int i = 0; i < bundles.length; i++) {
|
66
|
if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) {
|
67
|
return bundles[i];
|
68
|
}
|
69
|
}
|
70
|
return null;
|
71
|
}
|
72
|
|
73
|
/*
|
74
|
* (non-Javadoc)
|
75
|
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
|
76
|
*/
|
77
|
public void stop(BundleContext context) throws Exception {
|
78
|
plugin = null;
|
79
|
super.stop(context);
|
80
|
logger.debug("Taxonomic Editor stopped.");
|
81
|
}
|
82
|
|
83
|
/**
|
84
|
* Returns the shared instance
|
85
|
*
|
86
|
* @return the shared instance
|
87
|
*/
|
88
|
public static TaxonomicEditorPlugin getDefault() {
|
89
|
return plugin;
|
90
|
}
|
91
|
}
|