package flexa.ff;

import flexa.fb.*;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;


public class td extends FComponent {
    
    OQL datasourceOql = null;
    
    public td() {
        super("ff.td");
    }

	public void updateFromRequest(HashMap<String, Object> aParameters) {
	    //if( aParameters.containsKey(this.getValue("name")) )
        //    this.setValue("value", aParameters.get(this.getValue("name")).toString());
	}  

    /**	
	public void event(String aAction, FContext aContext) throws Exception {
	    //Log.getInstance().info("td " + this.name + " event " + aAction);
	    if( this.status == 0 
	        && (hasValue("datasource_oql") || hasValue("datasource_sql"))
	        && (aAction.equals(this.name + ".select") || aAction.equals(this.name + ".refresh") || aAction.equals("start") || aAction.equals("onopen")) 
	        ) {
	        
	        // EXECUTES SQL/OQL
	        Log.getInstance().info("td event " + aAction + " datasource : " + (String)getValue("datasource") );
	        String dsOql = (String)getValue("datasource_oql");
	        String dsSql = (String)getValue("datasource_sql");
	        // @todo list and expression
	        FResult result = null;
	        if( dsOql != null && !dsOql.trim().equals("") ) {
	            if( this.datasourceOql == null ) {  // @todo OQL array with UNION ALL
	                this.datasourceOql = OQL.parseOql(dsOql);
	            }
	            Log.getInstance().info("td executing OQL " + this.datasourceOql);
	            result = ORM.getInstance().oqltoarrayddtotal(aContext, this.datasourceOql);
	        }
	        if( dsSql != null && !dsSql.trim().equals("") ) {
	            Log.getInstance().info("td executing SQL " + dsSql);
	            result = Util.sqltoarrayddtotal(aContext, dsSql);
	        }
	        
            // CLONE TR BODY
            int totalrows = result.size();
            FComponent tbody = this.findChildOfType("td", "type", "body");
            
            //@todo buscar one row for body 
            //if( tbody == null ) 
            
            if( tbody == null ) throw new Exception("No td body found on tr " + (String)getValue("name"));   // @todo armar filas con FResult
            int tposition = this.getChildren().indexOf(tbody);
            FComponent torender = tbody;
            String tid = (String)torender.getValue("id");
            // Por cada registro clona elemento
            for(int i = 0; i < totalrows; i++) {
                FRow row = result.get(i);
                Log.getInstance().info("TR body ds row " + i);
                if( i > 0 ) {
                    // Clone and add to father
                    //torender = (FComponent)PipedDeepCopy.copy(this);
                    torender = (FComponent)tbody.clone();
                    //torender = new FComponent(this);
                    torender.setValue("id", tid + "[" + i + "]");
                    this.addChild(torender, tposition + i );
                }
                Log.info("Row moredata:");
                Log.info(row.toString());
                //Log.info(((FObject)row.get("x")).info());
                //torender.moreData = row;
                torender.context = new FContext(row);
                //Log.getInstance().info("Torender " + torender.getValue("id"));
            }
            //Log.getInstance().info("tr EVENT end: " + torender.info());
            // @todo eliminar clonados demas de anteriores clonaciones
            // @todo si no hay registros limpiar elemento y ponerlo como inactivo (status -1)
	    }
	    super.event(aAction, aContext);
	}
	**/
	
}
