| /******************************************************************************* |
| * Copyright (c) 2012 IBM 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 |
| *******************************************************************************/ |
| package org.eclipse.ptp.internal.remote.terminal; |
| |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.core.runtime.Plugin; |
| import org.eclipse.core.runtime.Status; |
| import org.eclipse.jface.resource.ImageDescriptor; |
| import org.eclipse.ptp.internal.remote.terminal.messages.Messages; |
| 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 Plugin { |
| |
| public static final String PLUGIN_ID = "org.eclipse.ptp.remote.terminal"; //$NON-NLS-1$ |
| private static Activator plugin; |
| |
| /** |
| * The constructor |
| */ |
| public Activator() { |
| super(); |
| plugin = this; |
| } |
| |
| @Override |
| public void start(BundleContext context) throws Exception { |
| super.start(context); |
| } |
| |
| @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; |
| } |
| |
| /** |
| * 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 AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path); |
| } |
| |
| /** |
| * Create log entry from an IStatus |
| * |
| * @param status |
| * status |
| */ |
| public static void log(IStatus status) { |
| getDefault().getLog().log(status); |
| } |
| |
| /** |
| * Create log entry from a string |
| * |
| * @param msg |
| * log message |
| */ |
| public static void log(String msg) { |
| log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, msg, null)); |
| } |
| |
| /** |
| * Create log entry from a Throwable |
| * |
| * @param e |
| * throwable |
| */ |
| public static void log(Throwable e) { |
| log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, Messages.TERMINAL_EXCEPTION, e)); |
| } |
| |
| // Get rid of edu.lsu.cct tags |
| |
| /** |
| * Generate a unique identifier |
| * |
| * @return unique identifier string |
| */ |
| public static String getUniqueIdentifier() { |
| if (getDefault() == null) { |
| // If the default instance is not yet initialized, |
| // return a static identifier. This identifier must |
| // match the plugin id defined in plugin.xml |
| return PLUGIN_ID; |
| } |
| return getDefault().getBundle().getSymbolicName(); |
| } |
| |
| /** |
| * 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; |
| } |
| } |