1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
;
17 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
18 import org
.eclipse
.jface
.resource
.ImageRegistry
;
19 import org
.eclipse
.swt
.graphics
.Image
;
20 import org
.eclipse
.ui
.plugin
.AbstractUIPlugin
;
21 import org
.osgi
.framework
.BundleContext
;
24 * The activator class controls the plug-in life cycle
26 public class Activator
extends AbstractUIPlugin
{
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
35 public static final String PLUGIN_ID
= "org.eclipse.linuxtools.lttng2.ui"; //$NON-NLS-1$
40 private static Activator plugin
;
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
54 // ------------------------------------------------------------------------
57 * Returns the shared instance
59 * @return the shared instance
61 public static Activator
getDefault() {
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
70 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
73 public void start(BundleContext context
) throws Exception
{
79 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
82 public void stop(BundleContext context
) throws Exception
{
88 * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse.jface.resource.ImageRegistry)
91 protected void initializeImageRegistry(ImageRegistry reg
) {
94 // ------------------------------------------------------------------------
96 // ------------------------------------------------------------------------
98 public Image
getImageFromPath(String path
) {
99 return getImageDescripterFromPath(path
).createImage();
102 public ImageDescriptor
getImageDescripterFromPath(String path
) {
103 return AbstractUIPlugin
.imageDescriptorFromPlugin(PLUGIN_ID
, path
);
106 public Image
getImageFromImageRegistry(String path
) {
107 Image icon
= getImageRegistry().get(path
);
109 icon
= getImageDescripterFromPath(path
).createImage();
110 plugin
.getImageRegistry().put(path
, icon
);
116 * Loads the image in the plug-ins image registry (if necessary) and returns the image
117 * @param url - URL relative to the Bundle
120 public Image
loadIcon(String url
) {
121 String key
= plugin
.getBundle().getSymbolicName() + "/" + url
; //$NON-NLS-1$
122 Image icon
= plugin
.getImageRegistry().get(key
);
124 URL imageURL
= plugin
.getBundle().getResource(url
);
125 ImageDescriptor descriptor
= ImageDescriptor
.createFromURL(imageURL
);
126 icon
= descriptor
.createImage();
127 plugin
.getImageRegistry().put(key
, icon
);