2016-11-15 2 views
0

https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TreeItem.html 다음에 나오는 TreeTableView의 데이터 모델로 사용할 클래스는 myClass extends TreeItem<file>입니다.JavaFX : TreeItem 이벤트를 트리거하는 방법

public class myTreeItem extends TreeItem<File> 
    private boolean isLeaf; 
    private boolean isFirstTimeChildren = true; 
    private boolean isFirstTimeLeaf = true; 

    @Override public ObservableList<TreeItem<File>> getChildren() { 
      // ... full code see link to Oracle documentation 
     return super.getChildren(); 
     } 

     private ObservableList<TreeItem<File>> buildChildren(TreeItem<File> TreeItem) { 
      // ... full code see link to Oracle documentation 
     }; 
} 

나는이 항목에 아이를 추가하는 기능을 추가했습니다. TreeTableView의 정확한 업데이트에 문제가 있습니다. 자세한 내용은 아래의 코드 및 설명을 참조하십시오.

public void addChild(String name) { 
    itemManger.addChild(this.getValue(), name); // Generate Child 
    isFirstTimeChildren = true;  // Ensure that buildChildren() is called, when getchildren() is called. 

// getChildren();     // If I would activate this line, 
             // all listeners would be notified 
             // and the TreeTableView is updated. 
             // This is most likely due to the call super.getChildren(); 

    // However I want to throw the event on my own in order 
    // to avoid the extra call of this.getChildren(). Here is my 
    // (not sufficent) try: 
    EventType<TreeItem.TreeModificationEvent<MLDCostumizableItem>> eventType = TreeItem.treeNotificationEvent(); 
    TreeModificationEvent<MLDCostumizableItem> event = new TreeModificationEvent<>(eventType,this); 
    Event.fireEvent(this, event); 


    // Here I don't know how to get a value for target. 
    // Is there some standard target, which includes all FX components? 

} 

이 이벤트를 올바르게 throw하는 방법은 무엇입니까?

+0

당신이 immeditely 목록을 새로 고치거나 더 나은 것 같은 효과 및 전자 방식의 성능을 가져야한다 갱신되는 목록을 발생시키는 이벤트를 트리거, 왜 전화하지 여부 'getChildren()'을 새로 고침 하시겠습니까? 불필요한 새로 고침을 원하지 않는다면 모든 조상이 확장되었는지 확인하십시오. – fabian

+0

FX 트리거에 대한 더 깊은 이해를 원합니다. 그러므로 내 질문. – BerndGit

+1

여기서 뭘 하려는지 이해가 안되지만, 일반적으로 적절한 생성자를 사용하여'TreeItem.TreeModificationEvent'를 생성 한 다음'Event.fire에서'TreeItem'을 대상으로 제공 할 것이라고 생각합니다. ...)'. 고맙습니다 James_D. –

답변

0

JavaFX에서 트리거가 작동하는 방식에 대해 내가 잘못 이해 한 것 같습니다. 지금 가장 간단한 해결책은 다음과 같습니다

@Override // Taken from Link 
public void update(Observable observ, Object arg1) { 
    if (observ!=this.item) 
    { 
     LOGGER.error(new MLDConnectionException("Unexpected call of update() with observ = " + observ.toString())); 
     return; 
    } 
    // Build new Chidren list 
    try { 
     super.getChildren().removeIf((x) -> true); // empty list 
     super.getChildren().setAll(buildChildren(this)); 
    } catch (MLDConnectionException e) { 
     LOGGER.error("Error when genereting children List: ", e); 
    } 

} 

public File addChild(String name) throws MLDException { 

    File newChild = itemManger.addChild(item, name); 
    update(this.item, null); 
    return newChild; 
}