/*******************************************************************************
* Copyright (c) 2017 Obeo
* 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:
* - William Piers <william.piers@obeo.fr>
*******************************************************************************/
package org.occiware.clouddesigner.occi.examples;
import java.net.URL;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*
* @author William Piers
* <a href="mailto:william.piers@obeo.fr">william.piers@obeo.fr</a>
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.occiware.clouddesigner.occi.examples"; //$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)
*/
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)
*/
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 Image getImage(String key) {
Image image = getImageRegistry().get(key);
if (image == null) {
image = registerImage(key);
}
return image;
}
private Image registerImage(String key) {
try {
IPath path = new Path("images/" + key); //$NON-NLS-1$
URL url = FileLocator.find(this.getBundle(), path, null);
if (url != null) {
ImageDescriptor desc = ImageDescriptor.createFromURL(url);
getImageRegistry().put(key, desc);
return getImageRegistry().get(key);
}
} catch (Exception e) {
// ignored
}
return null;
}
}