package com.arondor.common.reflection.gwt.client.presenter.fields;

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

import com.arondor.common.reflection.gwt.client.presenter.TreeNodePresenter;
import com.arondor.common.reflection.model.config.ElementConfiguration;
import com.arondor.common.reflection.model.config.ListConfiguration;
import com.arondor.common.reflection.model.config.ObjectConfigurationFactory;
import com.arondor.common.reflection.model.config.PrimitiveConfiguration;

public class StringListTreeNodePresenter implements TreeNodePresenter
{
    private final String fieldName;

    public interface StringListDisplay extends ValueDisplay<List<String>>
    {
    }

    private final StringListDisplay primitiveDisplay;

    public StringListTreeNodePresenter(String fieldName, StringListDisplay primitiveDisplay)
    {
        this.fieldName = fieldName;
        this.primitiveDisplay = primitiveDisplay;
    }

    public String getFieldName()
    {
        return fieldName;
    }

    public ElementConfiguration getElementConfiguration(ObjectConfigurationFactory objectConfigurationFactory)
    {
        // TODO Auto-generated method stub
        return null;
    }

    public void setElementConfiguration(ElementConfiguration elementConfiguration)
    {
        if (elementConfiguration instanceof ListConfiguration)
        {
            ListConfiguration listConfiguration = (ListConfiguration) elementConfiguration;
            List<String> stringList = new ArrayList<String>();
            for (ElementConfiguration childConfiguration : listConfiguration.getListConfiguration())
            {
                if (childConfiguration instanceof PrimitiveConfiguration)
                {
                    PrimitiveConfiguration primitiveConfiguration = (PrimitiveConfiguration) childConfiguration;
                    stringList.add(primitiveConfiguration.getValue());
                }
            }
            primitiveDisplay.setValue(stringList);
        }
    }

    public Display getDisplay()
    {
        return primitiveDisplay;
    }

}

@@ -482,16 +482,140 @@
 uration;
+%0Aimport com.google.gwt.event.logical.shared.ValueChangeEvent;%0Aimport com.google.gwt.event.logical.shared.ValueChangeHandler;
 %0A%0Apublic
@@ -859,16 +859,50 @@
 splay;%0A%0A
+    private List%3CString%3E values;%0A%0A
     publ
@@ -1086,242 +1086,1008 @@
     
-%7D%0A%0A    public String getFieldName()%0A    %7B%0A        return fieldName;%0A    %7D%0A%0A    public ElementConfiguration getElementConfiguration(ObjectConfigurationFactory objectConfigurationFactory)%0A    %7B%0A        // TODO Auto-generated method stub
+    bind();%0A    %7D%0A%0A    private void bind()%0A    %7B%0A        primitiveDisplay.addValueChangeHandler(new ValueChangeHandler%3CList%3CString%3E%3E()%0A        %7B%0A            public void onValueChange(ValueChangeEvent%3CList%3CString%3E%3E event)%0A            %7B%0A                values = event.getValue();%0A            %7D%0A        %7D);%0A%0A    %7D%0A%0A    public String getFieldName()%0A    %7B%0A        return fieldName;%0A    %7D%0A%0A    public ElementConfiguration getElementConfiguration(ObjectConfigurationFactory objectConfigurationFactory)%0A    %7B%0A        if (values != null)%0A        %7B%0A            ListConfiguration listConfiguration = objectConfigurationFactory.createListConfiguration();%0A            listConfiguration.setListConfiguration(new ArrayList%3CElementConfiguration%3E());%0A            for (String value : values)%0A            %7B%0A                listConfiguration.getListConfiguration().add(%0A                        objectConfigurationFactory.createPrimitiveConfiguration(value));%0A            %7D%0A            return listConfiguration;%0A        %7D
 %0A   
@@ -2902,16 +2902,54 @@
 gList);%0A
+            this.values = stringList;%0A
         

Implement StringList get/set !