blob: 7edda19f1c56bfc36742acd5c4d09d6c432f620e [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2011 Eike Stepper (Berlin, Germany) 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:
* Eike Stepper - initial API and implementation
*******************************************************************************/
package org.eclipse.emf.ecp.workspace.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.
*
* @author Eike Stepper
*/
public final class Activator extends AbstractUIPlugin {
/**
* The plug-in ID.
*/
public static final String PLUGIN_ID = "org.eclipse.emf.ecp.workspace.ui"; //$NON-NLS-1$
private static Activator instance;
/**
* The constructor.
*/
public Activator() {
}
// BEGIN SUPRESS CATCH EXCEPTION
@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);
}
// END SUPRESS CATCH EXCEPTION
/**
* Returns the shared instance.
*
* @return the shared instance
*/
public static Activator getInstance() {
return instance;
}
/**
* Logs and Info message.
*
* @param message the message to log
*/
public static void log(String message) {
instance.getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message));
}
private static void log(IStatus status) {
instance.getLog().log(status);
}
/**
* Logs a {@link Throwable}.
*
* @param t the {@link Throwable} to log
* @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} for a path.
*
* @param path the path to an image
* @return the {@link ImageDescriptor}
*/
public static ImageDescriptor loadImageDescriptor(String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
}