I added a handler for the eclipse print command like that:
<handler
class="org.acme.PrintHandler"
commandId="org.eclipse.ui.file.print">
<activeWhen>
<with variable="activePart">
<test property="org.acme.printable" />
</with>
</activeWhen>
</handler>
Which works really nicely. But sometimes the enablement of the command changes even though the active part did not. So I want to force a re-evaluation of the activeWhen
part. How do I do this?
I tried something like this:
ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
Command printCommand = service.getCommand("org.eclipse.ui.file.print");
EvaluationContext context = new EvaluationContext(null, lastEditor);
context.addVariable(ISources.ACTIVE_PART_NAME, lastEditor);
ExecutionEvent event = new ExecutionEvent(printCommand, Collections.EMPTY_MAP, null, context);
// this does nothing
printCommand.setEnabled(context);
// this does nothing as well
service.refreshElements("org.eclipse.ui.file.print", null);
// this executes the command
// (but at least re-evaluates it's enablement before)
printCommand.executeWithChecks(event);
I think the
IEvaluationService.requestEvaluation
method may do what you want:The JavaDoc says