package baseclass;

import p2.p2server.P2Server;
import p2.pao.PaoField;
import p2.pao.PaoFieldObjectBind;
import p2.pao.PaoSetRemote;
import p2.util.P2Exception;

public class PaoFieldObjectBindCust extends PaoFieldObjectBind {

	public PaoFieldObjectBindCust(PaoField arg0) {
		super(arg0);
		String DataBindId = "";
		try {
			PaoSetRemote ps_objectcols = P2Server.getP2Server().getPaoSet("ps_objectcols",
					P2Server.getP2Server().getSystemUserInfo());
			ps_objectcols
					.setWhere("objectname ='" + arg0.getPao().getName() + "' and fieldname='" + arg0.getName() + "'");
			ps_objectcols.reset();
			if (!ps_objectcols.isEmpty()) {
				DataBindId = ps_objectcols.getPao(0).getString("databindid");
			}
			ps_objectcols.close();
		} catch (P2Exception e) {
			e.printStackTrace();
		}
		setDataBindId(DataBindId);
	}

	@Override
	public void action() throws P2Exception {
		super.action();
		/*PaoSetRemote list = getList();
		list.setQbe(getMatchingAttr(), "=" + getPaoField().getString());
		list.reset();
		if (!list.isEmpty()) {
			setValueFromLookup(list.getPao(0));
		}*/
		if (getPaoField().getPao() instanceof PaoCust) {
			PaoCust cust = (PaoCust) getPaoField().getPao();
			cust.fieldAction(this, getPaoField().getName());
		}
	}

	@Override
	public void validate() throws P2Exception {
		super.validate();
		if (getPaoField().getPao() instanceof PaoCust) {
			PaoCust cust = (PaoCust) getPaoField().getPao();
			cust.fieldValidate(this, getPaoField().getName());
		}
	}

	@Override
	public PaoSetRemote getList() throws P2Exception {
		if (getPaoField().getPao() instanceof PaoCust) {
			PaoCust cust = (PaoCust) getPaoField().getPao();
			return cust.fieldGetlist(this, super.getList(), getPaoField().getName());
		}
		return super.getList();
	}

	@Override
	public void initValue() throws P2Exception {
		super.initValue();
		if (getPaoField().getPao() instanceof PaoCust) {
			PaoCust cust = (PaoCust) getPaoField().getPao();
			cust.fieldInitValue(this, getPaoField().getName());
		}
	}

}
