01: /*******************************************************************************
02: * Copyright (c) 2006, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.handlers;
11:
12: import java.util.HashMap;
13: import java.util.Map;
14:
15: import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
16:
17: /**
18: * <p>
19: * A service which holds mappings between retarget action identifiers and
20: * command identifiers (aka: action definition ids). This implementation does
21: * not clean up in the case of dynamic plug-ins.
22: * </p>
23: * <p>
24: * This class is not intended for use outside of the
25: * <code>org.eclipse.ui.workbench</code> plug-in.
26: * </p>
27: *
28: * @since 3.2
29: */
30: public final class ActionCommandMappingService implements
31: IActionCommandMappingService {
32:
33: /**
34: * The map of action identifiers ({@link String}) to command identifiers ({@link String}).
35: * This value is never <code>null</code>.
36: */
37: private final Map mapping = new HashMap();
38:
39: public final String getCommandId(final String actionId) {
40: if (actionId == null) {
41: throw new NullPointerException(
42: "Cannot get the command identifier for a null action id"); //$NON-NLS-1$
43: }
44:
45: return (String) mapping.get(actionId);
46: }
47:
48: public final void map(final String actionId, final String commandId) {
49: if (actionId == null) {
50: throw new NullPointerException(
51: "The action id cannot be null"); //$NON-NLS-1$
52: }
53:
54: if (commandId == null) {
55: throw new NullPointerException(
56: "The command id cannot be null"); //$NON-NLS-1$
57: }
58:
59: mapping.put(actionId, commandId);
60: }
61:
62: public final String getGeneratedCommandId(String targetId,
63: String actionId) {
64: return IWorkbenchRegistryConstants.AUTOGENERATED_PREFIX
65: + targetId + '/' + actionId;
66: }
67: }
|