.next();
final Iterator activationItr = activations.iterator();
// Check the first activation to see if it has changed.
if (activationItr.hasNext()) {
IHandlerActivation activation = (IHandlerActivation) activationItr
.next();
final boolean currentActive = evaluate(activation);
activation.clearResult();
final boolean newActive = evaluate(activation);
if (newActive != currentActive) {
changedCommandIds
.add(activation.getCommandId());
// Then add every other activation as well.
while (activationItr.hasNext()) {
activation = (IHandlerActivation) activationItr
.next();
activation.setResult(newActive);
changedCommandIds.add(activation
.getCommandId());
}
} else {
while (activationItr.hasNext()) {
activation = (IHandlerActivation) activationItr
.next();
// if for some reason another activation
// doesn't match the new result, update and
// mark as changed. It's not as expensive
// as it looks :-)
if (newActive != evaluate(activation)) {
activation.setResult(newActive);
changedCommandIds.add(activation
.getCommandId());
}
}
}
}
}
}
}
}
MultiStatus conflicts = new MultiStatus("org.eclipse.ui.workbench", 0, //$NON-NLS-1$
"A handler conflict occurred. This may disable some commands.", //$NON-NLS-1$
null);
/*
* For every command identifier with a changed activation, we resolve
* conflicts and trigger an update.
*/
final Iterator changedCommandIdItr = changedCommandIds.iterator();
while (changedCommandIdItr.hasNext()) {
final String commandId = (String) changedCommandIdItr.next();
final Object value = handlerActivationsByCommandId.get(commandId);
if (value instanceof IHandlerActivation) {
final IHandlerActivation activation = (IHandlerActivation) value;
updateCommand(commandId, (evaluate(activation) ? activation
: null));
} else if (value instanceof SortedSet) {
final IHandlerActivation activation = resolveConflicts(
commandId, (SortedSet) value, conflicts);
updateCommand(commandId, activation);
} else {
updateCommand(commandId, null);
}