Force Neubewertung der Befehlsaktivierung
Ich habe einen Handler für den Eclipse-Druckbefehl hinzugefügt:
<handler
class="org.acme.PrintHandler"
commandId="org.eclipse.ui.file.print">
<activeWhen>
<with variable="activePart">
<test property="org.acme.printable" />
</with>
</activeWhen>
</handler>
Was wirklich gut funktioniert. Aber manchmal ändert sich die Aktivierung des Befehls, obwohl der aktive Teil dies nicht tat. Also möchte ich eine Neubewertung des @ erzwingactiveWhen
Teil. Wie mache ich das
Ich habe so etwas ausprobiert:
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);