01: package simpleorm.simplewebapp.dbute;
02:
03: import simpleorm.core.*;
04: import simpleorm.simplewebapp.core.WTree;
05:
06: /**
07: * Builds a tree, with subgroups.
08: */
09: public class WGenericTree {
10: public void addSubTree(WTree tree, WTree.WTreeNode grandparent,
11: SRecordMeta meta, SFieldMeta group, SFieldMeta display,
12: SFieldMeta id, String url) {
13:
14: tree.addNode(grandparent, "<i>New User</i>", url);
15: SResultSet res = meta.newQuery().rawOrderBy(
16: "\"" + group.getProperty(SCon.SCOLUMN_NAME) + "\"")
17: .execute(); // .ascending(group) has simpleORM bug
18: String prevGrouper = null;
19: WTree.WTreeNode parent = null;
20: while (res.hasNext(1000)) {
21: SRecordInstance rec = res.getRecord();
22: String grouper = rec.getString(group);
23: if (!grouper.equals(prevGrouper)) {
24: parent = tree.addNode(grandparent, grouper, url);
25: prevGrouper = grouper;
26: }
27: tree.addNode(parent, rec.getString(display), url
28: + "?userId=" + rec.getInt(id));
29: }
30:
31: }
32: }
|