Eclipse 플랫폼을 이용하여 Eclipse Plug-in 개발시 Command를 직접 호출할 경우가 생기는데 코드 상에서 어떻게 호출 할 수 있는지 설명한다. 

코드는 간단하다. 단순히 Workbench 객체에서 관련 Service 참조 객체를 얻어온 다음 메소드로 실행 시키면 된다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
private void sampleCode() {
    IHandlerService handlerService =
                   (IHandlerService) getSite.getService(IHandlerService.class);
    try {
        handlerService.executeCommand("Command ID", null);
    } catch (ExecutionException e) {
        e.printStackTrace();
    } catch (NotDefinedException e) {
        e.printStackTrace();
    } catch (NotEnabledException e) {
        e.printStackTrace();
    } catch (NotHandledException e) {
        e.printStackTrace();
    }
}


  • 참고 사이트

http://wiki.eclipse.org/Platform_Command_Framework


Posted by 빌리 :