1 package eu
.etaxonomy
.taxeditor
;
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
;
16 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
19 * The activator class controls the plug-in life cycle
23 public class TaxonomicEditorPlugin
extends AbstractUIPlugin
{
25 private static final Logger logger
= Logger
.getLogger(TaxonomicEditorPlugin
.class);
28 /** Constant <code>PLUGIN_ID="eu.etaxonomy.taxeditor.application"</code> */
29 public static final String PLUGIN_ID
= "eu.etaxonomy.taxeditor.application";
31 // The shared instance
32 private static TaxonomicEditorPlugin plugin
;
34 private PackageAdmin packageAdmin
;
36 private ServiceReference
<?
> packageAdminRef
;
38 /** Constant <code>bundleContext</code> */
39 protected static BundleContext bundleContext
;
42 private ServiceRegistration
<?
> policyRegistration
;
44 private ProvisioningSession session
;
45 private ProvisioningUI ui
;
47 // private CloudPolicy policy;
52 public TaxonomicEditorPlugin() {
56 public void start(BundleContext context
) throws Exception
{
60 bundleContext
= context
;
62 packageAdminRef
= bundleContext
.getServiceReference(PackageAdmin
.class.getName());
63 packageAdmin
= (PackageAdmin
) bundleContext
.getService(packageAdminRef
);
65 logger
.debug("Taxonomic Editor started.");
68 private Bundle
getBundle(String symbolicName
) {
69 if (packageAdmin
== null) {
72 Bundle
[] bundles
= packageAdmin
.getBundles(symbolicName
, null);
73 if (bundles
== null) {
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) {
86 public void stop(BundleContext context
) throws Exception
{
89 MessagingUtils
.info("Taxonomic Editor stopped.");
93 * Returns the shared instance
95 * @return the shared instance
97 public static TaxonomicEditorPlugin
getDefault() {
101 public static BundleContext
getContext() {
102 return bundleContext
;
105 public ProvisioningUI
getProvisioningUI() {
108 ServiceReference
<?
> reference
= bundleContext
.getServiceReference(IProvisioningAgent
.SERVICE_NAME
);
109 IProvisioningAgent agent
= (IProvisioningAgent
) bundleContext
.getService(reference
);
111 session
= new ProvisioningSession(agent
);
113 Policy policy
= null;// = (Policy) ServiceHelper.getService(ProvUIActivator.getContext(), Policy.class.getName());
114 if (policy
== null) {
115 policy
= new Policy();
118 ui
= new ProvisioningUI(session
, IProfileRegistry
.SELF
, policy
);