p2izing the editor
[taxeditor.git] / taxeditor-application / src / main / java / eu / etaxonomy / taxeditor / TaxonomicEditorPlugin.java
index 2d8e76703c22daf565a0093e593059695fa78ecc..76eb61673a6654e0a9f131bc9dd3d3f617d46fc3 100644 (file)
@@ -2,7 +2,10 @@ package eu.etaxonomy.taxeditor;
 
 import org.apache.log4j.Logger;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.packageadmin.PackageAdmin;
 
 /**
  * The activator class controls the plug-in life cycle
@@ -16,6 +19,12 @@ public class TaxonomicEditorPlugin extends AbstractUIPlugin {
 
        // The shared instance
        private static TaxonomicEditorPlugin plugin;
+
+       private PackageAdmin packageAdmin;
+
+       private ServiceReference packageAdminRef;
+
+       private BundleContext bundleContext;
        
        /**
         * The constructor
@@ -30,9 +39,37 @@ public class TaxonomicEditorPlugin extends AbstractUIPlugin {
        public void start(BundleContext context) throws Exception {
                super.start(context);
                plugin = this;
+               
+               bundleContext = context;
+               
+               // this should enable automatic updating. Not working at the moment
+               packageAdminRef = bundleContext.getServiceReference(PackageAdmin.class.getName());
+               packageAdmin = (PackageAdmin) bundleContext.getService(packageAdminRef);
+
+               // XXX start up the p2 infrastructure.  Normally the p2 UI class library does
+               // this, but we are running without UI.
+               getBundle("org.eclipse.equinox.p2.exemplarysetup").start(Bundle.START_TRANSIENT); //$NON-NLS-1$
+               getBundle("org.eclipse.equinox.frameworkadmin.equinox").start(Bundle.START_TRANSIENT); //$NON-NLS-1$
+               getBundle("org.eclipse.equinox.simpleconfigurator.manipulator").start(Bundle.START_TRANSIENT); //$NON-NLS-1$
+               
                logger.debug("Taxonomic Editor started.");
        }
 
+       private Bundle getBundle(String symbolicName) {
+               if (packageAdmin == null)
+                       return null;
+               Bundle[] bundles = packageAdmin.getBundles(symbolicName, null);
+               if (bundles == null)
+                       return null;
+               // Return the first bundle that is not installed or uninstalled
+               for (int i = 0; i < bundles.length; i++) {
+                       if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) {
+                               return bundles[i];
+                       }
+               }
+               return null;
+       }
+       
        /*
         * (non-Javadoc)
         * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)