/*******************************************************************************
* Copyright (c) 2011-2012 Bundlemaker project team.
* 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:
* Bundlemaker project team - initial API and implementation
******************************************************************************/
package org.bundlemaker.core.ui.mvn;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
/**
* This enumeration provides a number of images for the plugin.
*
* <p>
* Taken from http://blogs.itemis.de/wendehal/2010/07/08/pretty-elegant-way-to-provide -images-in-eclipse-ui-plug-ins/
*/
public enum MvnBundleMakerImages {
/**
* the BundleMaker logo
*/
MVN_PROJECT_CONTENT_PROVIDER("icons/mvn_project_provider.gif");
/**
* The bundle-relative path to the icon
*/
private final String path;
/**
* <p>
* Creates a new instance of type {@link MvnBundleMakerImages}.
* </p>
*
* @param path
*/
private MvnBundleMakerImages(final String path) {
this.path = path;
}
/**
* Returns an image. Clients do not need to dispose the image, it will be disposed automatically.
*
* @return an {@link Image}
*/
public Image getImage() {
final ImageRegistry imageRegistry = Activator.getDefault().getImageRegistry();
Image image = imageRegistry.get(this.path);
if (image == null) {
addImageDescriptor();
image = imageRegistry.get(this.path);
}
return image;
}
/**
* Returns an image descriptor.
*
* @return an {@link ImageDescriptor}
*/
public ImageDescriptor getImageDescriptor() {
final ImageRegistry imageRegistry = Activator.getDefault().getImageRegistry();
ImageDescriptor imageDescriptor = imageRegistry.getDescriptor(this.path);
if (imageDescriptor == null) {
addImageDescriptor();
imageDescriptor = imageRegistry.getDescriptor(this.path);
}
return imageDescriptor;
}
/**
* <p>
* </p>
*/
private void addImageDescriptor() {
final Activator plugin = Activator.getDefault();
final ImageDescriptor id = ImageDescriptor.createFromURL(plugin.getBundle().getEntry(this.path));
plugin.getImageRegistry().put(this.path, id);
}
}