use of db.OneToMany in project common by zenlunatics.
the class Admin method _newViewDef.
// --------------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
if (name.startsWith("admin__")) {
String table = name.substring(7);
ViewDef view_def = new ViewDef(name, table, null) {
@Override
public View newView(Request request) {
if (!request.getUser().isAdministrator())
return null;
return super.newView(request);
}
};
view_def.setAllowQuickEdit(true);
view_def.setRecordName(table);
view_def.setShowTableColumnPicker(true, null);
DBConnection db = new DBConnection(site);
JDBCTable jdbc_table = db.getTable(table);
if (jdbc_table.getColumn("_order_") != null)
view_def.setReorderable(new Reorderable());
for (String column_name : jdbc_table.getColumnNamesAll()) if (column_name.equals("_owner_"))
view_def.setColumn(new LookupColumn(column_name, "people", "first,last").setAllowNoSelection(true).setShowFormLink(true));
else if (column_name.endsWith("_id") && jdbc_table.getColumn(column_name).getType() == Types.INTEGER) {
String one_table = column_name.substring(0, column_name.length() - 3);
if (one_table.equals("people"))
view_def.setColumn(new LookupColumn(column_name, one_table, "first,last").setAllowNoSelection(true).setShowFormLink(true));
else if (db.getTable(one_table) != null) {
String[] column_names = db.getTable(one_table).getColumnNames();
if (column_names.length > 0)
view_def.setColumn(new LookupColumn(column_name, one_table, column_names[0]).setAllowNoSelection(true).setShowFormLink(true));
}
}
for (String[] foreign_key : db.getForeignKeys(table)) if (foreign_key[1].equals(table + "_id"))
view_def.addRelationshipDef(new OneToMany(foreign_key[0]));
db.close();
return view_def;
}
return null;
}
Aggregations