package com.sometrik.framework;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewParent;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class FWTable extends TableLayout implements NativeCommandHandler {
  
  FrameWork frame;
  int columnCount = 4;
  ArrayList<TableRow> rowList;
  ArrayList<View> dataList;
  
  public FWTable(FrameWork frameWork) {
    super(frameWork);
    frame = frameWork;
    rowList = new ArrayList<TableRow>();
    rowList.add(new TableRow(frame));
    dataList = new ArrayList<View>();
  }
  
  private TableRow getCurrentRow(){
    if (dataList.size() / columnCount > rowList.size()) {
      TableRow row = new TableRow(frame);
      rowList.add(row);
      addView(row);
      return row;
    } else {
      return rowList.get(rowList.size() - 1);
    }
  }
  
  public void setColumnCount(int columnCount) { this.columnCount = columnCount; };


  @Override
  public void addChild(View view) {
    TableRow row = getCurrentRow();
    row.addView(view);
    dataList.add(view);
  }
  
  @Override
  public void addOption(int optionId, String text) {
    System.out.println("FWTable couldn't handle command");
  }

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

  @Override
  public void setValue(String v) {
    System.out.println("FWTable couldn't handle command");
  }

  @Override
  public void setValue(int v) {
    System.out.println("FWTable couldn't handle command");
  }

  @Override
  public void setViewEnabled(Boolean enabled) {
    System.out.println("FWTable couldn't handle command");
  }

  @Override
  public void setStyle(String key, String value) { }

  @Override
  public void setError(boolean hasError, String errorText) { }
}

@@ -87,16 +87,41 @@
 ontext;%0A
+import android.util.Log;%0A
 import a
@@ -586,39 +586,96 @@
     
-rowList.add(new TableRow(frame)
+TableRow firstRow = new TableRow(frame);%0A    rowList.add(firstRow);%0A    addView(firstRow
 );%0A 
@@ -761,16 +761,17 @@
 %0A    if 
+(
 (dataLis
@@ -778,16 +778,21 @@
 t.size()
+ + 1)
  / colum
@@ -814,24 +814,57 @@
 t.size()) %7B%0A
+      Log.d(%22table%22, %22New Row%22);%0A
       TableR
@@ -1156,24 +1156,48 @@
 iew view) %7B%0A
+    dataList.add(view);%0A
     TableRow
@@ -1247,32 +1247,8 @@
 w);%0A
-    dataList.add(view);%0A
   %7D%0A

Fix TableLayout missing rows