01: package org.osbl.orga.gui;
02:
03: import org.osbl.orga.logic.OrgaStructureLogic;
04: import org.osbl.orga.model.Group;
05: import org.osbl.orga.model.Organisation;
06: import org.osbl.client.wings.form.GenericObjectTreeNode;
07: import org.osbl.client.wings.form.ObjectContext;
08: import org.osbl.persistence.*;
09: import org.hibernate.Hibernate;
10: import org.hibernate.FetchMode;
11:
12: import java.util.*;
13:
14: /**
15: * @author hengels
16: * @version $Revision$
17: */
18: public class OrganisationTreeNode extends
19: GenericObjectTreeNode<Organisation> {
20: public OrganisationTreeNode() {
21: }
22:
23: public OrganisationTreeNode(Organisation organisation) {
24: this .object = organisation;
25: }
26:
27: public OrganisationsTreeNode getParent() {
28: return (OrganisationsTreeNode) parent;
29: }
30:
31: protected void loadChildren() {
32: OrgaTreeModel model = (OrgaTreeModel) getModel();
33: OrgaStructureLogic logic = model.getTreeLogic();
34: List<Group> groups = logic.roots(object.getId());
35: children = new ArrayList<GenericObjectTreeNode>(groups.size());
36: for (Iterator<Group> iterator = groups.iterator(); iterator
37: .hasNext();) {
38: Group group = iterator.next();
39: GroupTreeNode child = new GroupTreeNode(group);
40: children.add(child);
41: child.setParent(this );
42: }
43: sortChildren();
44: }
45:
46: public boolean getAllowsChildren() {
47: return true;
48: }
49:
50: public boolean isLeaf() {
51: return false;
52: }
53:
54: public Class getObjectType() {
55: return Organisation.class;
56: }
57:
58: public Class[] getChildTypes() {
59: return new Class[] { Group.class };
60: }
61:
62: protected void installContext(ObjectContext context) {
63: context.putObject("organisation", loadObject());
64: }
65:
66: public Organisation loadObject() {
67: Organisation object = getObject();
68: if (object == null)
69: return null;
70:
71: SimpleQueryCommand queryCommand = (SimpleQueryCommand) ((OrgaTreeModel) getModel())
72: .getPersistence().createCommand("list");
73: queryCommand.setType(Organisation.class);
74: queryCommand.addFilter("id", Operator.EQUAL, object.getId());
75: queryCommand.addFetch("roles", Fetch.JOIN);
76: queryCommand.addFetch("relations", Fetch.JOIN);
77: List<Organisation> list = queryCommand.execute();
78: return list.get(0);
79:
80: /*
81: LoadCommand loadCommand = (LoadCommand)((OrgaTreeModel)getModel()).getPersistence().createCommand("load");
82: loadCommand.setType(Organisation.class);
83: loadCommand.setId(object.getId());
84: object = (Organisation)loadCommand.execute();
85: Hibernate.initialize(object.getRoles());
86: Hibernate.initialize(object.getRelations());
87: Hibernate.initialize(object.getMembers());
88: return object;
89: */
90: }
91: }
|