package org.opengroupware.jope.samples.HelloWorld;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.opengroupware.jope.appserver.core.WOComponent;
import org.opengroupware.jope.appserver.core.WOContext;
import org.opengroupware.jope.appserver.core.WODisplayGroup;
import org.opengroupware.jope.eocontrol.EOArrayDataSource;
import org.opengroupware.jope.foundation.NSPropertyListParser;

@SuppressWarnings("unchecked")
public class TableView extends WOComponent {

  static List<Object> data;
  
  static {
    NSPropertyListParser parser = new NSPropertyListParser();
    data = (List<Object>)
      parser.parse(Main.class.getResource("Data.plist"));
    if (data == null)
      System.err.println(parser.lastException());    
  }
  
  /* ivars */
  
  public WODisplayGroup      dg;
  public Map<String, Object> item;
  public int                 index;
  
  /* setup */
  
  @Override
  public WOComponent initWithContext(WOContext _ctx) {
    super.initWithContext(_ctx);
    
    this.dg = new WODisplayGroup();
    this.dg.setDataSource(new EOArrayDataSource(data));
    this.dg.setFetchesOnLoad(true);
    this.dg.setNumberOfObjectsPerBatch(3);
    
    return this;
  }
  
  /* accessors */
  
  public List data() {
    return data;
  }
  
  public Date now() {
    return new Date();
  }
}
