| /** |
| * <copyright> |
| * |
| * Copyright (c) 2014 itemis and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html |
| * |
| * Contributors: |
| * itemis - Initial API and implementation |
| * |
| * </copyright> |
| */ |
| package org.eclipse.sphinx.emf.check.ui.internal; |
| |
| import java.net.URL; |
| |
| import org.eclipse.jface.resource.ImageDescriptor; |
| import org.eclipse.jface.resource.ImageRegistry; |
| 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 |
| */ |
| public class Activator extends AbstractUIPlugin { |
| |
| // The plug-in ID |
| public static String PLUGIN_ID = "org.eclipse.sphinx.emf.check.ui"; //$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 ) |
| */ |
| @Override |
| public void start(BundleContext bundleContext) throws Exception { |
| super.start(bundleContext); |
| plugin = this; |
| } |
| |
| /* |
| * (non-Javadoc) |
| * @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 Activator getDefault() { |
| return plugin; |
| } |
| |
| @Override |
| protected void initializeImageRegistry(ImageRegistry reg) { |
| addImageFilePath(CheckValidationImageProvider.FILE); |
| addImageFilePath(CheckValidationImageProvider.ERROR_ICO); |
| addImageFilePath(CheckValidationImageProvider.WARNING_ICO); |
| addImageFilePath(CheckValidationImageProvider.INFO_ICO); |
| addImageFilePath(CheckValidationImageProvider.GROUP_ICO); |
| addImageFilePath(CheckValidationImageProvider.CHECK_ICO); |
| } |
| |
| private void addImageFilePath(String relativeURL) { |
| Image image = plugin.getImageRegistry().get(relativeURL); |
| if (image == null) { |
| URL imageURL = plugin.getBundle().getEntry(relativeURL); |
| ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL); |
| image = descriptor.createImage(); |
| plugin.getImageRegistry().put(relativeURL, image); |
| } |
| } |
| |
| public static ImageDescriptor getImageDescriptor(String relativeURL) { |
| URL entry = plugin.getBundle().getEntry(relativeURL); |
| if (entry != null) { |
| return ImageDescriptor.createFromURL(entry); |
| } |
| return null; |
| } |
| } |