| 1 | package de.uka.ipd.sdq.codegen.simucontroller; |
| 2 | |
| 3 | import org.apache.log4j.Logger; |
| 4 | import org.eclipse.core.runtime.Status; |
| 5 | import org.eclipse.ui.PlatformUI; |
| 6 | import org.eclipse.ui.plugin.AbstractUIPlugin; |
| 7 | import org.osgi.framework.Bundle; |
| 8 | import org.osgi.framework.BundleContext; |
| 9 | import org.osgi.framework.BundleEvent; |
| 10 | import org.osgi.framework.BundleException; |
| 11 | import org.osgi.framework.BundleListener; |
| 12 | |
| 13 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.DocksModel; |
| 14 | import de.uka.ipd.sdq.codegen.simucontroller.gui.DockStatusViewPart; |
| 15 | import de.uka.ipd.sdq.codegen.simucontroller.gui.DockStatusViewer; |
| 16 | |
| 17 | /** |
| 18 | * The activator class controls the plug-in life cycle |
| 19 | */ |
| 20 | public class SimuControllerPlugin extends AbstractUIPlugin { |
| 21 | /** Logger for this class. */ |
| 22 | private static final Logger logger = Logger.getLogger(SimuControllerPlugin.class); |
| 23 | |
| 24 | // The plug-in ID |
| 25 | public static final String PLUGIN_ID = "de.uka.ipd.sdq.codegen.simucontroller"; |
| 26 | |
| 27 | // The shared instance |
| 28 | private static SimuControllerPlugin plugin; |
| 29 | |
| 30 | private static DocksModel dockModel = null; |
| 31 | |
| 32 | /** |
| 33 | * The constructor |
| 34 | */ |
| 35 | public SimuControllerPlugin() { |
| 36 | plugin = this; |
| 37 | } |
| 38 | |
| 39 | /* (non-Javadoc) |
| 40 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) |
| 41 | */ |
| 42 | @Override |
| 43 | public void start(BundleContext context) throws Exception { |
| 44 | |
| 45 | context.addBundleListener(new BundleListener(){ |
| 46 | |
| 47 | public void bundleChanged(BundleEvent event) { |
| 48 | if (event.getType() == BundleEvent.INSTALLED){ |
| 49 | |
| 50 | } |
| 51 | } |
| 52 | }); |
| 53 | super.start(context); |
| 54 | |
| 55 | ensurePluginLoaded(context,"org.eclipse.equinox.event"); |
| 56 | ensurePluginLoaded(context,"org.eclipse.equinox.log"); |
| 57 | ensurePluginLoaded(context, "ch.ethz.iks.slp"); |
| 58 | ensurePluginLoaded(context,"ch.ethz.iks.r_osgi.remote"); |
| 59 | ensurePluginLoaded(context,"ch.ethz.iks.r_osgi.service_discovery.slp"); |
| 60 | |
| 61 | dockModel = new DocksModel(context); |
| 62 | |
| 63 | // FB 2011-06-29: added exception handling. If the SimuControllerPlugin is |
| 64 | // loaded right at the start of the platform (e.g., the SLA@SOI prediction |
| 65 | // server does this in order to publish a simulation service), then it may |
| 66 | // be loaded before the workbench itself, and the SimuDock cannot be |
| 67 | // displayed. |
| 68 | try { |
| 69 | DockStatusViewer.showSimuDockView(); |
| 70 | } catch (Exception e) { |
| 71 | e.printStackTrace(); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | private void ensurePluginLoaded(BundleContext context, String bundleName) { |
| 76 | for (Bundle b : context.getBundles()) { |
| 77 | if (b.getSymbolicName().equals(bundleName)) { |
| 78 | if (b.getState() != Bundle.ACTIVE){ |
| 79 | try { |
| 80 | b.start(); |
| 81 | while (b.getState() != Bundle.ACTIVE){ |
| 82 | try { |
| 83 | Thread.sleep(50); |
| 84 | } catch (InterruptedException e) { |
| 85 | logger.warn("Waiting for initalization was aborted unexpectedly.", e); |
| 86 | } |
| 87 | } |
| 88 | } catch (BundleException e) { |
| 89 | logger.error("Error while starting the OSGI bundle occured.", e); |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /* (non-Javadoc) |
| 97 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) |
| 98 | */ |
| 99 | public void stop(BundleContext context) throws Exception { |
| 100 | //extCache.shutdown(); |
| 101 | plugin = null; |
| 102 | super.stop(context); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Returns the shared instance |
| 107 | */ |
| 108 | public static SimuControllerPlugin getDefault() { |
| 109 | return plugin; |
| 110 | } |
| 111 | |
| 112 | public static void log(int severity, String message){ |
| 113 | plugin.getLog().log(new Status(severity,PLUGIN_ID,message)); |
| 114 | } |
| 115 | |
| 116 | public static DocksModel getDockModel() { |
| 117 | return dockModel; |
| 118 | } |
| 119 | |
| 120 | } |