package com.agile.test;
/**
* Created by IntelliJ IDEA.
* User:
* Date: Aug 19, 2008
* Time: 12:45:44 PM
* To change this template use File | Settings | File Templates.
*/
import com.agile.px.*;
import com.agile.api.*;
import java.util.List;
public class HWPX implements ICustomAction{
public ActionResult doAction(IAgileSession agileSession,
INode node,
IDataObject affectedObject) {
try {
IItem part = null;
if(affectedObject!=null) {
part = (IItem)agileSession.getObject(IItem.OBJECT_TYPE,affectedObject.getObjectId());
}
int size = 0;
if(part!=null) {
size = countBom(part);
return new ActionResult(ActionResult.STRING, String.valueOf(size));
}
return new ActionResult(ActionResult.STRING, "hello world!!!");
} catch (APIException e) {
return new ActionResult(ActionResult.STRING, "Exception");
}
}
private int countBom(IItem part) throws APIException{
ITable bomTable = part.getTable(ItemConstants.TABLE_BOM);
int size = 1;
ITwoWayIterator iter = bomTable.getTableIterator();
while(iter.hasNext()) {
IRow subRow = (IRow)iter.next();
IItem subPart = (IItem)subRow.getReferent();
size = size + countBom(subPart);
}
return size;
}
}