2016-11-15 5 views
0

私はクラスmyClass extends TreeItem<file>TreeTableViewのデータモデルとして使用します。ここでの例は、ほとんどがhttps://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TreeItem.htmlです。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? 

} 

このイベントを正しくスローするにはどうすればいいですか?

+0

、なぜ呼び出さない:今、最も簡単な解決策があります'getChildren()'はリフレッシュを引き起こしますか?不必要な更新をしたくない場合は、すべての祖先が展開されているかどうかをチェックしてください。 – fabian

+0

FXトリガーについてさらに深く理解したいと思っています。したがって、私の質問。 – BerndGit

+1

ここで何をしようとしているのか分かりませんが、適切なコンストラクタを使用して 'TreeItem.TreeModificationEvent'を作成し、' Event.fireの 'TreeItem'をターゲットとして提供すると思います...) '。 –

答えて

0

JavaFXでトリガがどのように機能するかについて私が誤解していたようです。あなたがimmeditelyリストを更新したり、リフレッシュするためのリストには、同じ効果を有するべきであり、前者のアプローチのパフォーマンスが良いだろう原因となるイベントをトリガするかどうか

@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; 
} 
関連する問題