2011-08-03 2 views
3

XTEXT 2.0 플러그인을 개발 중입니다. "가상"노드에서 내 윤곽선 안에 일부 노드를 그룹화하고 싶습니다. 이 결과를 달성하는 올바른 방법은 무엇입니까? 내가 유형 "A"의 그룹 노드에 원하는 경우그룹 개요 노드

현재, 내 OutlineTreeProvider에서 나는 다음과 같은 방법 나는 또한 EStructuralFeatureNode이 있음을 보았다 Xtext 2.0 문서를 읽기

protected void _createNode(IOutlineNode parentNode, A node) { 
if(this.myContainerNode == null){ 
    A container = S3DFactoryImpl.eINSTANCE.createA(); 
    super._createNode(parentNode, container); 
    List<IOutlineNode> children = parentNode.getChildren(); 
    this.myContainerNode = children.get(children.size()-1); 
} 
super._createNode(this.myContainerNode, node); 
} 

을 정의합니다. 이 노드의 유형과 사용 방법을 정확히 이해하지 못했습니다. EStructuralFeatureNode가 사용되는 것을 설명 할 수 있습니까?

많은 감사

답변

2

코드에 문제가 몇 가지가 있습니다

this.myContainerNode : 당신의 공급자가 프로토 타입입니다 보장이 없다가, 누군가 인스턴스를 싱글 톤으로 구성 할 수 있습니다. 따라서 인스턴스 필드를 사용하지 마십시오.

이 문제에 대한 두 가지 해결책이 있습니다

  1. 이 인스턴스에 캐시를 추가 그것은 (느리지 만 간단한)가 필요 때마다 컨테이너 노드의 부모 노드를 검색
  2. ( How do I attach some cached information to an Eclipse editor or resource? 참조)

super._createNode() : _으로 메소드를 호출하지 말고 항상 일반 버전 (super.createNode())을 호출하십시오. 그 방법은 어느 오버로드 된 _create * 메서드를 호출 할지를 결정합니다. 그러나 당신의 경우에는 루프를 얻을 수 있기 때문에 이러한 메서드를 호출 할 수 없습니다. 대신 createEObjectNode()으로 전화하십시오.

마지막으로 A (S3DFactoryImpl.eINSTANCE.createA())의 인스턴스를 만들 필요가 없습니다. 노드는 모델 요소로 백업 할 수 있지만 선택 사항입니다.

이 그룹에 대해, 나는이 클래스를 사용 : 귀하의 경우에는

public class VirtualOutlineNode extends AbstractOutlineNode { 
    protected VirtualOutlineNode(IOutlineNode parent, Image image, Object text, boolean isLeaf) { 
     super(parent, image, text, isLeaf); 
    } 
} 

를, 코드가 너무과 같습니다

protected void _createNode(IOutlineNode parentNode, A node) { 
    VirtualOutlineNode group = findExistingNode(); 
    if(null == group) { 
     group = new VirtualOutlineNode(parentNode, null, "Group A", false); 
    } 
    // calling super._createNode() or super.createNode() would create a loop 
    createEObjectNode(group, node); 
}