블로그 이미지

GUEST

eclipse 2010. 8. 16. 18:31

eclipse command

rcp나 plugin에서 기능을 추가할 때 action이나 command를 사용한다.
action은 코딩이 간단하지만 UI와 handler가 1:1로 밀결합되고 image icon등이 고정되는 등의 단점이 있어서 command를 주로 사용한다.

plugin에서 command를 추가할 때는 3가지를 고려한다.

command
UI
handler

command
command는 기능에 대한 선언적 정의(declarative definition)이다.
command id를 선언하고 이 id를 menu와 handler에서 command id 항목으로 지정한다.
defaultHandler를 가질 수 있고 하나의 command에 여러 개의 handler를 지정할 수 있다.
그러나 한 시점에 하나의 handler만 활성화된다.

UI
menu를 추가한다. eclipse에서 추가한 기능을 사용하기 위한 interface 역할을 한다.
일반 메뉴, toolbar, view에서의 메뉴, view에서의 toolbar등이 된다.

handler
command의 동작을 구현한다.
activeWhen을 이용하여 활성화되는 시점을 결정할 수 있다.


eclipse toolbar에 올 수 있는 버튼이나 radio 등을 생각해 보자.
이러한 component들은 선택된 상태(또는 체크)에 대한 상태값이 필요하다.
상태값 - state 에 대한 것들은 command에서 지정한다.

example01 - state
<command 
      defaultHandler="com.eclipse_tips.commandstate.BoldHandler" 
      id="com.eclipse-tips.commandState.boldCommand" 
      name="Bold"> 
   <state 
         class="org.eclipse.ui.handlers.RegistryToggleState:true
         id="org.eclipse.ui.commands.toggleState"> 
   </state> 
</command> 

위와 같이 <state> 구분 안에서 eclipse에서 기정의해 놓은 class와 id를 사용할 수 있다. 소스에서는 아래와 같이 사용한다.

public Object execute(ExecutionEvent event) throws ExecutionException { 
     Command command = event.getCommand(); 
     boolean oldValue = HandlerUtil.toggleCommandState(command); 
     // use the old value and perform the operation

    return null; 
}


cf) 기본적으로 command의 state를 update하는 것은 handler의 책임이다. handler는 state를 알고 있으면서 외부에 알려줄 수 있어야 한다.
cf) ...RegistryToggleState:true 이렇게 사용할 수 있는 것은 RegistryToggleState가 IExecutableExtension 인터페이스를 구현하고 있기 때문이다.
':' 뒤의 값은 초기화할 때 사용한다.
또한 PersistentState를 상속받기 때문에 elipse session간 상태값이 남게 된다. eclipse를 재기동해도 state의 최종값이 반영되게 된다.


상황에 따라 다른 handler를 사용할 수 있는 것이 command의 장점이라고 했다. 만일 상황에 따라 다른 state를 사용해야 한다면 command를 <commandParameter>를 이용하여 나누어준다.

example02 - parameterize
<command 
      defaultHandler="com.eclipse_tips.commandstate.AlignHandler" 
      id="com.eclipse-tips.commandState.alignCommand" 
      name="Align Command"> 
   <commandParameter 
         id="org.eclipse.ui.commands.radioStateParameter
         name="State" 
         optional="false"> 
   </commandParameter> 
   <state 
         class="org.eclipse.ui.handlers.RadioState:left" 
         id="org.eclipse.ui.commands.radioState"> 
   </state> 
</command>

code에서는 아래와 같이 사용한다.

public Object execute(ExecutionEvent event) throws ExecutionException { 
    if(HandlerUtil.matchesRadioState(event)) 
        return null; // we are already in the updated state - do nothing 
    String currentState = event.getParameter(RadioState.PARAMETER_ID); 
    // perform task for current state 
    if(currentState.equals("left")) 
    // perform left alignment 
    else if(currentState.equals("center")) 
    // perform center alignment 
    // and so on ... 

    // and finally update the current state 
    HandlerUtil.updateRadioState(event.getCommand(), currentState);

    return null; 
}

,
eclipse 2010. 8. 16. 11:03

eclipse sse

sse(Structured Source Editor)는 eclipse WTP(Web Tools Platform)의 subproject이다.
sse는 xml이나 html과 같이 구조화된 문서를 eclipse editor에서 다룰 수 있게 해 준다.

sse에 이미 기본 structured text editor가 있다. 
이를 확장하여 (구조화된, structured)문서의 타입에 해당하는 editor를 만들 수 있는데, 
sse framework는 subclassing없이 extention point를 이용하여 확장할 수 있게 해 놓았다.

editor configuration extention point 하위에 3개의 configuration element를 추가하고, 
각 element에는 해당 configuration을 구현하는 class가 지정되어야 한다.

editor configuration extention
  sourceViewerConfiguration 
    target : 확장할 editor나 content type id.
    class : org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration 의  subclass
  contentOutlineConfiguration
    target : 확장할 editor나 content type id.
    class : org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration 의 subclass
  propertySheetConfiguration 
    target : 확장할 editor나 content type id.
    class : org.eclipse.wst.sse.ui.views.properties.PropertySheetConfiguration 의 subclass


cf) wtp에는 웹개발을 위한 ide로서의 eclipse를 지원하는 많은 subproject가 있다.
여타 다른 project들이 update를 통해 설치한 후 바로 사용하는데 반해, sse는 rcp나 plugin에서 editor를 직접 (확장하여) 만들 때 사용한다.


SturceViewerConfiguration 
structured text editor의  다양한 속성 - systax highlighting, content assist 등을 접근하고 수정할 수 있다. 
org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration을 상속받아, 편집을 원하는 문서의 확장자에 맞게 subclass를 구현하여 사용한다. 
StructuredTextViewerConfigurationHTML, StructuredTextViewerConfigurationJSP, StructuredTextViewerConfigurationXML, Java SourceViewerConfiguration 등이 해당된다.

ContentOutlineConfiguration
editor의 outline view 속성을 규정한다. editor의 input 자원을 Tree control에 mapping시켜준다.
sse의 org.eclipse.wst.sse.ui.views.ContentOutlineConfiguration을 상속받아 구현한다.

PropertySheetConfiguration
editor의 properties view 속성을 규정한다. editor의 input자원을 Table control에 mapping시켜준다.
sse의 org.eclipse.wst.sse.ui.views.properties.PropertySheetConfiguration을 상속받아 구현한다.



참조 

,
TOTAL TODAY