In Eclipse RCP there are at-least two different ways we can check the state of a menu item or a toolbar item inside a handlers execute method :
Option 1 :
Option 1 :
ICommandService service =(ICommandService)
PlatformUI.getWorkbench().getService(ICommandService.class);
Command command =
service.getCommand("org.eclipse.example.command.toggle");
State state =
command.getState("org.eclipse.example.command.toggleState");
System.out.println(state.getValue());
//state.setValue(!(Boolean) state.getValue());
Option 2:
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Event selEvent = (Event) event.getTrigger();
Widget widget = selEvent.widget;
if (widget instanceof ToolItem) {
isSelected = ((ToolItem)widget).getSelection();
}else {
isSelected = ((MenuItem)widget).getSelection();
}
}