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
24 public class TaxonomicEditorPlugin
extends AbstractUIPlugin
{
25 private static final Logger logger
= Logger
26 .getLogger(TaxonomicEditorPlugin
.class);
29 /** Constant <code>PLUGIN_ID="eu.etaxonomy.taxeditor.application"</code> */
30 public static final String PLUGIN_ID
= "eu.etaxonomy.taxeditor.application";
32 // The shared instance
33 private static TaxonomicEditorPlugin plugin
;
35 private PackageAdmin packageAdmin
;
37 private ServiceReference packageAdminRef
;
39 /** Constant <code>bundleContext</code> */
40 protected static BundleContext bundleContext
;
43 private ServiceRegistration policyRegistration
;
45 private ProvisioningSession session
;
46 private ProvisioningUI ui
;
48 // private CloudPolicy policy;
53 public TaxonomicEditorPlugin() {
58 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
62 public void start(BundleContext context
) throws Exception
{
66 bundleContext
= context
;
68 packageAdminRef
= bundleContext
.getServiceReference(PackageAdmin
.class.getName());
69 packageAdmin
= (PackageAdmin
) bundleContext
.getService(packageAdminRef
);
71 logger
.debug("Taxonomic Editor started.");
74 private Bundle
getBundle(String symbolicName
) {
75 if (packageAdmin
== null) {
78 Bundle
[] bundles
= packageAdmin
.getBundles(symbolicName
, null);
79 if (bundles
== null) {
82 // Return the first bundle that is not installed or uninstalled
83 for (int i
= 0; i
< bundles
.length
; i
++) {
84 if ((bundles
[i
].getState() & (Bundle
.INSTALLED
| Bundle
.UNINSTALLED
)) == 0) {
93 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
97 public void stop(BundleContext context
) throws Exception
{
100 MessagingUtils
.info("Taxonomic Editor stopped.");
104 * Returns the shared instance
106 * @return the shared instance
108 public static TaxonomicEditorPlugin
getDefault() {
112 public static BundleContext
getContext() {
113 return bundleContext
;
116 public ProvisioningUI
getProvisioningUI() {
119 ServiceReference reference
= bundleContext
.getServiceReference(IProvisioningAgent
.SERVICE_NAME
);
120 IProvisioningAgent agent
= (IProvisioningAgent
) bundleContext
.getService(reference
);
121 session
= new ProvisioningSession(agent
);
122 Policy policy
= null;// = (Policy) ServiceHelper.getService(ProvUIActivator.getContext(), Policy.class.getName());
123 if (policy
== null) {
124 policy
= new Policy();
126 ui
= new ProvisioningUI(session
, IProfileRegistry
.SELF
, policy
);