package com.sometrik.framework;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ListView;
import android.widget.TextView;

public class FWList extends ListView implements NativeCommandHandler{

  private FrameWork frame;
  private FWAdapter adapter;
  
  public FWList(FrameWork frame, FWAdapter adapter) {
    super(frame);
    this.frame = frame;
    this.adapter = adapter;
    setAdapter(adapter);
  }
  
  public void addData(int row, int column, String text){
    Log.d("FWList", "adding data for row " + row + " column " + column);
    ArrayList<String> dataRow = adapter.getDataRow(row);
    if (dataRow != null){
      Log.d("FWList", "row found adding data");
      dataRow.add(column, text);
    } else {
      Log.d("FWList", "creating new row");
      dataRow = new ArrayList<String>();
      dataRow.add(text);
      adapter.addItem(row, dataRow);
    }
  }

  @Override
  public void onScreenOrientationChange(boolean isLandscape) {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void addChild(View view) {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void addOption(int optionId, String text) {
    if (optionId == 0){
      adapter.addColumn(text);
    } else {
      Log.d("FWList", "adding header to row " + optionId);
      adapter.addSectionHeader(optionId, text);
    }
  }

  @Override
  public void setValue(String v) {
  }

  @Override
  public void setValue(int v) {
    if (v == 0){
      adapter.clear();
    }
  }

  @Override
  public void setViewEnabled(Boolean enabled) {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void setStyle(String key, String value) {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void setError(boolean hasError, String errorText) {
    // TODO Auto-generated method stub
    
  }

  @Override
  public int getElementId() {
    return getId();
  }

  @Override
  public void setViewVisibility(boolean visibility) {
    if (visibility){
      this.setVisibility(VISIBLE);
    } else {
      this.setVisibility(INVISIBLE);
    }
  }
}

@@ -134,24 +134,59 @@
 .view.View;%0A
+import android.widget.AdapterView;%0A
 import andro
@@ -207,32 +207,32 @@
 ndableListView;%0A
-
 import android.w
@@ -426,16 +426,22 @@
  FWList(
+final 
 FrameWor
@@ -540,16 +540,16 @@
 dapter;%0A
-
     setA
@@ -565,16 +565,344 @@
 apter);%0A
+    setOnItemClickListener(new OnItemClickListener()%7B%0A%0A      @Override%0A      public void onItemClick(AdapterView%3C?%3E parent, View view, int position, long rowId) %7B%0A%09System.out.println(%22itemClick detected %22 + position);%0A%09frame.intChangedEvent(System.currentTimeMillis() / 1000.0, getElementId(), position);%0A      %7D%0A      %0A    %7D);%0A
   %7D%0A  %0A 

Add onItemClickListener