// generated by FBuilder
package flexa.ff;
import flexa.fb.*;
import java.util.Map;
import java.util.HashMap;
import javax.script.*;
import java.util.ArrayList;
public class subformrow extends FComponent {
    //
    // CONSTRUCTOR
    //
    public subformrow() {
        super("ff.subformrow");
    }
    
    // 
    // Methods
    //
    
    
    public Map<String, String> calcExpressions(FContext aContext, boolean executeRenderEvents)  throws Exception { 
    		FCollection tcol = (FCollection)this.getContainer().fobject;
		String tindex = this.id.substring(this.id.indexOf("[") + 1, this.id.indexOf("]"));
		Log.info("[calcexpressions] Setting position " + tindex + " on subform " + this.getContainer().getId());
		tcol.setPosition(Integer.parseInt(tindex));
		Map<String, String> tret = super.calcExpressions(aContext, executeRenderEvents);
		tcol.setPosition(0);
		return tret;

    }
    


    
    public void setFObject(FObject aobject)  throws Exception { 
    		this.fobject = aobject;
		super.setFObject(aobject);

    }
    


    
    public String validate(FContext aContext)  throws Exception { 
    		StringBuffer sb = new StringBuffer();
		boolean tisvalid = true;
		// Si el componentne tiene ROWVALID evalua
		if( this.getValue("rowvalid") != null ) {
			Object calcvalid = this.calcExpression(aContext, "rowvalid");
			Log.info("Calcvalid " + this.getId(), calcvalid);
			if( !LibPrim.to_bool(calcvalid) ) {
				tisvalid = false;
				String tmessage = this.getValue("rowinvalidmessage") != null ? (String)this.getValue("rowinvalidmessage") : ("Valor invalido en " + this.getTitle());
				Log.info(tmessage);
				if( sb.length() > 0 ) sb.append("\n");
				sb.append(tmessage);
			}
		}
		for (FComponent element : this.getChildren()) {
			String tmessage2 = element.validate(aContext);
			if( !tmessage2.trim().equals("") ) {
				if( sb.length() > 0 ) sb.append("\n");
				sb.append(tmessage2);
			}
			
		}		
		return sb.toString();

    }
    


    
    public boolean isvalid(FContext aContext)  throws Exception { 
    		boolean tisvalid = true;
		if( this.getValue("rowvalid") != null ) {
			Object calcvalid = this.calcExpression(aContext, "rowvalid");
			if( !LibPrim.to_bool(calcvalid) )
				tisvalid = false;
		}
		// Solo valida subformrows
		for (FComponent element : this.getChildren()) {
			if( !element.isValid(aContext) ) {
				tisvalid = false;
			}
		}		
		return tisvalid;

    }
    


    // 
    // Events
    //
	public void event(String aAction, FContext aContext) throws Exception {
        // Events
        
    
        // delete EVENT
        if( LibText.stringToArray("" + this.name + ".delete").contains(aAction) ) {
        			// Remove myself
			if( this.fobject != null ) {
			    ((FCollection)(((subform)this.container).fobject)).remove(this.fobject);
			}
			this.removeMyself();

        }
    


	    super.event(aAction, aContext);
	}
	
	
}