package tool;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.ui.statushandlers.StatusManager;
import org.osgi.framework.BundleContext;
import tool.builder.RepositoryStateJob;
/**
* The activator class controls the plug-in life cycle
*/
public class ToolBuilderActivator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "ToolBuilder"; //$NON-NLS-1$
// The shared instance
private static ToolBuilderActivator plugin;
/**
* The constructor
*/
public ToolBuilderActivator() {
super();
syncrohizeRepositoryState();
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
private void syncrohizeRepositoryState() {
RepositoryStateJob runner = new RepositoryStateJob();
runner.setPriority(Job.LONG);
runner.schedule();
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static ToolBuilderActivator getDefault() {
return plugin;
}
/**
* Returns an image descriptor for the image file at the given
* plug-in relative path
*
* @param path the path
* @return the image descriptor
*/
public static ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
/**
* shows and logs an error
*
* @param message
* @param e
*/
public static void showError(String message, Throwable e) {
IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, message, e);
StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.SHOW);
}
public static void log(int level, String message){
plugin.getLog().log(new Status(level, PLUGIN_ID, message, null));
}
public static void log(int level, String message, Throwable e){
plugin.getLog().log(new Status(level, PLUGIN_ID, message, e));
}
public static MessageConsole findConsole(String name) {
MessageConsole myConsole = null;
ConsolePlugin plugin = ConsolePlugin.getDefault();
if (plugin != null){
IConsoleManager conMan = plugin.getConsoleManager();
IConsole[] existing = conMan.getConsoles();
for (int i = 0; i < existing.length; i++)
if (name.equals(existing[i].getName()))
return (MessageConsole) existing[i];
//no console found, so create a new one
myConsole = new MessageConsole(name, null);
conMan.addConsoles(new IConsole[]{myConsole});
}
return myConsole;
}
}