Java tutorial
/* Copyright (C) 2013-2015 BMW Group * Author: Manfred Bathelt (manfred.bathelt@bmw.de) * Author: Juergen Gehring (juergen.gehring@bmw.de) * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package de.bmw.yamaica.ea.ui.internal; import java.net.URL; import java.util.Map; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import de.bmw.yamaica.ea.core.resources.Resource; import de.bmw.yamaica.ea.core.resources.Resources; /** * The activator class controls the plug-in life cycle */ public class Activator extends AbstractUIPlugin { // The plug-in ID public static final String PLUGIN_ID = "de.bmw.yamaica.ea.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) */ 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; } @Override protected void initializeImageRegistry(ImageRegistry imageRegistry) { Map<String, Resource> resources = Resources.getResources(getBundle()); for (Resource resource : resources.values()) { Bundle bundle = Platform.getBundle(resource.getBundleId()); IPath path = new Path(resource.getPath()); URL url = FileLocator.find(bundle, path, null); imageRegistry.put(resource.getName(), ImageDescriptor.createFromURL(url)); } } }