/******************************************************************************* * Copyright (c) 2005, 2007 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 *******************************************************************************/ package org.eclipse.jst.jee.ui.plugin; import java.net.URL; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; /** * The activator class controls the plug-in life cycle */ public class JEEUIPlugin extends AbstractUIPlugin { // The plug-in ID public static final String PLUGIN_ID = "org.eclipse.jst.jee.ui"; //$NON-NLS-1$ // The shared instance private static JEEUIPlugin plugin; /** * The constructor */ public JEEUIPlugin() { } /* * (non-Javadoc) * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ @Override public void start(BundleContext context) throws Exception { super.start(context); plugin = this; } /* * (non-Javadoc) * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ @Override public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); } /** * Returns the shared instance * * @return the shared instance */ public static JEEUIPlugin getDefault() { return plugin; } /** * This gets a .gif from the icons folder. */ public ImageDescriptor getImageDescriptor(String key) { ImageDescriptor imageDescriptor = null; URL gifImageURL = getImageURL(key); if (gifImageURL != null) imageDescriptor = ImageDescriptor.createFromURL(gifImageURL); return imageDescriptor; } /** * @param key * @return */ private URL getImageURL(String key) { return J2EEPlugin.getImageURL(key, getBundle()); } /** * * Record a message against this plugin's log. * * @param severity * @param aCode * @param aMessage * @param exception */ public static void log(int severity, int aCode, String aMessage, Throwable exception) { log(createStatus(severity, aCode, aMessage, exception)); } /** * Create a status associated with this plugin. * * @param severity * @param aCode * @param aMessage * @param exception * @return A status configured with this plugin's id and the given parameters. */ public static IStatus createStatus(int severity, int aCode, String aMessage, Throwable exception) { return new Status(severity, PLUGIN_ID, aCode, aMessage != null ? aMessage : "No message.", exception); //$NON-NLS-1$ } /** * * Record a status against this plugin's log. * * @param aStatus */ public static void log(IStatus aStatus) { getDefault().getLog().log(aStatus); } public static void logError(String message, Exception e) { log(IStatus.ERROR, IStatus.ERROR,message,e); } public static IStatus createStatus(int severity, String message, Throwable exception) { return new Status(severity, PLUGIN_ID, message, exception); } public static IStatus createStatus(int severity, String message) { return createStatus(severity, message, null); } public static void logError(Throwable exception) { Platform.getLog(Platform.getBundle(PLUGIN_ID)).log( createStatus(IStatus.ERROR, exception.getMessage(), exception)); } public static void logError(CoreException exception) { Platform.getLog(Platform.getBundle(PLUGIN_ID)).log( exception.getStatus() ); } public Image getImage(String key){ return getImageDescriptor(key).createImage(); } }