blob: 40875d58e81639d9ececbfce40eadd532694db1d [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2006, 2015 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ui.internal.handlers;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
/**
* <p>
* A service which holds mappings between retarget action identifiers and
* command identifiers (aka: action definition ids). This implementation does
* not clean up in the case of dynamic plug-ins.
* </p>
* <p>
* This class is not intended for use outside of the
* <code>org.eclipse.ui.workbench</code> plug-in.
* </p>
*
* @since 3.2
*/
public final class ActionCommandMappingService implements IActionCommandMappingService {
/**
* The map of action identifiers ({@link String}) to command identifiers
* ({@link String}). This value is never <code>null</code>.
*/
private final Map<String, String> mapping = new HashMap<>();
@Override
public String getCommandId(final String actionId) {
if (actionId == null) {
throw new NullPointerException("Cannot get the command identifier for a null action id"); //$NON-NLS-1$
}
return mapping.get(actionId);
}
@Override
public void map(final String actionId, final String commandId) {
if (actionId == null) {
throw new NullPointerException("The action id cannot be null"); //$NON-NLS-1$
}
if (commandId == null) {
throw new NullPointerException("The command id cannot be null"); //$NON-NLS-1$
}
mapping.put(actionId, commandId);
}
@Override
public String getGeneratedCommandId(String targetId, String actionId) {
return IWorkbenchRegistryConstants.AUTOGENERATED_PREFIX + targetId + '/' + actionId;
}
}