/* *****************************************************************************
* Copyright (c) 2009 Ola Spjuth <ola@bioclipse.net>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contact: http://www.bioclipse.net/
******************************************************************************/
package net.bioclipse.vscreen;
import net.bioclipse.vscreen.business.IVScreenManager;
import net.bioclipse.vscreen.business.IJavaVScreenManager;
import net.bioclipse.vscreen.business.IJavaScriptVScreenManager;
import org.apache.log4j.Logger;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
/**
* The Activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
private static final Logger logger = Logger.getLogger(Activator.class);
// The plug-in ID
public static final String PLUGIN_ID = "net.bioclipse.vscreen";
// The shared instance
private static Activator plugin;
// Trackers for getting the managers
private ServiceTracker javaFinderTracker;
private ServiceTracker jsFinderTracker;
public Activator() {
}
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
javaFinderTracker
= new ServiceTracker( context,
IJavaVScreenManager.class.getName(),
null );
javaFinderTracker.open();
jsFinderTracker
= new ServiceTracker( context,
IJavaScriptVScreenManager.class.getName(),
null );
jsFinderTracker.open();
}
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
public IVScreenManager getJavaVScreenManager() {
IVScreenManager manager = null;
try {
manager = (IVScreenManager)
javaFinderTracker.waitForService(1000*10);
}
catch (InterruptedException e) {
throw new IllegalStateException(
"Could not get the Java VScreenManager",
e );
}
if (manager == null) {
throw new IllegalStateException(
"Could not get the Java VScreenManager");
}
return manager;
}
public IJavaScriptVScreenManager getJavaScriptVScreenManager() {
IJavaScriptVScreenManager manager = null;
try {
manager = (IJavaScriptVScreenManager)
jsFinderTracker.waitForService(1000*10);
}
catch (InterruptedException e) {
throw new IllegalStateException(
"Could not get the JavaScript VScreenManager",
e );
}
if (manager == null) {
throw new IllegalStateException(
"Could not get the JavaScript VScreenManager");
}
return manager;
}
}