### Eclipse Workspace Patch 1.0 #P org.eclipse.ui.tests diff --git Eclipse UI Tests/org/eclipse/ui/tests/TestUtils.java Eclipse UI Tests/org/eclipse/ui/tests/TestUtils.java new file mode 100644 index 0000000..1229de6 --- /dev/null +++ Eclipse UI Tests/org/eclipse/ui/tests/TestUtils.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * 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; + +import java.util.Arrays; + +import junit.framework.Assert; + +/** + * Test helper methods + */ +public class TestUtils { + + /** + * To be replaced with Assert.assertArrayEquals in JUnit 4 + */ + public static void assertArrayEquals(Object[] expecteds, Object[] actuals) { + if (!Arrays.equals(expecteds, actuals)) { + Assert.assertEquals(arrayToString(expecteds), arrayToString(actuals)); + } + } + + /** + * To be replaced with Arrays.toString in Java 1.5 + */ + public static String arrayToString(Object[] array) { + StringBuffer buffer = new StringBuffer(); + if (array == null) + buffer.append("null"); + else { + buffer.append('['); + for (int i = 0; i < array.length; i++) { + buffer.append(array[i]); + if (i != array.length - 1) + buffer.append(','); + } + } + return buffer.toString(); + } +} \ No newline at end of file diff --git Eclipse UI Tests/org/eclipse/ui/tests/commands/CountingHandler.java Eclipse UI Tests/org/eclipse/ui/tests/commands/CountingHandler.java new file mode 100644 index 0000000..e936360 --- /dev/null +++ Eclipse UI Tests/org/eclipse/ui/tests/commands/CountingHandler.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * 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.commands; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; + +public class CountingHandler extends AbstractHandler { + + public int executionCount = 0; + public static CountingHandler lastExecutedHandler = null; + + public Object execute(ExecutionEvent event) { + lastExecutedHandler = this; + executionCount++; + return null; + } + +} \ No newline at end of file diff --git Eclipse UI Tests/org/eclipse/ui/tests/commands/HandlerActivationTest.java Eclipse UI Tests/org/eclipse/ui/tests/commands/HandlerActivationTest.java index 9bfd6aa..125c0df 100644 --- Eclipse UI Tests/org/eclipse/ui/tests/commands/HandlerActivationTest.java +++ Eclipse UI Tests/org/eclipse/ui/tests/commands/HandlerActivationTest.java @@ -264,7 +264,6 @@ public class HandlerActivationTest extends UITestCase { CMD_ID, currentHandler, expression)); } - public void testExceptionThrowingHandler(){ try { @@ -275,7 +274,14 @@ public class HandlerActivationTest extends UITestCase { fail("Unexpected exception while executing command", e); } } - + + public void testHandlerForAliasCommand() throws Exception { + handlerService.executeCommand("org.eclipse.ui.tests.newCommand", null); + assertEquals(1, CountingHandler.lastExecutedHandler.executionCount); + + handlerService.executeCommand("org.eclipse.ui.tests.oldCommand", null); + assertEquals(2, CountingHandler.lastExecutedHandler.executionCount); + } public void testBasicHandler() throws Exception { diff --git Eclipse UI Tests/org/eclipse/ui/tests/menus/MenuBaseTests.java Eclipse UI Tests/org/eclipse/ui/tests/menus/MenuBaseTests.java index b7d0eec..cff9498 100644 --- Eclipse UI Tests/org/eclipse/ui/tests/menus/MenuBaseTests.java +++ Eclipse UI Tests/org/eclipse/ui/tests/menus/MenuBaseTests.java @@ -16,6 +16,8 @@ import org.eclipse.jface.action.MenuManager; import org.eclipse.swt.widgets.Decorations; import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.menus.CommandContributionItem; +import org.eclipse.ui.tests.TestUtils; import org.eclipse.ui.tests.menus.DeclaredProgrammaticFactory.MyItem; /** @@ -40,8 +42,9 @@ public class MenuBaseTests extends MenuTestCase { "MenuTest.Separator", "MenuTest.AfterSeparator", "MenuTest.ParameterItem", - null, // "MenuTest.DynamicItem", + "MenuTest.DynamicItem", "MenuTest.DynamicMenu", + "MenuTest.AliasedCmdItem", "MenuTest.ItemX1", MenuPopulationTest.ID_DEFAULT, MenuPopulationTest.ID_ALL, @@ -61,6 +64,7 @@ public class MenuBaseTests extends MenuTestCase { org.eclipse.ui.menus.CommandContributionItem.class, org.eclipse.ui.menus.CommandContributionItem.class, org.eclipse.ui.menus.CommandContributionItem.class, + org.eclipse.ui.menus.CommandContributionItem.class, MyItem.class }; String[] expectedMenuItemLabels = { @@ -72,42 +76,51 @@ public class MenuBaseTests extends MenuTestCase { "Dynamic Item 1", "Dynamic Item 2", "Dynamic Menu", + "New Command", "Icons Default", "Icons All", "Icons Toolbar Only", "MyItem" }; + + private MenuManager manager; - /** - * @param testName - */ public MenuBaseTests(String testName) { super(testName); } - - public void testBasicPopulation() throws Exception { - MenuManager manager = new MenuManager(null, TEST_CONTRIBUTIONS_CACHE_ID); + + protected void doSetUp() throws Exception { + super.doSetUp(); + manager = new MenuManager("Test Menu", TEST_CONTRIBUTIONS_CACHE_ID); menuService.populateContributionManager(manager, "menu:" + TEST_CONTRIBUTIONS_CACHE_ID); - IContributionItem[] items = manager.getItems(); - - // Correct number of items? - assertEquals("Bad count", expectedIds.length, items.length); - - int diffIndex = checkContribIds(items, expectedIds); - assertTrue("Id mismatch at index " + diffIndex , diffIndex == ALL_OK); - - diffIndex = checkContribClasses(items, expectedClasses); - assertTrue("Class mismatch at index " + diffIndex , diffIndex == ALL_OK); - + } + + protected void doTearDown() throws Exception { menuService.releaseContributions(manager); manager.dispose(); + super.doTearDown(); + } + + public void testContributionItemsCorrect() throws Exception { + IContributionItem[] items = manager.getItems(); + TestUtils.assertArrayEquals(expectedIds, getContributionItemIds(items)); + assertContributionClassesInstanceOf(expectedClasses, items); + } + + public void testAliasedCommandItem() { + IContributionItem[] items = manager.getItems(); + CommandContributionItem aliasedCommandContribution = null; + for (int i = 0; i < items.length; i++) { + if ("MenuTest.AliasedCmdItem".equals(items[i].getId())) { + aliasedCommandContribution = (CommandContributionItem) items[i]; + } + } + assertNotNull("aliasedCommandContribution", aliasedCommandContribution); + assertEquals("org.eclipse.ui.tests.newCommand", aliasedCommandContribution.getCommand().getId()); } - public void testBasicMenuPopulation() throws Exception { - MenuManager manager = new MenuManager("Test Menu", TEST_CONTRIBUTIONS_CACHE_ID); - menuService.populateContributionManager(manager, "menu:" - + TEST_CONTRIBUTIONS_CACHE_ID); + public void testMenuItemsCorrect() throws Exception { Shell shell = window.getShell(); @@ -121,11 +134,7 @@ public class MenuBaseTests extends MenuTestCase { // printClasses(items); // printMenuItemLabels(menuItems); - // Correct number of items? - assertEquals("createMenuBar: Bad count", expectedMenuItemLabels.length, menuItems.length); - - int diffIndex = checkMenuItemLabels(menuItems, expectedMenuItemLabels); - assertTrue("createMenuBar: Index mismatch at index " + diffIndex , diffIndex == ALL_OK); + TestUtils.assertArrayEquals(expectedMenuItemLabels, getMenuItemsLabels(menuItems)); // Test the update mechanism diff --git Eclipse UI Tests/org/eclipse/ui/tests/menus/MenuTestCase.java Eclipse UI Tests/org/eclipse/ui/tests/menus/MenuTestCase.java index 024d109..6af442d 100644 --- Eclipse UI Tests/org/eclipse/ui/tests/menus/MenuTestCase.java +++ Eclipse UI Tests/org/eclipse/ui/tests/menus/MenuTestCase.java @@ -18,6 +18,7 @@ import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.contexts.IContextActivation; import org.eclipse.ui.contexts.IContextService; import org.eclipse.ui.menus.IMenuService; +import org.eclipse.ui.tests.TestUtils; import org.eclipse.ui.tests.api.workbenchpart.MenuContributionHarness; import org.eclipse.ui.tests.harness.util.UITestCase; @@ -49,11 +50,6 @@ public class MenuTestCase extends UITestCase { protected IWorkbenchWindow window; protected IContextActivation activeContext; - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.tests.harness.util.UITestCase#doSetUp() - */ protected void doSetUp() throws Exception { super.doSetUp(); @@ -70,11 +66,6 @@ public class MenuTestCase extends UITestCase { menuService = (IMenuService) window.getService(IMenuService.class); } - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.tests.harness.util.UITestCase#doTearDown() - */ protected void doTearDown() throws Exception { if (activeContext != null) { contextService.deactivateContext(activeContext); @@ -106,27 +97,39 @@ public class MenuTestCase extends UITestCase { return ALL_OK; } - protected static int checkContribClasses(IContributionItem[] items, Class[] classes) { - // Test cases should check this independently so they can issue the - // correct error (i.e. "Not enough items...wanted 6 got 5") but for - // safety's sake... - if (items.length != classes.length) - return 0; - - for (int i = 0; i < classes.length; i++) { - // HACK!! cant find anonyous classes - if (classes[i] == null) - continue; - - // minor upgrade ... if the item is an instanceof the class we're good - // this handles the case where the item is a subclass of - // CompoundContributionItem - if (!classes[i].isInstance(items[i])) - return i; + protected static String[] getContributionItemIds(IContributionItem[] items) { + String[] ids = new String[items.length]; + for (int i = 0; i < items.length; i++) { + if (items[i] != null) { + ids[i] = items[i].getId(); + } } - return ALL_OK; + return ids; } + protected static String[] getMenuItemsLabels(MenuItem[] items) { + String[] ids = new String[items.length]; + for (int i = 0; i < items.length; i++) { + if (items[i] != null) { + ids[i] = items[i].getText(); + } + } + return ids; + } + + protected static void assertContributionClassesInstanceOf(Class[] expectedClasses, + IContributionItem[] items) { + assertEquals("contributed item count, actual items = " + + TestUtils.arrayToString(getContributionItemIds(items)), expectedClasses.length, + items.length); + for (int i = 0; i < expectedClasses.length; i++) { + if (expectedClasses[i] == null) { + assertNull("index " + i, items[i]); + } else { + assertTrue("index " + i, expectedClasses[i].isInstance(items[i])); + } + } + } protected static int checkMenuItemLabels(MenuItem[] menuItems, String[] expectedLabels) { // Test cases should check this independently so they can issue the diff --git Eclipse UI Tests/org/eclipse/ui/tests/themes/JFaceThemeTest.java Eclipse UI Tests/org/eclipse/ui/tests/themes/JFaceThemeTest.java index 770b930..a65dca9 100644 --- Eclipse UI Tests/org/eclipse/ui/tests/themes/JFaceThemeTest.java +++ Eclipse UI Tests/org/eclipse/ui/tests/themes/JFaceThemeTest.java @@ -19,6 +19,7 @@ import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.RGB; +import org.eclipse.ui.tests.TestUtils; import org.eclipse.ui.themes.ITheme; import org.eclipse.ui.themes.IThemeManager; @@ -48,7 +49,7 @@ public class JFaceThemeTest extends ThemeTest { themeFonts.getKeySet())); for (Iterator i = themeFonts.getKeySet().iterator(); i.hasNext();) { String key = (String) i.next(); - assertArrayEquals(themeFonts.getFontData(key), jfaceFonts + TestUtils.assertArrayEquals(themeFonts.getFontData(key), jfaceFonts .getFontData(key)); } } diff --git Eclipse UI Tests/org/eclipse/ui/tests/themes/ThemeAPITest.java Eclipse UI Tests/org/eclipse/ui/tests/themes/ThemeAPITest.java index a0ceb68..7a4e7b2 100644 --- Eclipse UI Tests/org/eclipse/ui/tests/themes/ThemeAPITest.java +++ Eclipse UI Tests/org/eclipse/ui/tests/themes/ThemeAPITest.java @@ -26,6 +26,7 @@ import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.internal.themes.ThemeElementHelper; import org.eclipse.ui.internal.util.PrefUtil; +import org.eclipse.ui.tests.TestUtils; import org.eclipse.ui.themes.ITheme; import org.eclipse.ui.themes.IThemeManager; @@ -36,122 +37,35 @@ import org.eclipse.ui.themes.IThemeManager; */ public class ThemeAPITest extends ThemeTest { - /** - * - */ private static final String EXTENDED_THEME3 = "extendedTheme3"; - /** - * - */ private static final String EXTENDED_THEME2 = "extendedTheme2"; - /** - * - */ private static final String EXTENDED_THEME1 = "extendedTheme1"; - /** - * - */ private static final String PLATFORMFONT = "platformfont"; - /** - * - */ private static final String PLATFORMCOLOR = "platformcolor"; - /** - * - */ private static final String NOOVERRIDEFONT = "nooverridefont"; - /** - * - */ private static final String NOVALFONT = "novalfont"; - /** - * - */ private static final String DEFAULTEDFONT3 = "defaultedfont3"; - /** - * - */ private static final String DEFAULTEDFONT2 = "defaultedfont2"; - /** - * - */ private static final String DEFAULTEDFONT = "defaultedfont"; - /** - * - */ private static final String VALFONT = "valfont"; - /** - * - */ private static final String DEFAULTEDCOLOR3 = "defaultedcolor3"; - /** - * - */ private static final String DEFAULTEDCOLOR2 = "adefaultedcolor2"; - /** - * - */ private static final String VALUE2 = "value2"; - /** - * - */ private static final String OVERRIDE1 = "override1"; - /** - * - */ private static final String NOOVERRIDECOLOR = "nooverridecolor"; - /** - * - */ private static final String DEFAULTEDCOLOR = "defaultedcolor"; - /** - * - */ private static final String SWTCOLOR = "swtcolor"; - /** - * - */ private static final String FACTORYCOLOR = "factorycolor"; - /** - * - */ private static final String RGBCOLOR = "rgbcolor"; - /** - * - */ private static final String BOOL1 = "bool1"; - /** - * - */ private static final String BOGUSKEY = "BOGUSKEY"; - /** - * - */ private static final String INT1 = "int1"; - /** - * - */ private static final String DATA2 = "data2"; - /** - * - */ private static final String DATA1 = "data1"; - /** - * - */ private static final String BAD_COLOR1 = "badColor1"; - /** - * - */ private static final String BAD_COLOR2 = "badColor2"; - /** - * - */ private static final String BAD_COLOR3 = "badColor3"; - /** - * @param testName - */ public ThemeAPITest(String testName) { super(testName); } @@ -165,9 +79,9 @@ public class ThemeAPITest extends ThemeTest { assertEquals(source, event.getSource()); if (array) { - assertArrayEquals((Object[]) oldObject, (Object[]) event + TestUtils.assertArrayEquals((Object[]) oldObject, (Object[]) event .getOldValue()); - assertArrayEquals((Object[]) newObject, (Object[]) event + TestUtils.assertArrayEquals((Object[]) newObject, (Object[]) event .getNewValue()); } else { assertEquals(oldObject, event.getOldValue()); @@ -177,9 +91,9 @@ public class ThemeAPITest extends ThemeTest { event = (PropertyChangeEvent) events.get(1); assertEquals(source, event.getSource()); if (array) { - assertArrayEquals((Object[]) oldObject, (Object[]) event + TestUtils.assertArrayEquals((Object[]) oldObject, (Object[]) event .getNewValue()); - assertArrayEquals((Object[]) newObject, (Object[]) event + TestUtils.assertArrayEquals((Object[]) newObject, (Object[]) event .getOldValue()); } else { assertEquals(oldObject, event.getNewValue()); @@ -348,35 +262,35 @@ public class ThemeAPITest extends ThemeTest { public void testDefaultedFont_valfont() { ITheme defaultTheme = getDefaultTheme(); - assertArrayEquals( + TestUtils.assertArrayEquals( defaultTheme.getFontRegistry().getFontData(VALFONT), defaultTheme.getFontRegistry().getFontData(DEFAULTEDFONT)); } public void testDefaultedFont_defaultedfont() { ITheme defaultTheme = getDefaultTheme(); - assertArrayEquals(defaultTheme.getFontRegistry().getFontData( + TestUtils.assertArrayEquals(defaultTheme.getFontRegistry().getFontData( DEFAULTEDFONT), defaultTheme.getFontRegistry().getFontData( DEFAULTEDFONT2)); } public void testDefaultedFont_defaultedfont2() { ITheme defaultTheme = getDefaultTheme(); - assertArrayEquals(defaultTheme.getFontRegistry().getFontData( + TestUtils.assertArrayEquals(defaultTheme.getFontRegistry().getFontData( DEFAULTEDFONT2), defaultTheme.getFontRegistry().getFontData( DEFAULTEDFONT3)); } public void testDefaultedFontOverride_valfont() { ITheme theme1 = getTheme1(); - assertArrayEquals(theme1.getFontRegistry().getFontData(VALFONT), + TestUtils.assertArrayEquals(theme1.getFontRegistry().getFontData(VALFONT), theme1.getFontRegistry().getFontData(DEFAULTEDFONT)); } public void testDefaultedFontOverride_defaultedfont2() { ITheme theme1 = getTheme1(); - assertArrayEquals(new FontData[] { new FontData("Courier", 16, + TestUtils.assertArrayEquals(new FontData[] { new FontData("Courier", 16, SWT.NORMAL) }, theme1.getFontRegistry().getFontData( DEFAULTEDFONT2)); } @@ -384,7 +298,7 @@ public class ThemeAPITest extends ThemeTest { public void testDefaultedFontOverride_defaultedfont3() { ITheme theme1 = getTheme1(); - assertArrayEquals(theme1.getFontRegistry() + TestUtils.assertArrayEquals(theme1.getFontRegistry() .getFontData(DEFAULTEDFONT2), theme1.getFontRegistry() .getFontData(DEFAULTEDFONT3)); } @@ -502,14 +416,14 @@ public class ThemeAPITest extends ThemeTest { public void testNoValFont() { ITheme defaultTheme = getDefaultTheme(); - assertArrayEquals(defaultTheme.getFontRegistry().defaultFont() + TestUtils.assertArrayEquals(defaultTheme.getFontRegistry().defaultFont() .getFontData(), defaultTheme.getFontRegistry().getFontData( NOVALFONT)); } public void testNoValFontOverride() { ITheme theme1 = getTheme1(); - assertArrayEquals(new FontData[] { new FontData("Courier", 10, + TestUtils.assertArrayEquals(new FontData[] { new FontData("Courier", 10, SWT.ITALIC) }, theme1.getFontRegistry() .getFontData(NOVALFONT)); @@ -536,9 +450,9 @@ public class ThemeAPITest extends ThemeTest { SWT.ITALIC) }; store.setValue(ThemeElementHelper.createPreferenceKey(theme, font), PreferenceConverter.getStoredRepresentation(newFont)); - assertArrayEquals(newFont, theme.getFontRegistry().getFontData(font)); + TestUtils.assertArrayEquals(newFont, theme.getFontRegistry().getFontData(font)); store.setToDefault(ThemeElementHelper.createPreferenceKey(theme, font)); - assertArrayEquals(oldFont, theme.getFontRegistry().getFontData(font)); + TestUtils.assertArrayEquals(oldFont, theme.getFontRegistry().getFontData(font)); } public void testPlatformColor() { @@ -569,7 +483,7 @@ public class ThemeAPITest extends ThemeTest { else data = new FontData[] { new FontData("Sans", 15, SWT.BOLD) }; - assertArrayEquals(data, defaultTheme.getFontRegistry().getFontData( + TestUtils.assertArrayEquals(data, defaultTheme.getFontRegistry().getFontData( PLATFORMFONT)); } @@ -641,7 +555,7 @@ public class ThemeAPITest extends ThemeTest { public void testValFont() { ITheme defaultTheme = getDefaultTheme(); - assertArrayEquals( + TestUtils.assertArrayEquals( new FontData[] { new FontData("Tahoma", 20, SWT.BOLD) }, defaultTheme.getFontRegistry().getFontData(VALFONT)); } @@ -684,10 +598,10 @@ public class ThemeAPITest extends ThemeTest { FontData[] fd = new FontData[] { new FontData("Sans", 10, SWT.NORMAL) }; - assertArrayEquals(fd, ext1.getFontRegistry() + TestUtils.assertArrayEquals(fd, ext1.getFontRegistry() .getFontData(VALFONT)); - assertArrayEquals(fd, ext1.getFontRegistry() + TestUtils.assertArrayEquals(fd, ext1.getFontRegistry() .getFontData(NOVALFONT)); } diff --git Eclipse UI Tests/org/eclipse/ui/tests/themes/ThemeTest.java Eclipse UI Tests/org/eclipse/ui/tests/themes/ThemeTest.java index 8f78eff..3d0cabf 100644 --- Eclipse UI Tests/org/eclipse/ui/tests/themes/ThemeTest.java +++ Eclipse UI Tests/org/eclipse/ui/tests/themes/ThemeTest.java @@ -10,8 +10,6 @@ *******************************************************************************/ package org.eclipse.ui.tests.themes; -import java.util.Arrays; - import org.eclipse.ui.tests.harness.util.UITestCase; import org.eclipse.ui.themes.ITheme; import org.eclipse.ui.themes.IThemeManager; @@ -25,62 +23,24 @@ public abstract class ThemeTest extends UITestCase { protected static final String THEME1 = "theme1"; - public static void assertArrayEquals(Object[] datas, Object[] datas2) { - if (!Arrays.equals(datas, datas2)) { - String expected = formatArray(datas); - String actual = formatArray(datas2); - fail("expected:<" + expected + "> but was:<" + actual + ">"); - } - } - - protected static String formatArray(Object[] datas) { - StringBuffer buffer = new StringBuffer(); - if (datas == null) - buffer.append("null"); - else { - buffer.append('['); - for (int i = 0; i < datas.length; i++) { - buffer.append(datas[i]); - if (i != datas.length - 1) - buffer.append(','); - } - } - return buffer.toString(); - } - protected IThemeManager fManager; - /** - * @param testName - */ public ThemeTest(String testName) { super(testName); - // TODO Auto-generated constructor stub } - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.tests.util.UITestCase#doSetUp() - */ protected void doSetUp() throws Exception { super.doSetUp(); fManager = fWorkbench.getThemeManager(); fManager.setCurrentTheme(IThemeManager.DEFAULT_THEME); } - /** - * @return - */ protected ITheme getDefaultTheme() { ITheme defaultTheme = fManager.getTheme(IThemeManager.DEFAULT_THEME); assertNotNull(defaultTheme); return defaultTheme; } - /** - * @return - */ protected ITheme getTheme1() { ITheme theme1 = fManager.getTheme(THEME1); assertNotNull(theme1); diff --git plugin.xml plugin.xml index e5c3a02..805232a 100644 --- plugin.xml +++ plugin.xml @@ -909,6 +909,17 @@ id="org.eclipse.ui.tests.keyModel.emacs1" name="emacsCommand1"> + + + + + + @@ -3195,6 +3206,13 @@ markerType="org.eclipse.ui.tests.categoryTestMarker"/> + + + + @@ -3820,6 +3838,12 @@ id="MenuTest.DynamicSubItem"> + + #P org.eclipse.ui.workbench diff --git Eclipse UI/org/eclipse/ui/internal/commands/CommandPersistence.java Eclipse UI/org/eclipse/ui/internal/commands/CommandPersistence.java index aeaedc2..abd25e0 100644 --- Eclipse UI/org/eclipse/ui/internal/commands/CommandPersistence.java +++ Eclipse UI/org/eclipse/ui/internal/commands/CommandPersistence.java @@ -13,20 +13,19 @@ package org.eclipse.ui.internal.commands; import java.util.ArrayList; import java.util.List; - import org.eclipse.core.commands.AbstractParameterValueConverter; import org.eclipse.core.commands.Category; import org.eclipse.core.commands.Command; import org.eclipse.core.commands.ParameterType; import org.eclipse.core.commands.State; import org.eclipse.core.commands.common.HandleObject; +import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionDelta; import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.IRegistryChangeEvent; import org.eclipse.core.runtime.Platform; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.internal.WorkbenchMessages; import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; import org.eclipse.ui.internal.services.RegistryPersistence; @@ -34,7 +33,9 @@ import org.eclipse.ui.internal.util.PrefUtil; /** *

- * A static class for accessing the registry and the preference store. + * CommandPersistence is responsible to read commands, categories, parameters, + * states and aliases from the extension registry and to register them with the + * {@link CommandService}. *

* * @since 3.1 @@ -72,14 +73,10 @@ public final class CommandPersistence extends RegistryPersistence { * @param configurationElementCount * The number of configuration elements that are really in the * array. - * @param commandService - * The command service to which the categories should be added; - * must not be null. */ - private static final void readCategoriesFromRegistry( + private final void readCategoriesFromRegistry( final IConfigurationElement[] configurationElements, - final int configurationElementCount, - final ICommandService commandService) { + final int configurationElementCount) { // Undefine all the previous handle objects. final HandleObject[] handleObjects = commandService .getDefinedCategories(); @@ -138,14 +135,10 @@ public final class CommandPersistence extends RegistryPersistence { * @param configurationElementCount * The number of configuration elements that are really in the * array. - * @param commandService - * The command service to which the commands should be added; - * must not be null. */ - private static final void readCommandsFromRegistry( + private final void readCommandsFromRegistry( final IConfigurationElement[] configurationElements, - final int configurationElementCount, - final ICommandService commandService) { + final int configurationElementCount) { // Undefine all the previous handle objects. final HandleObject[] handleObjects = commandService .getDefinedCommands(); @@ -167,6 +160,20 @@ public final class CommandPersistence extends RegistryPersistence { continue; } + IConfigurationElement[] aliases = configurationElement + .getChildren(TAG_COMMAND_ALIAS_FOR); + if (aliases.length > 0) { + if (aliases.length > 1) { + logWarnings(warningsToLog, "There should only be only one aliasFor element"); //$NON-NLS-1$ + } + String targetCommandId = readRequired(aliases[0], ATT_COMMAND_ID, warningsToLog, + "aliasFor needs a commandId"); //$NON-NLS-1$ + commandService.defineAlias(commandId, targetCommandId); + // Other attributes are ignored for alias commands + // as documented in extension point description + continue; + } + // Read out the name. final String name = readRequired(configurationElement, ATT_NAME, warningsToLog, "Commands need a name"); //$NON-NLS-1$ @@ -190,7 +197,7 @@ public final class CommandPersistence extends RegistryPersistence { // Read out the parameters. final Parameter[] parameters = readParameters(configurationElement, - warningsToLog, commandService); + warningsToLog); // Read out the returnTypeId. final String returnTypeId = readOptional(configurationElement, @@ -241,15 +248,12 @@ public final class CommandPersistence extends RegistryPersistence { * The list of warnings found during parsing. Warnings found * while parsing the parameters will be appended to this list. * This value must not be null. - * @param commandService - * The command service from which the parameter can get parameter - * types; must not be null. * @return The array of parameters found for this configuration element; * null if none can be found. */ - private static final Parameter[] readParameters( + private final Parameter[] readParameters( final IConfigurationElement configurationElement, - final List warningsToLog, final ICommandService commandService) { + final List warningsToLog) { final IConfigurationElement[] parameterElements = configurationElement .getChildren(TAG_COMMAND_PARAMETER); if ((parameterElements == null) || (parameterElements.length == 0)) { @@ -318,15 +322,11 @@ public final class CommandPersistence extends RegistryPersistence { * @param configurationElementCount * The number of configuration elements that are really in the * array. - * @param commandService - * The command service to which the commands should be added; - * must not be null. * @since 3.2 */ - private static final void readParameterTypesFromRegistry( + private final void readParameterTypesFromRegistry( final IConfigurationElement[] configurationElements, - final int configurationElementCount, - final ICommandService commandService) { + final int configurationElementCount) { // Undefine all the previous handle objects. final HandleObject[] handleObjects = commandService @@ -425,7 +425,7 @@ public final class CommandPersistence extends RegistryPersistence { * The command service with which this persistence class is associated; * never null. */ - private final ICommandService commandService; + private final CommandService commandService; /** * Constructs a new instance of CommandPersistence. @@ -434,10 +434,8 @@ public final class CommandPersistence extends RegistryPersistence { * The command service which should be populated with the values * from the registry; must not be null. */ - CommandPersistence(final ICommandService commandService) { - if (commandService == null) { - throw new NullPointerException("The command service cannot be null"); //$NON-NLS-1$ - } + CommandPersistence(final CommandService commandService) { + Assert.isNotNull(commandService, "commandService"); //$NON-NLS-1$ this.commandService = commandService; } @@ -462,10 +460,6 @@ public final class CommandPersistence extends RegistryPersistence { /** * Reads all of the commands and categories from the registry, - * - * @param commandService - * The command service which should be populated with the values - * from the registry; must not be null. */ protected final void read() { super.read(); @@ -519,12 +513,12 @@ public final class CommandPersistence extends RegistryPersistence { readCategoriesFromRegistry( indexedConfigurationElements[INDEX_CATEGORY_DEFINITIONS], - categoryDefinitionCount, commandService); + categoryDefinitionCount); readCommandsFromRegistry( indexedConfigurationElements[INDEX_COMMAND_DEFINITIONS], - commandDefinitionCount, commandService); + commandDefinitionCount); readParameterTypesFromRegistry( indexedConfigurationElements[INDEX_PARAMETER_TYPE_DEFINITIONS], - parameterTypeDefinitionCount, commandService); + parameterTypeDefinitionCount); } } diff --git Eclipse UI/org/eclipse/ui/internal/commands/CommandService.java Eclipse UI/org/eclipse/ui/internal/commands/CommandService.java index 2c448fd..2f91b1b 100644 --- Eclipse UI/org/eclipse/ui/internal/commands/CommandService.java +++ Eclipse UI/org/eclipse/ui/internal/commands/CommandService.java @@ -17,7 +17,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; - import org.eclipse.core.commands.Category; import org.eclipse.core.commands.Command; import org.eclipse.core.commands.CommandManager; @@ -31,9 +30,9 @@ import org.eclipse.core.commands.common.NotDefinedException; import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.SafeRunner; import org.eclipse.jface.commands.PersistentState; +import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.commands.IElementReference; import org.eclipse.ui.commands.IElementUpdater; -import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.internal.WorkbenchPlugin; import org.eclipse.ui.internal.util.PrefUtil; import org.eclipse.ui.menus.UIElement; @@ -335,4 +334,17 @@ public final class CommandService implements ICommandService { public CommandPersistence getCommandPersistence() { return commandPersistence; } + + /** + * Defines an alias in the underlying CommandManager. + * + * @see CommandManager#defineAlias(String, String) + * @param sourceCommandId + * alias command id + * @param targetCommandId + * alias target command id + */ + protected void defineAlias(String sourceCommandId, String targetCommandId) { + commandManager.defineAlias(sourceCommandId, targetCommandId); + } } diff --git Eclipse UI/org/eclipse/ui/internal/registry/IWorkbenchRegistryConstants.java Eclipse UI/org/eclipse/ui/internal/registry/IWorkbenchRegistryConstants.java index 90123e0..f61a2e1 100644 --- Eclipse UI/org/eclipse/ui/internal/registry/IWorkbenchRegistryConstants.java +++ Eclipse UI/org/eclipse/ui/internal/registry/IWorkbenchRegistryConstants.java @@ -945,6 +945,11 @@ public interface IWorkbenchRegistryConstants { public static String TAG_COMMAND = "command"; //$NON-NLS-1$ /** + * The name of the element storing an alias. + */ + public static String TAG_COMMAND_ALIAS_FOR = "aliasFor"; //$NON-NLS-1$ + + /** * The name of the element storing a parameter. */ public static String TAG_COMMAND_PARAMETER = "commandParameter"; //$NON-NLS-1$ #P org.eclipse.core.commands diff --git src/org/eclipse/core/commands/CommandManager.java src/org/eclipse/core/commands/CommandManager.java index 1fa61a8..a98b209 100644 --- src/org/eclipse/core/commands/CommandManager.java +++ src/org/eclipse/core/commands/CommandManager.java @@ -285,6 +285,13 @@ public final class CommandManager extends HandleObjectManager implements */ private final Map parameterTypesById = new HashMap(); + + /** + * Map holding command aliases mapping from sourceCommandId + * to targetCommandId. + */ + private Map commandIdAliases = new HashMap(); + /** * Adds a listener to this command manager. The listener will be notified * when the set of defined commands changes. This can be used to track the @@ -543,7 +550,7 @@ public final class CommandManager extends HandleObjectManager implements public final Command getCommand(final String commandId) { checkId(commandId); - Command command = (Command) handleObjectsById.get(commandId); + Command command = (Command) handleObjectsById.get(resolveAlias(commandId)); if (command == null) { command = new Command(commandId); handleObjectsById.put(commandId, command); @@ -1048,4 +1055,31 @@ public final class CommandManager extends HandleObjectManager implements executionListener.postExecuteFailure(commandId, exception); } } + + /** + * Defines an alias from sourceCommandId to targetCommandId. This makes + * getCommand(sourceCommandId) equivalent to getCommand(targetCommandId). + * + * @param sourceCommandId + * command id of alias command + * @param targetCommandId + * command id of alias target + */ + public void defineAlias(String sourceCommandId, String targetCommandId) { + commandIdAliases.put(sourceCommandId, targetCommandId); + } + + /** + * Returns the alias target command id if an alias for the given commandId was + * defined. If no alias is defined, the given commandId is returned unchanged. + * + * @param commandId + * command id to resolve + * @return alias target command id or given command id if no alias was + * defined. + */ + private String resolveAlias(String commandId) { + String targetCommandId = (String) commandIdAliases.get(commandId); + return targetCommandId != null ? targetCommandId : commandId; + } } #P org.eclipse.ui diff --git schema/commands.exsd schema/commands.exsd index 157ce95..ff99d35 100644 --- schema/commands.exsd +++ schema/commands.exsd @@ -2,9 +2,9 @@ - + - + <p> The <code>org.eclipse.ui.commands</code> extension point is used to declare commands and command categories, using the <code>command</code> and <code>category</code> elements. A command is an abstract representation of some semantic behaviour, but not it's actual implementation. This allows different developers to contribute specific behaviour for their individual parts. For example, there might be a "paste" command with one implementation in an editor and a different implementation in an explorer widget. These implementations are called handlers. Commands can also be viewed as declarative function pointers, or signal handlers. @@ -13,6 +13,11 @@ The <code>org.eclipse.ui.commands</code> extension point is used to + + + + + @@ -36,9 +41,9 @@ The <code>org.eclipse.ui.commands</code> extension point is used to An optional name of the extension instance. - + - + @@ -64,15 +69,16 @@ This element is used to define commands. A command represents an request from th + Please use <code>categoryId</code> instead. - + - + @@ -80,9 +86,9 @@ This element is used to define commands. A command represents an request from th A translatable short description of this command for display in the UI. - + - + @@ -97,9 +103,9 @@ This element is used to define commands. A command represents an request from th The translatable name of this command for display in the UI. Commands are typically named in the form of an imperative verb. - + - + @@ -110,9 +116,9 @@ The unique id of the category for this command. If this command does not specify </p> <p><em>Since: 3.0</em></p> - + - + @@ -123,9 +129,9 @@ The default handler for this command (see the <a href="org_eclipse_ui_ha </p> <p><em>Since: 3.1</em></p> - + - + @@ -136,9 +142,9 @@ The id of a <code>commandParameterType</code> indicating the type of </p> <p><em>Since: 3.2</em></p> - + - + @@ -168,9 +174,9 @@ In the UI, commands are often organized by category to make them more manageable A translatable short description of this category for display in the UI. - + - + @@ -185,9 +191,9 @@ In the UI, commands are often organized by category to make them more manageable The translatable name of this category for display in the UI. - + - + @@ -195,9 +201,9 @@ In the UI, commands are often organized by category to make them more manageable - + - + <p> Defines a parameter that a command should understand. A parameter is a way to provide more information to a handler at execution time. For example, a "show view" command might take a view as a parameter. Handlers should be able to understand these parameters, so they should be treated like API. @@ -221,9 +227,9 @@ Defines a parameter that a command should understand. A parameter is a way to p The name for the parameter. This is the name as it will be displayed to an end-user. As such, it should be translatable. The name should be short -- preferrably one word. - + - + @@ -231,9 +237,9 @@ Defines a parameter that a command should understand. A parameter is a way to p The class providing a list of parameter values for the user to select. This class should implement <code>org.eclipse.core.commands.IParameterValues</code>. If this class is not specified, you must specify the more verbose <code>values</code> element. Please see <code>org.eclipse.core.runtime.IExecutableExtension</code>. - + - + @@ -241,9 +247,9 @@ Defines a parameter that a command should understand. A parameter is a way to p The id of a commandParameterType for this commandParameter. Specifying a typeId allows handlers of a command to convert string parameter values to objects in a consistent way and it allows potential callers of a command to look for commands that take objects of various types for their parameters. - + - + @@ -278,9 +284,9 @@ Defines the object type of a commandParameter and may specify an <code>org The fully qualified name of a Java class or interface to use as the type of this command parameter. This attribute is optional, however if omitted, <code>java.lang.Object</code> will be used as the parameter type. - + - + @@ -288,9 +294,9 @@ Defines the object type of a commandParameter and may specify an <code>org The class for converting between objects and string representations of objects for command parameter values. This class should extend <code>org.eclipse.core.commands.AbstractParameterValueConverter</code>. The converter should produce and consume objects of the type indicated in the <code>type</code> attribute. If this class is not specified, this facility to convert between string and object values for this parameter type will not be available (the <code>getValueConverter()</code> on class <code>ParameterType</code> will return <code>null</code>). - + - + @@ -298,9 +304,9 @@ Defines the object type of a commandParameter and may specify an <code>org - + - + <p> The more verbose version of the <code>values</code> attribute on the <code>commandParameter</code>. @@ -317,9 +323,9 @@ The more verbose version of the <code>values</code> attribute on the The class providing a list of parameter values for the user to select. This class should implement <code>org.eclipse.core.commands.IParameterValues</code>. If this class is not specified, you must specify the more verbose <code>values</code> element. Please see <code>org.eclipse.core.runtime.IExecutableExtension</code>. - + - + @@ -327,9 +333,9 @@ The more verbose version of the <code>values</code> attribute on the - + - + <p> A possible value for a parameter. @@ -357,9 +363,9 @@ A possible value for a parameter. - + - + <p> The default handler for this command. If no other handler is active, this handler will be active. This handler will conflict with other handler definitions that specify no <code>activeWhen</code> conditions. If you are not creating an <code>IExecutableExtension</code>, you can use the <code>defaultHandler</code> attribute instead. @@ -376,9 +382,9 @@ The default handler for this command. If no other handler is active, this handl The class which implements <code>org.eclipse.core.commands.IHandler</code>. - + - + @@ -386,9 +392,9 @@ The default handler for this command. If no other handler is active, this handl - + - + <p> State information shared between all handlers, and potentially persisted between sessions.The state is simply a class that is loaded to look after the state. See the API Information for more details. This is not used for UI attributes like a menu contribution check box state or label. @@ -405,9 +411,9 @@ State information shared between all handlers, and potentially persisted between The class that can be loaded to store the state of this command. State is shared amongst handlers, and can be persisted between sessions. This class must subclass <code>org.eclipse.core.commands.State</code>. Please see API Information. - + - + @@ -424,9 +430,9 @@ A unique identifier for this state. This is used for persisting the state betwe - + - + <p> The class that can be loaded to store the state of this command. This element is used if you wish to pass multiple parameters to an <code>org.eclipse.core.runtime.IExecutableExtension</code>. @@ -443,9 +449,9 @@ The class that can be loaded to store the state of this command. This element i The class that can be loaded to store the state of this command. State is shared amongst handlers, and can be persisted between sessions. This class must implement <code>org.eclipse.core.commands.State</code>. Please see API Information. - + - + @@ -453,9 +459,9 @@ The class that can be loaded to store the state of this command. This element i - + - + This element is used to define key configurations. If more than one of these elements exist with the same <code>id</code> attribute, only the last declared element (in order of reading the plugin registry) is considered valid. Please use the "org.eclipse.ui.bindings" extension point instead. @@ -466,9 +472,9 @@ The class that can be loaded to store the state of this command. This element i A translatable short description of this key configuration for display in the UI. - + - + @@ -476,9 +482,9 @@ The class that can be loaded to store the state of this command. This element i The unique identifier of this key configuration. - + - + @@ -486,9 +492,9 @@ The class that can be loaded to store the state of this command. This element i The translatable name of this key configuration for display in the UI. If this key configuration has a parent, it is not necessary to add "(extends ...)" to the name. This will be automatically added by the UI where necessary. - + - + @@ -497,9 +503,9 @@ The class that can be loaded to store the state of this command. This element i The unique id of the parent key configuration. If this key configuration has a parent, it will borrow all key bindings from its parent, in addition to the key bindings defined in its own key configuration. @deprecated Please use parentId instead. - + - + @@ -507,9 +513,9 @@ The class that can be loaded to store the state of this command. This element i The unique id of the parent key configuration. If this key configuration has a parent, it will borrow all key bindings from its parent, in addition to the key bindings defined in its own key configuration. - + - + @@ -517,9 +523,9 @@ The class that can be loaded to store the state of this command. This element i - + - + This element is used to define contexts. If more than one of these elements exist with the same <code>id</code> attribute, only the last declared element (in order of reading the plugin registry) is considered valid. Please use the <a href="org_eclipse_ui_contexts.html">org.eclipse.ui.contexts</a> extension point instead. @@ -530,9 +536,9 @@ The class that can be loaded to store the state of this command. This element i A translatable short description of this context for display in the UI. - + - + @@ -540,9 +546,9 @@ The class that can be loaded to store the state of this command. This element i The unique identifier of this context. - + - + @@ -550,9 +556,9 @@ The class that can be loaded to store the state of this command. This element i The translatable name of this context for display in the UI. If this context has a parent, it is not necessary to add "(extends parent)" to the name. This will be automatically added by the UI where necessary. - + - + @@ -561,9 +567,9 @@ The class that can be loaded to store the state of this command. This element i The unique id of the parent context. If this context has a parent, it will borrow all key bindings from its parent, in addition to the key bindings defined in its own context. @deprecated Please use "parentId" instead. - + - + @@ -571,9 +577,9 @@ The class that can be loaded to store the state of this command. This element i The unique id of the parent context. If this context has a parent, it will borrow all key bindings from its parent, in addition to the key bindings defined in its own context. - + - + @@ -581,9 +587,9 @@ The class that can be loaded to store the state of this command. This element i - + - + This element is used to define scopes. If more than one of these elements exist with the same <code>id</code> attribute, only the last declared element (in order of reading the plugin registry) is considered valid. @deprecated Please use the "org.eclipse.ui.contexts" extension point instead. @@ -597,9 +603,9 @@ The class that can be loaded to store the state of this command. This element i @deprecated Please use the "org.eclipse.ui.contexts" extension point instead. - + - + @@ -609,9 +615,9 @@ The class that can be loaded to store the state of this command. This element i @deprecated Please use the "org.eclipse.ui.contexts" extension point instead. - + - + @@ -621,9 +627,9 @@ The class that can be loaded to store the state of this command. This element i @deprecated Please use the "org.eclipse.ui.contexts" extension point instead. - + - + @@ -633,9 +639,9 @@ The class that can be loaded to store the state of this command. This element i @deprecated Please use the "org.eclipse.ui.contexts" extension point instead. - + - + @@ -643,9 +649,9 @@ The class that can be loaded to store the state of this command. This element i - + - + <p> This element is used to define the initial active key configuration for Eclipse. If more than one of these elements exist, only the last declared element (in order of reading the plugin registry) is considered valid. @@ -661,9 +667,9 @@ This element has been replaced with a preference. If your application needs to The unique id (<code>id</code> attribute) of the keyConfiguration element one wishes to be initially active. - + - + @@ -671,9 +677,9 @@ This element has been replaced with a preference. If your application needs to The unique id (<code>id</code> attribute) of the keyConfiguration element one wishes to be initially active. - + - + @@ -681,9 +687,9 @@ This element has been replaced with a preference. If your application needs to - + - + This element allows one to assign key sequences to commands. Please use the <code>key</code> element in the "org.eclipse.ui.bindings" extension point instead. @@ -695,9 +701,9 @@ This element has been replaced with a preference. If your application needs to The unique id of the key configuration of this key binding. @deprecated Please use keyConfigurationId instead. - + - + @@ -706,9 +712,9 @@ This element has been replaced with a preference. If your application needs to The unique identifier of the command to which the key sequence specified by this key binding is assigned. If the value of this attribute is an empty string, the key sequence is assigned to an internal 'no operation' command. This is useful for 'undefining' key bindings in specific key configurations and contexts which may have been borrowed from their parents. @deprecated Please use "commandId" instead. - + - + @@ -716,9 +722,9 @@ This element has been replaced with a preference. If your application needs to An optional attribute indicating that this key binding is only defined for the specified locale. Locales are specified according to the format declared in <code>java.util.Locale</code>. - + - + @@ -726,9 +732,9 @@ This element has been replaced with a preference. If your application needs to An optional attribute indicating that this key binding is only defined for the specified platform. The possible values of the <code>platform</code> attribute are the set of the possible values returned by <code>org.eclipse.swt.SWT.getPlatform()</code>. - + - + @@ -736,9 +742,9 @@ This element has been replaced with a preference. If your application needs to The unique id of the context of this key binding. - + - + @@ -747,9 +753,9 @@ This element has been replaced with a preference. If your application needs to The key sequence to assign to the command. Key sequences consist of one or more key strokes, where a key stroke consists of a key on the keyboard, optionally pressed in combination with one or more of the following modifiers: Ctrl, Alt, Shift, and Command. Key strokes are separated by spaces, and modifiers are separated by '+' characters. @deprecated Please use "keySequence" instead. - + - + @@ -758,9 +764,9 @@ This element has been replaced with a preference. If your application needs to The unique id of the context of this key binding. @deprecated Please use "contextId" instead. The old default scope, "org.eclipse.ui.globalScope", has been changed to "org.eclipse.ui.contexts.window". The old name is still supported, but it is deprecated. - + - + @@ -769,9 +775,9 @@ This element has been replaced with a preference. If your application needs to The unique id of the key configuration of this key binding. @deprecated Please use the <code>schemeId</code> attribute on the <code>key</code> element in the new "org.eclipse.ui.bindings" extension point. - + - + @@ -779,9 +785,9 @@ This element has been replaced with a preference. If your application needs to The unique identifier of the command to which the key sequence specified by this key binding is assigned. If the value of this attribute is an empty string, the key sequence is assigned to an internal 'no operation' command. This is useful for 'undefining' key bindings in specific key configurations and contexts which may have been borrowed from their parents. - + - + @@ -791,27 +797,47 @@ This element has been replaced with a preference. If your application needs to <p>The modifier keys can also be expressed in a platform-independent way. On MacOS X, for example, "Command" is almost always used in place of "Ctrl". So, we provide "M1" which will map to either "Ctrl" or "Command", as appropriate. Similarly, "M2" is "Shift"; "M3" is "Alt"; and "M4" is "Ctrl" (MacOS X). If more platforms are added, then you can count on these aliases being mapped to good platform defaults.</p> <p>The syntax for this string is defined in <code>org.eclipse.ui.internal.keys</code>. Briefly, the string is case insensitive -- though all capitals is preferred stylistically. If the key is a letter, then simply append the letter. If the key is a special key (i.e., non-ASCII), then use one of the following: ARROW_DOWN, ARROW_LEFT, ARROW_RIGHT, ARROW_UP, BREAK, CAPS_LOCK, END, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14, F15, HOME, INSERT, NUM_LOCK, NUMPAD_0, NUMPAD_1, NUMPAD_2, NUMPAD_3, NUMPAD_4, NUMPAD_5, NUMPAD_6, NUMPAD_7, NUMPAD_8, NUMPAD_9, NUMPAD_ADD, NUMPAD_DECIMAL, NUMPAD_DIVIDE, NUMPAD_ENTER, NUMPAD_EQUAL, NUMPAD_MULTIPLY, NUMPAD_SUBTRACT, PAGE_UP, PAGE_DOWN, PAUSE, PRINT_SCREEN, or SCROLL_LOCK. If the key is a non-printable ASCII key, then use one of the following: BS, CR, DEL, ESC, FF, LF, NUL, SPACE, TAB, or VT. Note that the main keyboard enter/return key is CR.</p> - + - + + + + + + + + + + Adding an "aliasFor" element to a command makes the command an alias for another command specified by the "commandId" attribute of the "aliasFor" element. This allows to refactor commands and change their ids in a backward-compatible fashion by defining a new command and making the old one an alias for the new one. All attributes of the alias command except the id will be ignored. The command itself will not be defined, wherever the command id is used, the alias command is used instead. + + + + + + + This is the id of the Command that this command is an alias for. + + + + - + - + -2.1 + 2.1 - + - + <p> The <code>plugin.xml</code> file in the <code>org.eclipse.ui</code> plugin makes extensive use of the <code>org.eclipse.ui.commands</code> extension point. @@ -820,9 +846,9 @@ The <code>plugin.xml</code> file in the <code>org.eclipse.ui&l - + - + <p> Handlers can be registered with commands using the <code>org.eclipse.ui.handlers.IHandlerService</code>. This can be retrieved from various workbench components (e.g., workbench, workbench window, part site, etc.) by calling <code>getService(IHandlerService.class)</code>. @@ -845,11 +871,10 @@ There are a few default implementations of handler states that may be useful to - - + - + Copyright (c) 2000, 2007 IBM Corporation and others.<br> All rights reserved. This program and the accompanying materials are made