/*******************************************************************************
* Copyright (c) 2006 IBM Corporation and others.
* 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
*
* Contributors:
* IBM Corporation - initial API and implementation
* IBM Research
*******************************************************************************/
package com.ibm.research.tagging.url;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class UrlWaypointPlugin extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "com.ibm.research.tagging.url";
public static final String IMG_WEB = "IMG_WEB";
public static final String IMG_WEB22 = "IMG_WEB22";
private static final String PATH_WEB = "icons/discovery.gif";
private static final String PATH_WEB22 = "icons/web22.gif";
// The shared instance
private static UrlWaypointPlugin plugin;
/**
* The constructor
*/
public UrlWaypointPlugin() {
plugin = this;
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
}
/*
* (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 UrlWaypointPlugin 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);
}
@Override
protected ImageRegistry createImageRegistry()
{
ImageRegistry registry = super.createImageRegistry();
loadImageDescriptorIntoRegistry(registry, IMG_WEB, PATH_WEB);
loadImageDescriptorIntoRegistry(registry, IMG_WEB22, PATH_WEB22);
return registry;
}
/**
* Loads an image descriptor into the registry if it doesn't already exist.
* @param reg the image registry
* @param key the key for the image in the registry
* @param path the path to the image (relative to the plugin directory (e.g. /icons/icon.gif)
*/
private void loadImageDescriptorIntoRegistry(ImageRegistry reg, String key, String path) {
ImageDescriptor descriptor = reg.getDescriptor(key);
if (descriptor == null) {
descriptor = getImageDescriptor(path);
if(descriptor != null) {
reg.put(key, descriptor);
}
}
}
/**
* Logs an information message.
* @param msg the message to log to the eclipse error log
*/
public static void log(String msg) {
log(IStatus.INFO, msg, null);
}
/**
* Logs a message with the given severity.
* @see IStatus
* @param severity the severity of the log message
* @param msg the message to log
*/
public static void log(int severity, String msg) {
log(severity, msg, null);
}
/**
* Logs a message and an exception to the workspace error log.
* @param msg the message to log
* @param ex the exception to log (can be null)
*/
public static void log(String msg, Throwable ex) {
log(IStatus.ERROR, msg, ex);
}
/**
* Logs a message to the eclipse error log.
* @param severity the importance - from INFO to ERROR
* @param msg the message to log
* @param ex the optional exception (can be null)
*
*/
@SuppressWarnings("restriction")
private static void log(int severity, String msg, Throwable ex) {
if (msg == null)
return;
if (getDefault() == null) {
// write the error out to standard error
String errMsg = "LOG [severity=" + severity + "]: " + msg;
System.err.println(errMsg);
if (ex != null) {
ex.printStackTrace(System.err);
}
} else {
getDefault().getLog().log(new Status(severity, PLUGIN_ID, severity, msg, ex));
}
}
}