package com.sometrik.framework;

import java.util.ArrayList;

import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ListView;

public class FWList extends ExpandableListView implements NativeCommandHandler{

  private FrameWork frame;
  private FWAdapter adapter;
  
  public FWList(final FrameWork frame, FWAdapter adapter) {
    super(frame);
    this.frame = frame;
    this.adapter = adapter;
    this.setAdapter((ExpandableListAdapter)adapter);
    setOnItemClickListener(new OnItemClickListener(){

      @Override
      public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
	System.out.println("itemClick detected " + position);
	frame.intChangedEvent(System.currentTimeMillis() / 1000.0, getElementId(), position);
      }
      
    });
  }
  
  @Override
  public void addData(String text, int row, int column, int sheet){
    Log.d("FWList", "adding data for row " + row + " column " + column + " sheet " + sheet);
    ArrayList<String> dataRow = adapter.getDataRow(row, sheet);
    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, sheet, 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);
    }
  }
}

@@ -593,20 +593,21 @@
    setOn
-Item
+Group
 ClickLis
@@ -618,20 +618,21 @@
 r(new On
-Item
+Group
 ClickLis
@@ -640,16 +640,22 @@
 ener()%7B%0A
+      
 %0A      @
@@ -680,39 +680,47 @@
 lic 
-void onItemClick(Adapter
+boolean onGroupClick(ExpandableList
 View
-%3C?%3E
  par
@@ -734,18 +734,20 @@
 ew v
-iew
 , int 
-p
+groupP
 osit
@@ -760,12 +760,9 @@
 ong 
-rowI
+i
 d) %7B
@@ -806,17 +806,22 @@
 ted %22 + 
-p
+groupP
 osition)
@@ -823,16 +823,201 @@
 tion);%0A%09
+if (groupPosition == 0) %7B%0A%09  System.out.println(%22column title clicked. ignoring%22);%0A%09%7D else %7B%0A%09  System.out.println(%22row clicked. Sending intChangedEvent of %22 + (groupPosition - 1));%0A%09  
 frame.in
@@ -1087,17 +1087,44 @@
 (), 
-p
+groupP
 osition
-)
+ - 1);%0A%09%7D%0A%09return false
 ;%0A  
@@ -1129,22 +1129,16 @@
       %7D%0A
-      
 %0A    %7D);
@@ -1142,18 +1142,16 @@
 %7D);%0A  %7D%0A
-  
 %0A  @Over

Change itemClickListener to GroupListener