2017-03-06 2 views
0

RAP e4 응용 프로그램의 팝업 메뉴에 대한 동적 하위 메뉴를 만들고 있습니다. 메뉴에는 동일한 명령을 사용하지만 명령 매개 변수가 다른 하나 또는 여러 개의 처리 된 메뉴 항목이 있습니다. 지금까지는 아무것도하지 않고 매개 변수 값을 기록하기로되어있는이 명령에 대한 핸들러도 작성했습니다.eclipse RAP : 동적 처리 된 메뉴 항목이 @CanExecute를 호출 할 수 있지만 @Execute를 호출 할 수없는 이유

@AboutToShow 
public void aboutToShow(List<MMenuElement> items, MPart part, MApplication app) { 
    AnnotationEditorPart aEPart = (AnnotationEditorPart) part.getObject(); 
    List<IAnnotationElement> elements = aEPart.getGrid().getElementsOfCurrentlySelectedCategory(); 
    String catName = ""; 
    if (aEPart.getGrid().getCurrentlySelectedCategory() != null) { 
     catName = aEPart.getGrid().getCurrentlySelectedCategory().getName(); 
    } 

    MMenu subMenu = MMenuFactory.INSTANCE.createMenu(); 
    subMenu.setLabel("Add Element..."); 
    items.add(subMenu); 

    if (catName.equals("")) { 
     //Not a category 
     return; 
    } 

    for (IAnnotationElement element: elements) { 
     if (element.isToBeDisplayed()) { 
      continue; 
     } 

     MHandledMenuItem dynamicItem = MMenuFactory.INSTANCE.createHandledMenuItem(); 
     dynamicItem.setLabel(element.getName()); 
     dynamicItem.setContributorURI("platform:/plugin/org.bgbm.annosys.ui"); 

     MCommand command = app.getCommand(COMMAND_ID); 

     dynamicItem.setCommand(command); 

     MParameter parameter = MCommandsFactory.INSTANCE.createParameter(); 
     parameter.setName("org.bgbm.annosys.ui.commandparameter.annotationElementToAddToCategory"); 
     parameter.setValue(element.getName()); 
     dynamicItem.getParameters().add(parameter); 

     MParameter parameter2 = MCommandsFactory.INSTANCE.createParameter(); 
     parameter2.setName("org.bgbm.annosys.ui.commandparameter.annotationCategoryToAddElementTo"); 
     parameter2.setValue(catName); 
     dynamicItem.getParameters().add(parameter2); 

     subMenu.getChildren().add(dynamicItem); 

     dynamicItem.setEnabled(true); 
     dynamicItem.setCommand(command); 
    } 
} 

는 기본적으로 내가 요소의 목록을 얻을 선택한 범주에 해당 요소를 추가하는 각 요소에 대한 menut 항목을 만들 :

여기에 하위 메뉴를 만드는 코드입니다. 필자가 필요로하는 것은 카테고리의 이름과 엘리먼트의 이름이다. 그래서 그것들을 명령 매개 변수에 넣는다.

이런 종류의 작품. 여기에 핸들러가 있습니다 :

package org.bgbm.annosys.ui.application.parts.handlers; 

import javax.inject.Named; 

import org.bgbm.annosys.logging.Logger; 
import org.eclipse.e4.core.di.annotations.CanExecute; 
import org.eclipse.e4.core.di.annotations.Execute; 

public class AddAnnotationElementToCategoryCommandHandler { 

    /** Default {@link Logger} instance of this class */ 
    final static Logger logger = Logger.getLogger(); 

    @Execute 
    public void execute(@Named("org.bgbm.annosys.ui.commandparameter.annotationElementToAddToCategory") String elementName, 
      @Named("org.bgbm.annosys.ui.commandparameter.annotationCategoryToAddElementTo") String categoryName) { 
     logger.debug("#### clicked: " + elementName + ", " + categoryName); 
    } 

    @CanExecute 
    public boolean canExecute(@Named("org.bgbm.annosys.ui.commandparameter.annotationElementToAddToCategory") String elementName, 
      @Named("org.bgbm.annosys.ui.commandparameter.annotationCategoryToAddElementTo") String categoryName) { 
     logger.debug(elementName + ", " + categoryName); 
     return true; 
    } 

} 

재미있는 점은 canExecute가 명확하게 트리거된다는 것입니다. 콘솔에서 예상되는 결과를 얻고 true 또는 false를 반환하는지 여부에 따라 항목을 평상시처럼 사용하거나 사용하지 않도록 설정합니다.

그러나 항목을 클릭해도 아무런 반응이 없습니다. 로그에 아무것도 없으며 execute 함수에 넣은 다른 코드는 무시됩니다. 이 메서드는 단순히 호출되지 않습니다.

왜 이런 이유가있을 수 있습니까?

편집 :
이제 동적 메뉴 항목에 명령을 묶는 여러 가지 방법을 시도했지만 결과는 동일하게 유지됩니다. 메뉴 항목을 선택할 때 중단 점을 사용하여 디버깅하고 싶습니다. 그러나 프레임 워크가 전체 메뉴 함수를 처리하고 실행 메서드가 호출되지 않으므로 중단 점의 위치를 ​​알 수 없습니다.

아마도 누군가 나를 도와 줄 수 있습니까?

답변

0

디버깅이 진행되는 동안 다양한 invoke(...) 메서드에서 조건부 중단 점을 org.eclipse.e4.core.contexts.ContextInjectionFactory (조건은 qualifier == org.eclipse.e4.core.di.annotations.Execute.class과 같음)으로 설정할 수 있습니다.

프레임 워크 내부로 더 이동하려면 org.eclipse.e4.core.di.annotations.Execute이 참조 된 곳을 확인하고 해당 참조 흔적을 따라 가면 메뉴 항목 렌더러로 연결됩니다.

관련 문제