Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

implement ObservableList, extend ObservableListWrapper

Tags:

java

javafx-2

I want to create a class that is almost identical to the object returned by FXCollections.observableArrayList() but with some extra functionality. My first thought was something like

public class MyObservableList implements ObservableList
{
    private ObservableList list = FXCollections.observableArrayList();

    public functionWhatever()
    {
        // whatever
    }

}

but that means overriding the ~30 functions that come with ObservableList (which seems like a hint that I'm doing something wrong).

FXCollections.observableArrayList() returns an object of type com.sun.javafx.collections.ObservableListWrapper, but when I extend ObservableListWrapper I'm required to create a constructor like

MyObservableList( List arg0 )

or

MyObservableList( List arg0, Callback arg1 )

which worries me because FXCollections.observableArrayList() doesn't accept any arguments.

I don't know how FXCollections creates the ObservableListWrapper object that it returns but I want MyObservableList to be identical to the object returned by FXCollections (plus a couple extra functions).

How do I do this?

like image 667
beardedlinuxgeek Avatar asked Dec 19 '12 00:12

beardedlinuxgeek


1 Answers

Extend SimpleListProperty docs.oracle.com

This class provides a full implementation of a Property wrapping an ObservableList.


Notice this ctor:

public SimpleListProperty(ObservableList initialValue)

So you can:

public class MyObservableList extends SimpleListProperty
{
    //constructor
    MyObservableList(){
        super(FXCollections.observableArrayList());
    }

    public functionWhatever()
    {
        // whatever
    } 

}

This way your class will be based on a ArrayList.

like image 77
drzymala Avatar answered Oct 14 '22 19:10

drzymala