Add extractor to existing ObservableList

做~自己de王妃 提交于 2019-12-10 17:29:44

问题


I have a model class ModelParent that has an observable list ObservableList<ModelChild>, where ModelChild is another model class, with it's own properties.

class ModelParent { 
    private final ObservableList<ModelChild> children = FXCollections.observableArrayList(); 

    public ObservableList<ModelChild> getChildren() {
        return children;
    }

    // More properties...
}

In certain occasions, I want to have an extractor applied to the list - that is, to be able to be notified when the list changes, or when a certain member of the list changes. The problem is, in different occasions I will want different properties to be watched, and sometimes I don't care at all about them.

I know I can apply an extractor to an ObservableList when I create it, but is it possible to add an extractor to an existing list? Or maybe create an observable list backed by the original (with changes reflected both ways), but with an additional extractor?

I saw this, but it explicitly says that changes done directly to the backing list will not trigger change events. The problem is the same model object instance may be held by a different object that doesn't care about this new extractor, and will happily add or remove items on the original ObservableList.

Does such thing exist in Java 8? Or is there a simple way to implement it myself?

来源:https://stackoverflow.com/questions/34602457/add-extractor-to-existing-observablelist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!