diff options
author | Paul Webster | 2007-11-08 14:27:49 +0000 |
---|---|---|
committer | Paul Webster | 2007-11-08 14:27:49 +0000 |
commit | 40d8e3cb20f2cb8579e3f45fa30eb335dec05e4e (patch) | |
tree | 2e458f8c33f6ff6bb81ac5470fa3ec206f33ab1c /bundles/org.eclipse.ui.workbench/Eclipse UI | |
parent | c86c45aff4a6b56fd4ae69eeb469df796af9c594 (diff) | |
download | eclipse.platform.ui-40d8e3cb20f2cb8579e3f45fa30eb335dec05e4e.tar.gz eclipse.platform.ui-40d8e3cb20f2cb8579e3f45fa30eb335dec05e4e.tar.xz eclipse.platform.ui-40d8e3cb20f2cb8579e3f45fa30eb335dec05e4e.zip |
Bug 164499 [Commands] org.eclipse.ui.commandImages API and documentation error
Move ICommandImageService into API and make sure it is used by org.eclipse.ui.menus
Diffstat (limited to 'bundles/org.eclipse.ui.workbench/Eclipse UI')
10 files changed, 108 insertions, 88 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/ICommandImageService.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/commands/ICommandImageService.java index fd0cf707d4e..6856d26ecdf 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/ICommandImageService.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/commands/ICommandImageService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. + * Copyright (c) 2005, 2007 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 @@ -8,11 +8,10 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.ui.internal.commands; - -import java.net.URL; +package org.eclipse.ui.commands; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.internal.commands.CommandImageManager; import org.eclipse.ui.services.IDisposable; /** @@ -36,20 +35,15 @@ import org.eclipse.ui.services.IDisposable; * different icons in each location. * </p> * <p> - * This interface should not be implemented or extended by clients. - * </p> - * <p> - * <strong>PROVISIONAL</strong>. This class or interface has been added as - * part of a work in progress. There is a guarantee neither that this API will - * work nor that it will remain the same. Please do not use this API without - * consulting with the Platform/UI team. + * We currently support a default image style (none) and an image style of + * IMAGE_STYLE_TOOLBAR. * </p> * <p> - * This class is eventually intended to exist in - * <code>org.eclipse.ui.commands</code>. + * This interface should not be implemented or extended by clients. It may + * change between now and M6. * </p> * - * @since 3.2 + * @since 3.4 */ public interface ICommandImageService extends IDisposable { @@ -70,50 +64,17 @@ public interface ICommandImageService extends IDisposable { public static final int TYPE_HOVER = CommandImageManager.TYPE_HOVER; /** - * Binds a particular image descriptor to a command id, type and style - * triple - * - * @param commandId - * The identifier of the command to which the image should be - * bound; must not be <code>null</code>. - * @param type - * The type of image to retrieve. This value must be one of the - * <code>TYPE</code> constants defined in this class. - * @param style - * The style of the image; may be <code>null</code>. - * @param descriptor - * The image descriptor. Should not be <code>null</code>. + * The default image style. This is provided when no style is requested or + * when the requested style is unavailable. (Value is <b>null</b>) */ - public void bind(String commandId, int type, String style, - ImageDescriptor descriptor); + public static final String IMAGE_STYLE_DEFAULT = null; /** - * Binds a particular image path to a command id, type and style triple - * - * @param commandId - * The identifier of the command to which the image should be - * bound; must not be <code>null</code>. - * @param type - * The type of image to retrieve. This value must be one of the - * <code>TYPE</code> constants defined in this class. - * @param style - * The style of the image; may be <code>null</code>. - * @param url - * The URL to the image. Should not be <code>null</code>. - */ - public void bind(String commandId, int type, String style, URL url); - - /** - * Generates a style tag that is not currently used for the given command. - * This can be used by applications trying to create a unique style for a - * new set of images. - * - * @param commandId - * The identifier of the command for which a unique style is - * required; must not be <code>null</code>. - * @return A style tag that is not currently used; may be <code>null</code>. + * The image style used for commands in a toolbar. This is useful if you + * want the icon for the command in the toolbar to be different than the one + * that is displayed with menu items. (Value is <b>toolbar</b>) */ - public String generateUnusedStyle(String commandId); + public static final String IMAGE_STYLE_TOOLBAR = "toolbar"; //$NON-NLS-1$ /** * Retrieves the default image associated with the given command in the @@ -170,15 +131,4 @@ public interface ICommandImageService extends IDisposable { * if the given image style cannot be found. */ public ImageDescriptor getImageDescriptor(String commandId, String style); - - /** - * <p> - * Reads the command image information from the registry. This will - * overwrite any of the existing information in the command image service. - * This method is intended to be called during start-up. When this method - * completes, this command image service will reflect the current state of - * the registry. - * </p> - */ - public void readRegistry(); } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java index a09099b1d92..a87f7361f61 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java @@ -118,6 +118,7 @@ import org.eclipse.ui.activities.IWorkbenchActivitySupport; import org.eclipse.ui.application.IWorkbenchConfigurer; import org.eclipse.ui.application.WorkbenchAdvisor; import org.eclipse.ui.browser.IWorkbenchBrowserSupport; +import org.eclipse.ui.commands.ICommandImageService; import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.commands.IWorkbenchCommandSupport; import org.eclipse.ui.contexts.IContextService; @@ -131,7 +132,6 @@ import org.eclipse.ui.internal.browser.WorkbenchBrowserSupport; import org.eclipse.ui.internal.commands.CommandImageManager; import org.eclipse.ui.internal.commands.CommandImageService; import org.eclipse.ui.internal.commands.CommandService; -import org.eclipse.ui.internal.commands.ICommandImageService; import org.eclipse.ui.internal.commands.WorkbenchCommandSupport; import org.eclipse.ui.internal.contexts.ActiveContextSourceProvider; import org.eclipse.ui.internal.contexts.ContextService; diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/actions/CommandAction.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/actions/CommandAction.java index acecd428f7b..144f738b58a 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/actions/CommandAction.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/actions/CommandAction.java @@ -20,10 +20,10 @@ import org.eclipse.core.commands.ParameterizedCommand; import org.eclipse.core.commands.common.NotDefinedException; import org.eclipse.jface.action.Action; import org.eclipse.swt.widgets.Event; +import org.eclipse.ui.commands.ICommandImageService; import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.handlers.IHandlerService; import org.eclipse.ui.internal.WorkbenchPlugin; -import org.eclipse.ui.internal.commands.ICommandImageService; import org.eclipse.ui.services.IServiceLocator; /** diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandImageManager.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandImageManager.java index 48e66704ec3..5e7d51d8744 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandImageManager.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandImageManager.java @@ -28,9 +28,9 @@ import org.eclipse.jface.resource.ImageDescriptor; * Clients may instantiate, but must not extend. * </p> * <p> - * <strong>PROVISIONAL</strong>. This class or interface has been added as - * part of a work in progress. There is a guarantee neither that this API will - * work nor that it will remain the same. Please do not use this API without + * <strong>PROVISIONAL</strong>. This class or interface has been added as part + * of a work in progress. There is a guarantee neither that this API will work + * nor that it will remain the same. Please do not use this API without * consulting with the Platform/UI team. * </p> * <p> @@ -138,11 +138,12 @@ public final class CommandImageManager extends EventManager { if (typedImage instanceof Map) { final Map styleMap = (Map) typedImage; styleMap.put(style, descriptor); - } else if (typedImage instanceof ImageDescriptor) { + } else if (typedImage instanceof ImageDescriptor + || typedImage == null) { final Map styleMap = new HashMap(); styleMap.put(null, typedImage); styleMap.put(style, descriptor); - images[type] = descriptor; + images[type] = styleMap; } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandImageService.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandImageService.java index 10bc1c74193..b467b552c9e 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandImageService.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandImageService.java @@ -13,6 +13,7 @@ package org.eclipse.ui.internal.commands; import java.net.URL; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.commands.ICommandImageService; import org.eclipse.ui.commands.ICommandService; /** @@ -63,11 +64,40 @@ public final class CommandImageService implements ICommandImageService { commandImageManager, commandService); } + /** + * Binds a particular image descriptor to a command id, type and style + * triple + * + * @param commandId + * The identifier of the command to which the image should be + * bound; must not be <code>null</code>. + * @param type + * The type of image to retrieve. This value must be one of the + * <code>TYPE</code> constants defined in this class. + * @param style + * The style of the image; may be <code>null</code>. + * @param descriptor + * The image descriptor. Should not be <code>null</code>. + */ public final void bind(final String commandId, final int type, final String style, final ImageDescriptor descriptor) { commandImageManager.bind(commandId, type, style, descriptor); } + /** + * Binds a particular image path to a command id, type and style triple + * + * @param commandId + * The identifier of the command to which the image should be + * bound; must not be <code>null</code>. + * @param type + * The type of image to retrieve. This value must be one of the + * <code>TYPE</code> constants defined in this class. + * @param style + * The style of the image; may be <code>null</code>. + * @param url + * The URL to the image. Should not be <code>null</code>. + */ public final void bind(final String commandId, final int type, final String style, final URL url) { commandImageManager.bind(commandId, type, style, url); @@ -77,6 +107,16 @@ public final class CommandImageService implements ICommandImageService { commandImagePersistence.dispose(); } + /** + * Generates a style tag that is not currently used for the given command. + * This can be used by applications trying to create a unique style for a + * new set of images. + * + * @param commandId + * The identifier of the command for which a unique style is + * required; must not be <code>null</code>. + * @return A style tag that is not currently used; may be <code>null</code>. + */ public final String generateUnusedStyle(final String commandId) { return commandImageManager.generateUnusedStyle(commandId); } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/CommandLegacyActionWrapper.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/CommandLegacyActionWrapper.java index 7397ef7fd50..5f28eb0a0c2 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/CommandLegacyActionWrapper.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/CommandLegacyActionWrapper.java @@ -35,9 +35,10 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.util.Util; import org.eclipse.swt.events.HelpListener; import org.eclipse.swt.widgets.Event; +import org.eclipse.ui.commands.ICommandImageService; import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.internal.commands.CommandImageManager; -import org.eclipse.ui.internal.commands.ICommandImageService; +import org.eclipse.ui.internal.commands.CommandImageService; import org.eclipse.ui.keys.IBindingService; import org.eclipse.ui.services.IServiceLocator; @@ -446,7 +447,10 @@ public final class CommandLegacyActionWrapper extends AbstractAction { final int type = CommandImageManager.TYPE_DISABLED; final ICommandImageService commandImageService = (ICommandImageService) serviceLocator .getService(ICommandImageService.class); - commandImageService.bind(commandId, type, style, newImage); + if (commandImageService instanceof CommandImageService) { + ((CommandImageService) commandImageService).bind(commandId, type, + style, newImage); + } } public final void setEnabled(final boolean enabled) { @@ -469,7 +473,10 @@ public final class CommandLegacyActionWrapper extends AbstractAction { final int type = CommandImageManager.TYPE_HOVER; final ICommandImageService commandImageService = (ICommandImageService) serviceLocator .getService(ICommandImageService.class); - commandImageService.bind(commandId, type, style, newImage); + if (commandImageService instanceof CommandImageService) { + ((CommandImageService) commandImageService).bind(commandId, type, + style, newImage); + } } public final void setId(final String id) { @@ -481,7 +488,10 @@ public final class CommandLegacyActionWrapper extends AbstractAction { final int type = CommandImageManager.TYPE_DEFAULT; final ICommandImageService commandImageService = (ICommandImageService) serviceLocator .getService(ICommandImageService.class); - commandImageService.bind(commandId, type, style, newImage); + if (commandImageService instanceof CommandImageService) { + ((CommandImageService) commandImageService).bind(commandId, type, + style, newImage); + } } public final void setMenuCreator(final IMenuCreator creator) { diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferencePage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferencePage.java index 1bb27e70316..50031e9aa05 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferencePage.java @@ -112,12 +112,12 @@ import org.eclipse.swt.widgets.TreeColumn; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandImageService; import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.contexts.IContextService; import org.eclipse.ui.dialogs.FilteredTree; import org.eclipse.ui.internal.IWorkbenchHelpContextIds; import org.eclipse.ui.internal.WorkbenchPlugin; -import org.eclipse.ui.internal.commands.ICommandImageService; import org.eclipse.ui.internal.misc.Policy; import org.eclipse.ui.internal.misc.StatusUtil; import org.eclipse.ui.internal.util.BundleUtility; diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuAdditionCacheEntry.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuAdditionCacheEntry.java index 624c9577901..43db81c0e42 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuAdditionCacheEntry.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuAdditionCacheEntry.java @@ -30,6 +30,7 @@ import org.eclipse.jface.action.ToolBarManager; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.actions.CompoundContributionItem; +import org.eclipse.ui.commands.ICommandImageService; import org.eclipse.ui.internal.WorkbenchWindow; import org.eclipse.ui.internal.provisional.presentations.IActionBarPresentationFactory; import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; @@ -195,12 +196,12 @@ public class MenuAdditionCacheEntry extends AbstractContributionFactory { /** * @param configurationElement - * @return + * @return the toolbar contribution item */ private IContributionItem createToolBarAdditionContribution( IActionBarPresentationFactory actionBarPresentationFactory, IConfigurationElement configurationElement) { - if (!getLocation().startsWith("toolbar")) { //$NON-NLS-1$ + if (!inToolbar()) { return null; } if (actionBarPresentationFactory != null) { @@ -213,6 +214,13 @@ public class MenuAdditionCacheEntry extends AbstractContributionFactory { } /** + * @return <code>true</code> if this is a toolbar contribution + */ + private boolean inToolbar() { + return getLocation().startsWith("toolbar"); //$NON-NLS-1$ + } + + /** * @param configurationElement * @return the menu manager */ @@ -221,7 +229,7 @@ public class MenuAdditionCacheEntry extends AbstractContributionFactory { // Is this for a menu or a ToolBar ? We can't create // a menu directly under a Toolbar; we have to add an // item of style 'pulldown' - if (getLocation().startsWith("toolbar")) { //$NON-NLS-1$ + if (inToolbar()) { return null; } @@ -281,7 +289,7 @@ public class MenuAdditionCacheEntry extends AbstractContributionFactory { */ private IContributionItem createControlAdditionContribution( final IConfigurationElement widgetAddition) { - if (!getLocation().startsWith("toolbar")) { //$NON-NLS-1$ + if (!inToolbar()) { return null; } // If we've already tried (and failed) to load the @@ -319,6 +327,9 @@ public class MenuAdditionCacheEntry extends AbstractContributionFactory { getLabel(commandAddition), getMnemonic(commandAddition), getTooltip(commandAddition), getStyle(commandAddition), getHelpContextId(commandAddition)); + if (inToolbar()) { + parm.iconStyle = ICommandImageService.IMAGE_STYLE_TOOLBAR; + } return new CommandContributionItem(parm); } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/menus/CommandContributionItem.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/menus/CommandContributionItem.java index 712a233c22d..fdc58e5680c 100755 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/menus/CommandContributionItem.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/menus/CommandContributionItem.java @@ -44,12 +44,12 @@ import org.eclipse.swt.widgets.Widget; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPartSite; import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.commands.ICommandImageService; import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.commands.IElementReference; import org.eclipse.ui.handlers.IHandlerService; import org.eclipse.ui.help.IWorkbenchHelpSystem; import org.eclipse.ui.internal.WorkbenchPlugin; -import org.eclipse.ui.internal.commands.ICommandImageService; import org.eclipse.ui.keys.IBindingService; import org.eclipse.ui.services.IServiceLocator; @@ -132,7 +132,7 @@ public final class CommandContributionItem extends ContributionItem { * Create a CommandContributionItem to place in a ContributionManager. * * @param contributionParameters - * paramters necessary to render this contribution item. + * parameters necessary to render this contribution item. */ public CommandContributionItem( CommandContributionItemParameter contributionParameters) { @@ -194,7 +194,8 @@ public final class CommandContributionItem extends ContributionItem { elementRef = commandService.registerElementForCommand(command, callback); command.getCommand().addCommandListener(getCommandListener()); - setImages(contributionParameters.serviceLocator); + setImages(contributionParameters.serviceLocator, + contributionParameters.iconStyle); if (contributionParameters.helpContextId == null) { try { @@ -262,16 +263,16 @@ public final class CommandContributionItem extends ContributionItem { mnemonic, tooltip, style, null)); } - private void setImages(IServiceLocator locator) { + private void setImages(IServiceLocator locator, String iconStyle) { if (icon == null) { ICommandImageService service = (ICommandImageService) locator .getService(ICommandImageService.class); icon = service.getImageDescriptor(command.getId(), - ICommandImageService.TYPE_DEFAULT); + ICommandImageService.TYPE_DEFAULT, iconStyle); disabledIcon = service.getImageDescriptor(command.getId(), - ICommandImageService.TYPE_DISABLED); + ICommandImageService.TYPE_DISABLED, iconStyle); hoverIcon = service.getImageDescriptor(command.getId(), - ICommandImageService.TYPE_HOVER); + ICommandImageService.TYPE_HOVER, iconStyle); } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/menus/CommandContributionItemParameter.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/menus/CommandContributionItemParameter.java index 340ed1692d8..1e3995e96be 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/menus/CommandContributionItemParameter.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/menus/CommandContributionItemParameter.java @@ -97,6 +97,13 @@ public class CommandContributionItemParameter { public String helpContextId; /** + * The icon style to use. May be <code>null</code> for default style. + * + * @see org.eclipse.ui.commands.ICommandImageService + */ + public String iconStyle; + + /** * Create the parameter object. Nullable attributes can be set directly. * * @param serviceLocator |