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
.linuxtools
.internal
.lttng2
.ui
.views
.control
.preferences
.ControlPreferences
;
20 import org
.eclipse
.swt
.graphics
.Image
;
21 import org
.eclipse
.ui
.plugin
.AbstractUIPlugin
;
22 import org
.osgi
.framework
.BundleContext
;
25 * The activator class controls the plug-in life cycle
27 public class Activator
extends AbstractUIPlugin
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
36 public static final String PLUGIN_ID
= "org.eclipse.linuxtools.lttng2.ui"; //$NON-NLS-1$
41 private static Activator plugin
;
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
58 * Returns the shared instance
60 * @return the shared instance
62 public static Activator
getDefault() {
66 // ------------------------------------------------------------------------
68 // ------------------------------------------------------------------------
71 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
74 public void start(BundleContext context
) throws Exception
{
77 ControlPreferences
.getInstance().init();
81 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
84 public void stop(BundleContext context
) throws Exception
{
85 ControlPreferences
.getInstance().dispose();
91 * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse.jface.resource.ImageRegistry)
94 protected void initializeImageRegistry(ImageRegistry reg
) {
97 // ------------------------------------------------------------------------
99 // ------------------------------------------------------------------------
101 public Image
getImageFromPath(String path
) {
102 return getImageDescripterFromPath(path
).createImage();
105 public ImageDescriptor
getImageDescripterFromPath(String path
) {
106 return AbstractUIPlugin
.imageDescriptorFromPlugin(PLUGIN_ID
, path
);
109 public Image
getImageFromImageRegistry(String path
) {
110 Image icon
= getImageRegistry().get(path
);
112 icon
= getImageDescripterFromPath(path
).createImage();
113 plugin
.getImageRegistry().put(path
, icon
);
119 * Loads the image in the plug-ins image registry (if necessary) and returns the image
120 * @param url - URL relative to the Bundle
123 public Image
loadIcon(String url
) {
124 String key
= plugin
.getBundle().getSymbolicName() + "/" + url
; //$NON-NLS-1$
125 Image icon
= plugin
.getImageRegistry().get(key
);
127 URL imageURL
= plugin
.getBundle().getResource(url
);
128 ImageDescriptor descriptor
= ImageDescriptor
.createFromURL(imageURL
);
129 icon
= descriptor
.createImage();
130 plugin
.getImageRegistry().put(key
, icon
);