### 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 4 Mar 2009 09:19:03 -0000 @@ -663,6 +663,10 @@ if (pluginId == null || imageFilePath == null) { throw new IllegalArgumentException(); } + + if(imageFilePath.startsWith("org.eclipse.ui.idConstants/org.eclipse.ui.sharedImages")) { //$NON-NLS-1$ + return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(imageFilePath); + } // 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 4 Mar 2009 09:18:59 -0000 @@ -15,6 +15,12 @@ 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; @@ -592,12 +598,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.idConstants"); //$NON-NLS-1$ + IExtension[] extensions = extensionPoint.getExtensions(); + for (int i = 0; i < extensions.length; i++) { + IConfigurationElement[] categories = extensions[i].getConfigurationElements(); + for (int j = 0; j < categories.length; j++) { + if(categories[j].getName().equals("category")) { //$NON-NLS-1$ + String categoryId = categories[j].getAttribute("id"); //$NON-NLS-1$ + if(!categoryId.equals("org.eclipse.ui.sharedImages")) //$NON-NLS-1$ + continue; // we are looking only for org.eclipse.ui.sharedImages constant + IConfigurationElement[] constants = categories[j].getChildren(); + for (int k = 0; k < constants.length; k++) { + String name = constants[k].getAttribute("name"); //$NON-NLS-1$ + try { + URL url = new URL(constants[k].getAttribute("value")); //$NON-NLS-1$ + ImageDescriptor desc = ImageDescriptor.createFromURL(url); + declareImage("org.eclipse.ui.idConstants/"+categoryId+'/'+name, desc, true); //$NON-NLS-1$ + } catch (Exception e) { + String message = "Workbench exception showing specified command line perspective on startup."; //$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 4 Mar 2009 09:19:13 -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 4 Mar 2009 09:19:12 -0000 @@ -57,6 +57,7 @@ ExtPoint.statusHandlers = Status Handlers ExtPoint.installationPages = Installation Pages ExtPoint.tweaklets = Tweaklets (internal/experimental) +ExtPoint.idConstants = ID Constants Views.Category.Basic = General Views.IntroAdapter = Welcome Index: schema/idConstants.exsd =================================================================== RCS file: schema/idConstants.exsd diff -N schema/idConstants.exsd --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ schema/idConstants.exsd 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,146 @@ + + + + + + + + + This extension point is used to register ID constants. The IDs can be grouped into a category and should have a value. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <p>The ID Constant</p> + + + + + + + name of the constant + + + + + + + value of the constant + + + + + + + + + + <p>Category, under which the constants are grouped</p> + + + + + + + + + + id of the category + + + + + + + + + + + + 3.5 + + + + + + + + + The following adds MY_CONSTANT with "Some Value" under a category named as myCategory + +<pre> +<extension point="org.eclipse.ui.idConstants"> + <category id="myCategory"> + <constant + name="MY_CONSTANT" + value="Some Value"/> + </category> +</extension> +<pre> + + + + + + + + + + <p> +This is primarily used by the workbench to add shared images constants. The shared image constants are added to the category org.eclipse.ui.sharedImages</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 4 Mar 2009 09:19:21 -0000 @@ -4122,4 +4122,39 @@ 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 4 Mar 2009 09:19:21 -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,72 @@ +/******************************************************************************* + * 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("org.eclipse.ui.idConstants/org.eclipse.ui.sharedImages/IMAGE1"); + assertNotNull(sharedImageDesc1); + + // test AUIP.imageDescriptorFromPlugin + ImageDescriptor sharedImageDesc2 = AbstractUIPlugin.imageDescriptorFromPlugin(TestPlugin.PLUGIN_ID, "org.eclipse.ui.idConstants/org.eclipse.ui.sharedImages/IMAGE1"); + 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); + + } +} \ No newline at end of file