Java tutorial
/******************************************************************************* * Copyright (c) 2008,2009 Communication & Systems. * * 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: * Arnaud Giuliani - initial API and implementation * Obeo - getImageDescriptor method, for icons directory *******************************************************************************/ package org.eclipse.m2m.atl.profiler.ui.activators; import java.net.MalformedURLException; import java.net.URL; 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 <a href="mailto:arnaud.giuliani@c-s.fr">Arnaud Giuliani</a> * @author <a href="mailto:thierry.fortin@obeo.fr">Thierry Fortin</a> */ public class ExecutionViewerActivator extends AbstractUIPlugin { /** The plug-in ID. */ public static final String PLUGIN_ID = "org.eclipse.m2m.atl.profiler.ui.executionviewer"; //$NON-NLS-1$ // The shared instance private static ExecutionViewerActivator plugin; /** * The constructor. */ public ExecutionViewerActivator() { } /** * {@inheritDoc} * * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ @Override public void start(BundleContext context) throws Exception { super.start(context); plugin = this; } /** * {@inheritDoc} * * @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 ExecutionViewerActivator 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) { ExecutionViewerActivator uiPlugin = ExecutionViewerActivator.getDefault(); String pluginDir = uiPlugin.getBundle().getEntry("/").toString(); //$NON-NLS-1$ String iconPath = "icons/"; //$NON-NLS-1$ try { return ImageDescriptor.createFromURL(new URL(pluginDir + iconPath + path)); } catch (MalformedURLException mfe) { return ImageDescriptor.getMissingImageDescriptor(); } } }