Evaluator is used to determine if a field (or tab) should be displayed or hidden.
I'm using it to see if, in the context of my record, a field has to be filled.
Here's my code to get a list of mandatory column, according to a specific record :
- Code: Select all
static MColumn[] columnsMandatory(Properties ctx, PO po, int tableID, int recordID, String trxName)
{
ArrayList<MColumn> listColumns = new ArrayList<MColumn>();
MDevice device = new MDevice(ctx, recordID, trxName);
int windowID = 1000002; // TODO hardcoded
// List of tabs based on po
String sql = "SELECT t.AD_Tab_ID"
+ " FROM AD_Tab t"
+ " WHERE t.IsActive='Y' AND t.AD_Window_ID=" + windowID
+ " AND t.AD_Table_ID=" + po.get_Table_ID()
+ " ORDER BY t.SeqNo";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement (sql, trxName);
rs = pstmt.executeQuery ();
while (rs.next ())
{
int tabID = rs.getInt(1);
MTab tab = new MTab(ctx, tabID, trxName);
boolean needToCheckTab=false;
if (tab.getDisplayLogic()==null)
needToCheckTab=true;
else
{
if (Evaluator.evaluateLogic(device, tab.getDisplayLogic()))
needToCheckTab=true;
}
if (needToCheckTab)
{
String sql2 = "SELECT f.AD_Field_ID"
+ " FROM AD_Field f"
+ " INNER JOIN AD_Tab t ON (f.AD_Tab_ID = t.AD_Tab_ID)"
+ " WHERE f.IsDisplayed='Y' AND f.AD_Tab_ID="+tabID
+ " ORDER BY t.SeqNo, f.IsDisplayed DESC, f.SeqNo";
PreparedStatement pstmt2 = null;
ResultSet rs2 = null;
pstmt2 = DB.prepareStatement (sql2, trxName);
rs2 = pstmt2.executeQuery ();
while (rs2.next ())
{
int fieldID = rs2.getInt(1);
MField field = new MField(ctx, fieldID, trxName);
MColumn column = new MColumn(ctx, field.getAD_Column_ID(), trxName);
if (column.getAD_Column_ID() == 1000557 || column.getAD_Column_ID()==1000559)
continue;
System.out.println("=> " + column);
boolean checkValue = false;
if (field.getIsMandatory() != null && field.getIsMandatory().equals(X_AD_Field.ISMANDATORY_Yes) && field.getDisplayLogic()==null)
checkValue=true;
else if (field.getDisplayLogic()!=null && Evaluator.evaluateLogic(po, field.getDisplayLogic()))
checkValue=true;
else // mandatory in base or have a mandatorylogic
{
if (column.isMandatory())
checkValue=true;
if (column.getMandatoryLogic() != null && Evaluator.evaluateLogic(po, column.getMandatoryLogic()))
checkValue=true;
}
if (checkValue)
{
listColumns.add (column);
System.out.println(" - " + column.getColumnName());
}
}
}
}
}
catch (Exception e)
{
s_log.log(Level.SEVERE, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
MColumn[] columns = new MColumn[listColumns.size ()];
listColumns.toArray (columns);
return columns;
Then, i can check if those columns are empty or not.