blob: bac364ea0d29ecdd8c1066153cf6bc9bf0db1bea [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2011-2012 EclipseSource Muenchen GmbH 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:
* Eugen Neufeld - initial API and implementation
*
*******************************************************************************/
package org.eclipse.emf.ecp.emfstore.internal.ui;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle.
*/
public class Activator extends AbstractUIPlugin {
/** The plug-in ID. **/
public static final String PLUGIN_ID = "org.eclipse.emf.ecp.emfstore.ui"; //$NON-NLS-1$
private static Activator instance;
/**
* The constructor.
*/
public Activator() {
}
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
instance = this;
}
@Override
public void stop(BundleContext context) throws Exception {
instance = null;
super.stop(context);
}
/**
* Returns the shared instance.
*
* @return the shared instance
*/
public static Activator getInstance() {
return instance;
}
private static void log(IStatus status) {
instance.getLog().log(status);
}
/**
* Logs a message with a specific status.
*
* @param status the {@link IStatus} value
* @param message the message to log
*/
public static void log(int status, String message) {
instance.getLog().log(new Status(status, PLUGIN_ID, message));
}
/**
* Logs a {@link Throwable}.
*
* @param t the {@link Throwable}
* @return the message of the {@link Throwable}
*/
public static String log(Throwable t) {
IStatus status = getStatus(t);
log(status);
return status.getMessage();
}
private static IStatus getStatus(Throwable t) {
if (t instanceof CoreException) {
CoreException coreException = (CoreException) t;
return coreException.getStatus();
}
String msg = t.getLocalizedMessage();
if (msg == null || msg.length() == 0) {
msg = t.getClass().getName();
}
return new Status(IStatus.ERROR, PLUGIN_ID, msg, t);
}
/**
* Returns an {@link ImageDescriptor} based on a path from this plugin.
* This is a wrapper for {@link AbstractUIPlugin#imageDescriptorFromPlugin(String, String)}.
*
* @param path the relative path of the image file, relative to the root of the plug-in; the path must be legal
* @return an image descriptor, or null if no image could be found
*/
public static ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
}