blob: 1687a6f3f9a97ea286d39c48496640c2a4ecf987 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2011 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.ptp.internal.rdt.sync.git.ui;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
/**
* 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.ptp.internal.rdt.sync.git.ui"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
}
/*
* (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 Activator getDefault() {
return plugin;
}
public static void log(Throwable e) {
log("Error", e); //$NON-NLS-1$
}
public static void log(String message, Throwable e) {
log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, e));
}
public static void log(IStatus status) {
getDefault().getLog().log(status);
}
public static void log(String message) {
log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, null));
}
/**
* Return the OSGi service with the given service interface.
*
* @param service
* service interface
* @return the specified service or null if it's not registered
*/
public static <T> T getService(Class<T> service) {
final BundleContext context = plugin.getBundle().getBundleContext();
final ServiceReference<T> ref = context.getServiceReference(service);
return ref != null ? context.getService(ref) : null;
}
}