serviceLocator, activationsByActionId);
} else if (activationsByActionId.containsKey(actionID)) {
final Object value = activationsByActionId
.remove(actionID);
if (value instanceof IHandlerActivation) {
final IHandlerActivation activation = (IHandlerActivation) value;
actionIdByCommandId.remove(activation.getCommandId());
service.deactivateHandler(activation);
activation.getHandler().dispose();
}
} else if (commandId != null
&& actionIdByCommandId.containsKey(commandId)) {
final Object value = activationsByActionId
.remove(actionIdByCommandId.remove(commandId));
if (value instanceof IHandlerActivation) {
final IHandlerActivation activation = (IHandlerActivation) value;
service.deactivateHandler(activation);
activation.getHandler().dispose();
}
}
}
if (commandId != null) {
actionIdByCommandId.put(commandId, actionID);
// Register this as a handler with the given definition id.
// the expression gives the setGlobalActionHandler() a
// priority.
final IHandler actionHandler = new ActionHandler(handler);
Expression handlerExpression = EXPRESSION;
//XXX add new API in next release to avoid down-casting (bug 137091)
if (this instanceof EditorActionBars) {
handlerExpression = ((EditorActionBars)this).getHandlerExpression();
}
final IHandlerActivation activation = service
.activateHandler(commandId, actionHandler,
handlerExpression);
activationsByActionId.put(actionID, activation);
}
}
} else {
if (actionHandlers != null) {
actionHandlers.remove(actionID);
}
// Remove the handler activation.
if (serviceLocator != null) {
final IHandlerService service = (IHandlerService) serviceLocator
.getService(IHandlerService.class);
if (activationsByActionIdByServiceLocator != null) {
final Map activationsByActionId = (Map) activationsByActionIdByServiceLocator
.get(serviceLocator);
if ((activationsByActionId != null)
&& (activationsByActionId.containsKey(actionID))) {
final Object value = activationsByActionId
.remove(actionID);
if (value instanceof IHandlerActivation) {
final IHandlerActivation activation = (IHandlerActivation) value;
actionIdByCommandId.remove(activation.getCommandId());
service.deactivateHandler(activation);
activation.getHandler().dispose();
}
}
}
}
}