Search in sources :

Example 1 with TableColumn

use of pcgen.cdom.format.table.TableColumn in project pcgen by PCGen.

the class LookupFunction method evaluate.

@Override
public Object evaluate(EvaluateVisitor visitor, Node[] args, EvaluationManager manager) {
    //Table name node (must be a Table)
    DataTable dataTable = (DataTable) args[0].jjtAccept(visitor, manager.getWith(EvaluationManager.ASSERTED, DATATABLE_CLASS));
    FormatManager<?> lookupFormat = dataTable.getFormat(0);
    //Lookup value (format based on the table)
    @SuppressWarnings("PMD.PrematureDeclaration") Object lookupValue = args[1].jjtAccept(visitor, manager.getWith(EvaluationManager.ASSERTED, lookupFormat.getManagedClass()));
    //Result Column Name (must be a tableColumn)
    TableColumn column = (TableColumn) args[2].jjtAccept(visitor, manager.getWith(EvaluationManager.ASSERTED, COLUMN_CLASS));
    String columnName = column.getName();
    if (!dataTable.isColumn(columnName)) {
        FormatManager<?> fmt = column.getFormatManager();
        System.out.println("Lookup called on invalid column: '" + columnName + "' is not present on table '" + dataTable.getName() + "' assuming default for " + fmt.getIdentifierType());
        FormulaManager fm = manager.get(EvaluationManager.FMANAGER);
        return fm.getDefault(fmt.getManagedClass());
    }
    if (!dataTable.hasRow(lookupValue)) {
        FormatManager<?> fmt = column.getFormatManager();
        System.out.println("Lookup called on invalid item: '" + lookupValue + "' is not present in the first row of table '" + dataTable.getName() + "' assuming default for " + fmt.getIdentifierType());
        FormulaManager fm = manager.get(EvaluationManager.FMANAGER);
        return fm.getDefault(fmt.getManagedClass());
    }
    return dataTable.lookupExact(lookupValue, columnName);
}
Also used : DataTable(pcgen.cdom.format.table.DataTable) FormulaManager(pcgen.base.formula.base.FormulaManager) TableColumn(pcgen.cdom.format.table.TableColumn)

Example 2 with TableColumn

use of pcgen.cdom.format.table.TableColumn in project pcgen by PCGen.

the class LookupFunctionTest method doTableSetup.

public DataTable doTableSetup() {
    DataTable dt = new DataTable();
    dt.setName("A");
    TableColumn c1 = new TableColumn();
    c1.setName("Name");
    c1.setFormatManager(stringManager);
    TableColumn c2 = new TableColumn();
    c2.setName("Value");
    c2.setFormatManager(numberManager);
    dt.addColumn(c1);
    dt.addColumn(c2);
    List<Object> row = new ArrayList<>();
    row.add("This");
    row.add(1);
    dt.addRow(row);
    row.clear();
    row.add("That");
    row.add(2);
    dt.addRow(row);
    row.clear();
    row.add("The \"Other\"");
    row.add(3);
    dt.addRow(row);
    row.clear();
    return dt;
}
Also used : DataTable(pcgen.cdom.format.table.DataTable) ArrayList(java.util.ArrayList) TableColumn(pcgen.cdom.format.table.TableColumn)

Example 3 with TableColumn

use of pcgen.cdom.format.table.TableColumn in project pcgen by PCGen.

the class LookupFunctionTest method buildColumn.

private Object buildColumn(String string, FormatManager<?> manager) {
    TableColumn tc = new TableColumn();
    tc.setName(string);
    tc.setFormatManager(manager);
    return tc;
}
Also used : TableColumn(pcgen.cdom.format.table.TableColumn)

Aggregations

TableColumn (pcgen.cdom.format.table.TableColumn)3 DataTable (pcgen.cdom.format.table.DataTable)2 ArrayList (java.util.ArrayList)1 FormulaManager (pcgen.base.formula.base.FormulaManager)1