The solution to the inability to update the enableWhen state in rcp

When adding an enableWhen event to a command, it is found that it will only change when the workbench is refreshed. The command in the drop-down menu always executes propertyTester to refresh the state when you open the menu, but the command in the toolbar only seems to be changed when the view is switched. The enable display will be changed according to the value in the tester. Trying to use updateElement to setEnable or setBaseEnable in the code doesn't work. Or redraw, update window will not work. So I went to find out what mechanism was used to call test in propertyTest, using IEvaluationService.

Add the following code to the place where enable is required, and the handler status can be refreshed normally.

IEvaluationService evaludationService = (IEvaluationService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(IEvaluationService.class);  
        evaludationService.getCurrentState (). addVariable ("noOfRowsChecked", noOfRowsChecked);  
        evaludationService.requestEvaluation("cn.xxxxxxx.propertytester.canAddValue");  

 

 http://equalxx.iteye.com/blog/2328955

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327070114&siteId=291194637