Execute Command from View/Editor in Eclipse RCP
All Commands will be registered to IHandlerService. If we get the IHandlerService instance then we can call the desired command and then execute it.
// Get the Instance of IHandlerService from View
// Alternate way of getting site object is this also:
// PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite()
// But we prefer following so we get the appropriate IWorkbenchPartSite object.
IHandlerService service = (IHandlerService) getSite().getService(IHandlerService.class);
try {
service.executeCommand("ResumeParser.commands.sampleCommand", null);
} catch (ExecutionException e1) {
e1.printStackTrace();
} catch (NotDefinedException e1) {
e1.printStackTrace();
} catch (NotEnabledException e1) {
e1.printStackTrace();
} catch (NotHandledException e1) {
e1.printStackTrace();
}
Comments
Post a Comment