### Eclipse Workspace Patch 1.0 #P org.eclipse.ui.workbench Index: Eclipse UI/org/eclipse/ui/plugin/AbstractUIPlugin.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/plugin/AbstractUIPlugin.java,v retrieving revision 1.49 diff -u -r1.49 AbstractUIPlugin.java --- Eclipse UI/org/eclipse/ui/plugin/AbstractUIPlugin.java 4 Mar 2009 02:47:53 -0000 1.49 +++ Eclipse UI/org/eclipse/ui/plugin/AbstractUIPlugin.java 5 Mar 2009 07:23:12 -0000 @@ -663,6 +663,10 @@ if (pluginId == null || imageFilePath == null) { throw new IllegalArgumentException(); } + + ImageDescriptor imageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(imageFilePath); + if(imageDescriptor != null) + return imageDescriptor; // found in the shared images // if the bundle is not ready then there is no image Bundle bundle = Platform.getBundle(pluginId); Index: Eclipse UI/org/eclipse/ui/internal/WorkbenchImages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchImages.java,v retrieving revision 1.65 diff -u -r1.65 WorkbenchImages.java --- Eclipse UI/org/eclipse/ui/internal/WorkbenchImages.java 6 Jan 2009 21:08:54 -0000 1.65 +++ Eclipse UI/org/eclipse/ui/internal/WorkbenchImages.java 5 Mar 2009 07:23:10 -0000 @@ -10,11 +10,18 @@ *******************************************************************************/ package org.eclipse.ui.internal; +import java.net.MalformedURLException; import java.net.URL; import java.util.HashMap; import java.util.Map; import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.swt.SWT; @@ -28,6 +35,7 @@ import org.eclipse.ui.internal.misc.Policy; import org.eclipse.ui.internal.misc.ProgramImageDescriptor; import org.eclipse.ui.internal.util.BundleUtility; +import org.eclipse.ui.plugin.AbstractUIPlugin; /** * This class provides convenience access to many of the resources required @@ -592,12 +600,47 @@ * @see ImageRegistry */ private static void initializeImageRegistry() { - imageRegistry = new ImageRegistry(); - descriptors = new HashMap(); - declareImages(); + //should be run in the display thread + Display.getDefault().syncExec(new Runnable(){ + + public void run() { + imageRegistry = new ImageRegistry(); + descriptors = new HashMap(); + declareImages(); + loadFromRegistry(); + } + }); } - /** + private static void loadFromRegistry() { + IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint("org.eclipse.ui.sharedImages"); //$NON-NLS-1$ + IExtension[] extensions = extensionPoint.getExtensions(); + for (int i = 0; i < extensions.length; i++) { + IConfigurationElement[] constants = extensions[i].getConfigurationElements(); + for (int j = 0; j < constants.length; j++) { + String name = constants[j].getAttribute("name"); //$NON-NLS-1$ + try { + String location = constants[j].getAttribute("location"); //$NON-NLS-1$ + ImageDescriptor desc; + try { + // check for any url pattern including platform:/plugin/... + URL url = new URL(location); + desc = ImageDescriptor.createFromURL(url); + } catch (MalformedURLException exception) { + // the plugin might have specified in /icons/something.png format + desc = AbstractUIPlugin.imageDescriptorFromPlugin(extensions[i].getNamespaceIdentifier(), location); + } + declareImage(name, desc, true); + } catch (Exception e) { + String message = "Exception while loading shared image '"+name+'\''; //$NON-NLS-1$ + WorkbenchPlugin.log(message, new Status(IStatus.ERROR, + PlatformUI.PLUGIN_ID, 0, message, e)); + } + } + } + } + + /** * Disposes and clears the workbench images. * Called when the workbench is shutting down. * #P org.eclipse.ui Index: plugin.xml =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui/plugin.xml,v retrieving revision 1.441 diff -u -r1.441 plugin.xml --- plugin.xml 25 Feb 2009 15:03:51 -0000 1.441 +++ plugin.xml 5 Mar 2009 07:23:26 -0000 @@ -50,6 +50,7 @@ + @@ -2228,4 +2229,5 @@ id="31.SystemPage"> + Index: plugin.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui/plugin.properties,v retrieving revision 1.217 diff -u -r1.217 plugin.properties --- plugin.properties 23 Feb 2009 23:55:35 -0000 1.217 +++ plugin.properties 5 Mar 2009 07:23:25 -0000 @@ -57,6 +57,7 @@ ExtPoint.statusHandlers = Status Handlers ExtPoint.installationPages = Installation Pages ExtPoint.tweaklets = Tweaklets (internal/experimental) +ExtPoint.sharedImages = Shared Images Views.Category.Basic = General Views.IntroAdapter = Welcome Index: schema/sharedImages.exsd =================================================================== RCS file: schema/sharedImages.exsd diff -N schema/sharedImages.exsd --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ schema/sharedImages.exsd 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,151 @@ + + + + + + + + + This extension point is used to register shared images. A Shared Image is denoted by its name and can be used in most the places where an image descriptor is required + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <p>The ID Constant</p> + + + + + + + Name of the constant that will be used to refer this shared image + + + + + + + location of the shared image. + + + + + + + + + + + + + + + 3.5 + + + + + + + + + The following adds a shared image + +<pre> +<extension point="org.eclipse.ui.sharedImages"> + <constant + name="IMG_SOME_TOOL" + location="icons/SomeTool.png"/> +</extension> +</pre> + +It can be used in icon contributions like: + +<pre> +<extension point="org.eclipse.ui.commandImages"> + <image + commandId="com.example.someCommand" + icon="IMG_SOME_TOOL"> + </image> +</extension> +</pre> + +or + +<pre> +<extension point="org.eclipse.ui.menus"> + <menuContribution + locationURI="menu:org.eclipse.ui.file?after=additions"> + <command + commandId="com.example.someCommand" + icon="IMG_SOME_TOOL"/> + </menuContribution> +</pre> + + + + + + + + + + <p> +This extension is used to register shared images. The registered shared image is available in the workbench's shared images registry. It can be used in plugin.xml contributions where an icon is required. The shared image can be obtained from the <samp>AbstractUIPlugin.imageDescriptorFromPlugin(...)</samp> by specifying the constant for the imagePath parameter +</p> + + + + + + + + + Copyright (c) 2009 IBM Corporation and others.<br> +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 <a +href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a> + + + + #P org.eclipse.ui.tests Index: plugin.xml =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.tests/plugin.xml,v retrieving revision 1.270 diff -u -r1.270 plugin.xml --- plugin.xml 3 Mar 2009 18:39:37 -0000 1.270 +++ plugin.xml 5 Mar 2009 07:23:37 -0000 @@ -4122,4 +4122,40 @@ replace="M2+8"> + + + + + + + + + + + + + + + + + + + + Index: Eclipse UI Tests/org/eclipse/ui/tests/api/IWorkbenchTestSuite.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IWorkbenchTestSuite.java,v retrieving revision 1.6 diff -u -r1.6 IWorkbenchTestSuite.java --- Eclipse UI Tests/org/eclipse/ui/tests/api/IWorkbenchTestSuite.java 16 Mar 2007 17:59:59 -0000 1.6 +++ Eclipse UI Tests/org/eclipse/ui/tests/api/IWorkbenchTestSuite.java 5 Mar 2009 07:23:37 -0000 @@ -34,5 +34,6 @@ public IWorkbenchTestSuite() { addTest(new TestSuite(IWorkbenchTest.class)); addTest(new TestSuite(IWorkbenchWindowTest.class)); + addTest(new TestSuite(ISharedImagesTest.class)); } } Index: Eclipse UI Tests/org/eclipse/ui/tests/api/ISharedImagesTest.java =================================================================== RCS file: Eclipse UI Tests/org/eclipse/ui/tests/api/ISharedImagesTest.java diff -N Eclipse UI Tests/org/eclipse/ui/tests/api/ISharedImagesTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ Eclipse UI Tests/org/eclipse/ui/tests/api/ISharedImagesTest.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * 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: + * IBM Corporation - initial API and implementation + ******************************************************************************/ + +package org.eclipse.ui.tests.api; + +import java.lang.reflect.Field; + +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.commands.ICommandImageService; +import org.eclipse.ui.menus.CommandContributionItem; +import org.eclipse.ui.menus.IMenuService; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.ui.tests.TestPlugin; +import org.eclipse.ui.tests.harness.util.UITestCase; + +/** + * @since 3.5 + * @author Prakash G.R. + * + */ +public class ISharedImagesTest extends UITestCase { + + public ISharedImagesTest(String testName) { + super(testName); + } + + public void testSharedImage() throws Exception { + + IWorkbench workbench = getWorkbench(); + IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); + + // test shared images + ImageDescriptor sharedImageDesc1 = workbench.getSharedImages().getImageDescriptor("SHARED_IMAGE_TEST1"); + assertNotNull(sharedImageDesc1); + + // test AUIP.imageDescriptorFromPlugin + ImageDescriptor sharedImageDesc2 = AbstractUIPlugin.imageDescriptorFromPlugin(TestPlugin.PLUGIN_ID, "SHARED_IMAGE_TEST1"); + assertNotNull(sharedImageDesc2); + + // test command image service + ICommandImageService commandImageService = (ICommandImageService) window.getService(ICommandImageService.class); + ImageDescriptor sharedImageDesc3 = commandImageService.getImageDescriptor("org.eclipse.ui.tests.someDummyCommand"); + assertNotNull(sharedImageDesc3); + + // test contribution + MenuManager menuManager = new MenuManager("Dummy Menu", "org.eclipse.ui.tests.sharedImagesTest"); + IMenuService menuService = (IMenuService) window.getService(IMenuService.class); + menuService.populateContributionManager(menuManager, "menu:org.eclipse.ui.tests.sharedImagesTest"); + CommandContributionItem item = (CommandContributionItem) menuManager.getItems()[0]; + Field iconField = CommandContributionItem.class.getDeclaredField("icon"); + iconField.setAccessible(true); + ImageDescriptor sharedImageDesc4 = (ImageDescriptor) iconField.get(item); + assertNotNull(sharedImageDesc4); + + // all of them should be the same + assertTrue(sharedImageDesc1 == sharedImageDesc2); + assertTrue(sharedImageDesc1 == sharedImageDesc3); + assertTrue(sharedImageDesc1 == sharedImageDesc4); + + // test platform:/plugin/... format as well + ImageDescriptor sharedImageDesc5 = workbench.getSharedImages().getImageDescriptor("SHARED_IMAGE_TEST2"); + assertNotNull(sharedImageDesc5); + + } +} \ No newline at end of file