KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > handlers > ActionCommandMappingService


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.internal.handlers;
13
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
18
19 /**
20  * <p>
21  * A service which holds mappings between retarget action identifiers and
22  * command identifiers (aka: action definition ids). This implementation does
23  * not clean up in the case of dynamic plug-ins.
24  * </p>
25  * <p>
26  * This class is not intended for use outside of the
27  * <code>org.eclipse.ui.workbench</code> plug-in.
28  * </p>
29  *
30  * @since 3.2
31  */

32 public final class ActionCommandMappingService implements
33         IActionCommandMappingService {
34
35     /**
36      * The map of action identifiers ({@link String}) to command identifiers ({@link String}).
37      * This value is never <code>null</code>.
38      */

39     private final Map JavaDoc mapping = new HashMap JavaDoc();
40
41     public final String JavaDoc getCommandId(final String JavaDoc actionId) {
42         if (actionId == null) {
43             throw new NullPointerException JavaDoc(
44                     "Cannot get the command identifier for a null action id"); //$NON-NLS-1$
45
}
46
47         return (String JavaDoc) mapping.get(actionId);
48     }
49
50     public final void map(final String JavaDoc actionId, final String JavaDoc commandId) {
51         if (actionId == null) {
52             throw new NullPointerException JavaDoc("The action id cannot be null"); //$NON-NLS-1$
53
}
54
55         if (commandId == null) {
56             throw new NullPointerException JavaDoc("The command id cannot be null"); //$NON-NLS-1$
57
}
58
59         mapping.put(actionId, commandId);
60     }
61
62     public final String JavaDoc getGeneratedCommandId(String JavaDoc targetId, String JavaDoc actionId) {
63         return IWorkbenchRegistryConstants.AUTOGENERATED_PREFIX + targetId
64                 + '/' + actionId;
65     }
66 }
67
Popular Tags