/*
* Copyright (c) 2010, IETR/INSA of Rennes
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the IETR/INSA of Rennes nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
package net.sf.orcc.ui;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
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.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class OrccUiActivator extends AbstractUIPlugin {
// The shared instance
private static OrccUiActivator plugin;
// The plug-in ID
public static final String PLUGIN_ID = "net.sf.orcc.ui"; //$NON-NLS-1$
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static OrccUiActivator getDefault() {
return plugin;
}
/**
* Returns an image for the image file at the given plug-in relative path.
*
* @param path
* the path
* @return the image
*/
public static Image getImage(String path) {
ImageRegistry ir = plugin.getImageRegistry();
Image image = ir.get(path);
if (image == null) {
ImageDescriptor id = imageDescriptorFromPlugin(PLUGIN_ID, path);
image = id.createImage();
ir.put(path, image);
}
return image;
}
/**
* Return an Orcc MessageConsole corresponding to <code>name</code>. If it
* does not already exists, create and register it to the manager.
*
* @param name
* Name of the console
* @return The console instance
*/
public static MessageConsole getOrccConsole(String name) {
IConsoleManager conMan = ConsolePlugin.getDefault().getConsoleManager();
IConsole[] existing = conMan.getConsoles();
for (IConsole element : existing) {
if (name.equals(element.getName())) {
return (MessageConsole) element;
}
}
// no console found, so create a new one
MessageConsole myConsole = new MessageConsole(name,
getImageDescriptor("icons/orcc.png"));
conMan.addConsoles(new IConsole[] { myConsole });
return myConsole;
}
/**
* 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
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
}