Wednesday, 27 April 2016

[RCP] How to execute command programmatically in Eclipse RCP.(코드로 Command를 실행)

Sample Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
IHandlerService handlerService = (IHandlerService) HandlerUtil.getActiveSite( event).getService( IHandlerService.class);
ICommandService commandService = (ICommandService) HandlerUtil.getActiveSite( event).getService( ICommandService.class);

// Retrieve the command
Command generateCmd = commandService.getCommand( OpenNewSCPEditorAction.ID);

// Create an ExecutionEvent and specify the IFile associated
ExecutionEvent executionEvent = handlerService.createExecutionEvent(generateCmd, new Event());
            
// Launch the command
try {
    generateCmd.executeWithChecks( executionEvent);
                
} catch ( Exception e) {
    LOG.error( "Failed to open new scp editor.\n{}", ExceptionUtils.getStackTrace( e));
                
}

No comments:

Post a Comment