package de.factoryfx.factory.atrribute;

import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonCreator;
import de.factoryfx.data.attribute.AttributeMetadata;
import de.factoryfx.data.attribute.ReferenceListAttribute;
import de.factoryfx.data.jackson.ObservableListJacksonAbleWrapper;
import de.factoryfx.factory.FactoryBase;

public class FactoryReferenceListAttribute<L,T extends FactoryBase<L,?>> extends  ReferenceListAttribute<T>{

    @JsonCreator
    protected FactoryReferenceListAttribute() {
        super();
    }

    @JsonCreator
    protected FactoryReferenceListAttribute(ObservableListJacksonAbleWrapper<T> list) {
        super(list);
    }

    public FactoryReferenceListAttribute(Class<T> clazz, AttributeMetadata attributeMetadata) {
        super(clazz, attributeMetadata);
    }

    //Workaround for genrics (T with generic params)
    @SuppressWarnings("unchecked")
    public FactoryReferenceListAttribute(AttributeMetadata attributeMetadata, Class clazz) {
        super(clazz, attributeMetadata);
    }

    public List<L> instances(){
        if (get()==null){
            return null;
        }
        ArrayList<L> result = new ArrayList<>();
        for(T item: get()){
            result.add(item.instance());
        }
        return result;
    }

    public boolean add(T data){
        return get().add(data);
    }
}

@@ -88,16 +88,118 @@
 l.List;%0D
+%0Aimport java.util.Optional;%0D%0Aimport java.util.function.Function;%0D%0Aimport java.util.function.Supplier;%0D
 %0A%0D%0Aimpor
@@ -243,24 +243,56 @@
 onCreator;%0D%0A
+import de.factoryfx.data.Data;%0D%0A
 import de.fa
@@ -1568,11 +1568,458 @@
 %0A    %7D%0D%0A
+%0D%0A    /**customise the list of selectable items*/%0D%0A    public FactoryReferenceListAttribute possibleValueProvider(Function%3CData,List%3CT%3E%3E provider)%7B%0D%0A        super.possibleValueProvider(provider);%0D%0A        return this;%0D%0A    %7D%0D%0A%0D%0A    /**customise how new values are created*/%0D%0A    public FactoryReferenceListAttribute newValueProvider(Supplier%3CT%3E newValueProvider)%7B%0D%0A        super.newValueProvider(newValueProvider);%0D%0A        return this;%0D%0A    %7D%0D%0A%0D%0A
 %7D%0D%0A

fix npe