1
|
package eu.etaxonomy.taxeditor;
|
2
|
|
3
|
import org.apache.log4j.Logger;
|
4
|
import org.eclipse.equinox.p2.core.IProvisioningAgent;
|
5
|
import org.eclipse.equinox.p2.engine.IProfileRegistry;
|
6
|
import org.eclipse.equinox.p2.operations.ProvisioningSession;
|
7
|
import org.eclipse.equinox.p2.ui.Policy;
|
8
|
import org.eclipse.equinox.p2.ui.ProvisioningUI;
|
9
|
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
10
|
import org.osgi.framework.Bundle;
|
11
|
import org.osgi.framework.BundleContext;
|
12
|
import org.osgi.framework.ServiceReference;
|
13
|
import org.osgi.framework.ServiceRegistration;
|
14
|
import org.osgi.service.packageadmin.PackageAdmin;
|
15
|
|
16
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
17
|
|
18
|
/**
|
19
|
* The activator class controls the plug-in life cycle
|
20
|
*
|
21
|
* @author n.hoffmann
|
22
|
*/
|
23
|
public class TaxonomicEditorPlugin extends AbstractUIPlugin {
|
24
|
|
25
|
private static final Logger logger = Logger.getLogger(TaxonomicEditorPlugin.class);
|
26
|
|
27
|
// The plug-in ID
|
28
|
/** Constant <code>PLUGIN_ID="eu.etaxonomy.taxeditor.application"</code> */
|
29
|
public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.application";
|
30
|
|
31
|
// The shared instance
|
32
|
private static TaxonomicEditorPlugin plugin;
|
33
|
|
34
|
private PackageAdmin packageAdmin;
|
35
|
|
36
|
private ServiceReference<?> packageAdminRef;
|
37
|
|
38
|
/** Constant <code>bundleContext</code> */
|
39
|
protected static BundleContext bundleContext;
|
40
|
|
41
|
|
42
|
private ServiceRegistration<?> policyRegistration;
|
43
|
|
44
|
private ProvisioningSession session;
|
45
|
private ProvisioningUI ui;
|
46
|
|
47
|
// private CloudPolicy policy;
|
48
|
|
49
|
/**
|
50
|
* The constructor
|
51
|
*/
|
52
|
public TaxonomicEditorPlugin() {
|
53
|
}
|
54
|
|
55
|
@Override
|
56
|
public void start(BundleContext context) throws Exception {
|
57
|
super.start(context);
|
58
|
|
59
|
plugin = this;
|
60
|
bundleContext = context;
|
61
|
|
62
|
packageAdminRef = bundleContext.getServiceReference(PackageAdmin.class.getName());
|
63
|
packageAdmin = (PackageAdmin) bundleContext.getService(packageAdminRef);
|
64
|
|
65
|
logger.debug("Taxonomic Editor started.");
|
66
|
}
|
67
|
|
68
|
private Bundle getBundle(String symbolicName) {
|
69
|
if (packageAdmin == null) {
|
70
|
return null;
|
71
|
}
|
72
|
Bundle[] bundles = packageAdmin.getBundles(symbolicName, null);
|
73
|
if (bundles == null) {
|
74
|
return null;
|
75
|
}
|
76
|
// Return the first bundle that is not installed or uninstalled
|
77
|
for (int i = 0; i < bundles.length; i++) {
|
78
|
if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) {
|
79
|
return bundles[i];
|
80
|
}
|
81
|
}
|
82
|
return null;
|
83
|
}
|
84
|
|
85
|
@Override
|
86
|
public void stop(BundleContext context) throws Exception {
|
87
|
plugin = null;
|
88
|
super.stop(context);
|
89
|
MessagingUtils.info("Taxonomic Editor stopped.");
|
90
|
}
|
91
|
|
92
|
/**
|
93
|
* Returns the shared instance
|
94
|
*
|
95
|
* @return the shared instance
|
96
|
*/
|
97
|
public static TaxonomicEditorPlugin getDefault() {
|
98
|
return plugin;
|
99
|
}
|
100
|
|
101
|
public static BundleContext getContext() {
|
102
|
return bundleContext;
|
103
|
}
|
104
|
|
105
|
public ProvisioningUI getProvisioningUI() {
|
106
|
|
107
|
if (ui == null) {
|
108
|
ServiceReference<?> reference = bundleContext.getServiceReference(IProvisioningAgent.SERVICE_NAME);
|
109
|
IProvisioningAgent agent = (IProvisioningAgent) bundleContext.getService(reference);
|
110
|
session = new ProvisioningSession(agent);
|
111
|
Policy policy = null;// = (Policy) ServiceHelper.getService(ProvUIActivator.getContext(), Policy.class.getName());
|
112
|
if (policy == null) {
|
113
|
policy = new Policy();
|
114
|
}
|
115
|
ui = new ProvisioningUI(session, IProfileRegistry.SELF, policy);
|
116
|
}
|
117
|
return ui;
|
118
|
}
|
119
|
}
|