package org.mwc.debrief.core.providers;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;

import Debrief.Wrappers.Extensions.ExtensionContentProvider;
import Debrief.Wrappers.Extensions.Measurements.CoreDataset;
import Debrief.Wrappers.Extensions.Measurements.DataFolder;
import Debrief.Wrappers.Extensions.Measurements.DataItem;
import MWC.GUI.Editable;
import MWC.GUI.HasChildData;

public class MeasuredDataProvider implements ExtensionContentProvider
{

  protected static class DatasetWrapper implements Editable
  {
    final private CoreDataset<?, ?> _data;

    public DatasetWrapper(final CoreDataset<?, ?> folder)
    {
      _data = folder;
    }

    @Override
    public EditorType getInfo()
    {
      return null;
    }

    @Override
    public String getName()
    {
      return _data.getName();
    }

    @Override
    public boolean hasEditor()
    {
      return false;
    }

    @Override
    public String toString()
    {
      return getName() + " (" + _data.size() + " items)";
    }
  }

  protected static class FolderWrapper implements Editable, HasChildData
  {
    final private DataFolder _folder;

    public FolderWrapper(final DataFolder folder)
    {
      _folder = folder;
    }

    @Override
    public Enumeration<Editable> elements()
    {
      final Vector<Editable> res = new Vector<Editable>();

      // get the folder contents
      final List<Editable> items = getItemsFor(_folder);

      // put into our vector
      res.addAll(items);

      return res.elements();
    }

    @Override
    public EditorType getInfo()
    {
      return null;
    }

    @Override
    public String getName()
    {
      return _folder.getName();
    }

    @Override
    public boolean hasEditor()
    {
      return false;
    }

    @Override
    public boolean hasOrderedChildren()
    {
      return false;
    }

    @Override
    public String toString()
    {
      return getName() + " (" + _folder.size() + " items)";
    }
  }

  private static List<Editable> getItemsFor(final Object subject)
  {
    List<Editable> res = null;

    if (subject instanceof DataFolder)
    {
      final DataFolder folder = (DataFolder) subject;

      // ok, go for it.
      for (final DataItem item : folder)
      {
        // produce an editable from this data item
        final Editable plottable;

        if (item instanceof DataFolder)
        {
          final DataFolder df = (DataFolder) item;
          plottable = new FolderWrapper(df);
        }
        else if (item instanceof CoreDataset<?, ?>)
        {
          final CoreDataset<?, ?> set = (CoreDataset<?, ?>) item;
          plottable = new DatasetWrapper(set);
        }
        else
        {
          System.err.println("unexpected data found in data folder");
          plottable = null;
        }

        if (res == null)
        {
          res = new ArrayList<Editable>();
        }
        res.add(plottable);
      }
    }

    return res;
  }

  @Override
  public List<Editable> itemsFor(final Object subject)
  {
    return getItemsFor(subject);
  }
}

@@ -34,16 +34,96 @@
 iders;%0A%0A
+import java.beans.IntrospectionException;%0Aimport java.beans.PropertyDescriptor;%0A
 import j
@@ -661,210 +661,1614 @@
     
-final private CoreDataset%3C?, ?%3E _data;%0A%0A    public DatasetWrapper(final CoreDataset%3C?, ?%3E folder)%0A    %7B%0A      _data = folder;%0A    %7D%0A%0A    @Override%0A    public EditorType getInfo()%0A    %7B%0A      return null
+%0A // ////////////////////////////////////////////////////%0A    // bean info for this class%0A    // ///////////////////////////////////////////////////%0A    public final class DatasetWrapperInfo extends Editable.EditorType%0A    %7B%0A%0A      public DatasetWrapperInfo(final DatasetWrapper data, final String theName)%0A      %7B%0A        super(data, theName, data.toString());%0A      %7D%0A%0A      @Override%0A      public final PropertyDescriptor%5B%5D getPropertyDescriptors()%0A      %7B%0A        try%0A        %7B%0A          final PropertyDescriptor%5B%5D myRes = %7B%0A              displayProp(%22ItemCount%22, %22Number of items%22, %22Number of items in this dataset%22, TEMPORAL),%0A              displayProp(%22Units%22, %22Units for data%22, %22Units for this dataset%22, TEMPORAL)%0A              %7D;%0A%0A          return myRes;%0A        %7D%0A        catch (final IntrospectionException e)%0A        %7B%0A          e.printStackTrace();%0A          return super.getPropertyDescriptors();%0A        %7D%0A      %7D%0A    %7D%0A    %0A    %0A    final private CoreDataset%3C?, ?%3E _data;%0A    private DatasetWrapperInfo _myEditor = null;%0A%0A    public DatasetWrapper(final CoreDataset%3C?, ?%3E folder)%0A    %7B%0A      _data = folder;%0A    %7D%0A    %0A    public String getItemCount()%0A    %7B%0A      return %22%22 + _data.size();%0A    %7D%0A    %0A    public void setItemCount(String val)%0A    %7B%0A      // ignore%0A    %7D%0A    %0A    public String getUnits()%0A    %7B%0A      return _data.getUnits();%0A    %7D%0A    %0A    public void setUnits(String val)%0A    %7B%0A      // ignore%0A    %7D%0A%0A%0A    @Override%0A    public EditorType getInfo()%0A    %7B%0A      if (_myEditor == null)%0A        _myEditor  = new DatasetWrapperInfo(this, this.getName());%0A%0A      return _myEditor
 ;%0A  
@@ -2413,36 +2413,35 @@
  %7B%0A      return 
-fals
+tru
 e;%0A    %7D%0A%0A    @O

Introduce some properties for dataset object