Question

I am making use of eclipse to do web development. The activation of my code requires me to first Save my changes by clicking on one menu item and then clicking on another menu item called Activate so that the changes in saved file are pushed to the server.

I am looking for a way to call to the the Activate menu item once the save button is pressed, so that i can save a click.

Below is the flow I want to achieve.

Make changes -> Press Save menu item -> This automatically calls the Activate Menu Item

Was it helpful?

Solution

Just execute a command, which is related to your Activate menu item:

// Obtain IServiceLocator implementer, e.g. from PlatformUI.getWorkbench():
IServiceLocator serviceLocator = PlatformUI.getWorkbench();
// or a site from within a editor or view:
// IServiceLocator serviceLocator = getSite();

ICommandService commandService = (ICommandService) serviceLocator.getService(ICommandService.class);

try  { 
    // Lookup commmand with its ID
    Command command = commandService.getCommand("org.eclipse.ui.help.helpContents");

    // Optionally pass a ExecutionEvent instance, default no-param arg creates blank event
    command.executeWithChecks(new ExecutionEvent());

} catch (ExecutionException | NotDefinedException |
        NotEnabledException | NotHandledException e) {

    // Replace with real-world exception handling
    e.printStackTrace();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top