Search code examples
eclipse-rcpe4

How to trigger @CanExecute method on TableViewer selection change


i have a Part with toolbar and there is also a TableViewer. Int toolbar i have an edit button, which should be active only when a row in table viewer is selected.

i have added a condition to handler's canExecute method. i can see that this method executes when i click some buttons, but it does not execute when selection in TableViewer is changed, so it does not recognize that the edit button in toolbar should activate.

Maybe i can trigger an exucution of @CanExecute when selection in TableViewer is changed or maybe there is another way?


Solution

  • You can execute the handler using:

    @Inject
    ECommandService commandService;
    
    @Inject
    EHandlerService handlerService;
    
    ...
    
    ParameterizedCommand command = commandService.createCommand("command id", Collections.emptyMap());
    
    if (handlerService.canExecute(command)) {
      handlerService.executeHandler(command);
    }
    

    "command id" is the id of the command that your handler is handling.

    You can request that the tool bar be updated using:

    @Inject
    IEventBroker eventBroker;
    
    ...
    
    eventBroker.send(UIEvents.REQUEST_ENABLEMENT_UPDATE_TOPIC, UIEvents.ALL_ELEMENT_ID);