Search code examples
eclipseeclipse-rcprcp

change the command ids handler


I need to change the command id's handler . For example ResetPerspectiveHandler's command id is org.eclipse.ui.window.ResetPerspective. So when we give the command is org.eclipse.ui.window.ResetPerspective it will call the ResetPerspectiveHandler. Now I wanted to restrict not to call the ResetPerspectiveHandler instead it should call my own Handlers when I give the org.eclipse.ui.window.ResetPerspective. How do I do that?


Solution

  • You can't override an existing command handler.

    You can use an IExecutionListener to listen for a command being executed using the ICommandService. The listener is informed before and after the command is executed.

    ICommandService commandService = PlatformUI.getWorkbench().getAdapter(ICommandService.class);
    
    commandService.addExecutionListener(listener);
    

    You can also listen to a specific command using:

    Command command = commandService.getCommand("command id");
    
    command.addExecutionListener(listener);