01: package org.osbl.orga.gui;
02:
03: import org.osbl.orga.model.*;
04: import org.osbl.orga.logic.OrgaStructureLogic;
05: import org.osbl.client.wings.form.GenericObjectTreeNode;
06: import org.osbl.persistence.LoadCommand;
07:
08: import java.util.*;
09:
10: /**
11: * @author hengels
12: * @version $Revision$
13: */
14: public class GroupTreeNode extends GenericObjectTreeNode<Group> {
15: public GroupTreeNode() {
16: }
17:
18: public GroupTreeNode(Group group) {
19: this .object = group;
20: }
21:
22: protected void loadChildren() {
23: object = loadObject();
24: if (object == null || object.getId() == null) {
25: children = new ArrayList<GenericObjectTreeNode>();
26: return;
27: }
28:
29: OrgaTreeModel model = (OrgaTreeModel) getModel();
30: OrgaStructureLogic logic = model.getTreeLogic();
31: List<Group> groups = logic.children(getOrganisation(), object
32: .getId());
33:
34: List<Membership> list = object.getMemberships();
35: if (list == null)
36: list = Collections.EMPTY_LIST;
37: children = new ArrayList<GenericObjectTreeNode>(list.size()
38: + groups.size());
39: for (Group childGroup : groups) {
40: GroupTreeNode child = new GroupTreeNode(childGroup);
41: children.add(child);
42: child.setParent(this );
43: }
44:
45: for (Membership membership : list) {
46: if (membership == null)
47: continue;
48: MembershipTreeNode child = new MembershipTreeNode(
49: membership);
50: children.add(child);
51: child.setParent(this );
52: }
53: sortChildren();
54: }
55:
56: Long getOrganisation() {
57: GenericObjectTreeNode node = this ;
58: while ((node = node.getParent()) != null)
59: if (node instanceof OrganisationTreeNode) {
60: OrganisationTreeNode organisationTreeNode = (OrganisationTreeNode) node;
61: return (organisationTreeNode.getObject()).getId();
62: }
63: return null;
64: }
65:
66: public boolean getAllowsChildren() {
67: return true;
68: }
69:
70: public boolean isLeaf() {
71: return false;
72: }
73:
74: public Class getObjectType() {
75: return Group.class;
76: }
77:
78: public Class[] getChildTypes() {
79: return new Class[] { Group.class, Membership.class };
80: }
81:
82: public Group loadObject() {
83: Group object = getObject();
84: LoadCommand loadCommand = (LoadCommand) ((OrgaTreeModel) getModel())
85: .getPersistence().createCommand("load");
86: loadCommand.setType(Group.class);
87: loadCommand.setId(object.getId());
88: object = (Group) loadCommand.execute();
89: return object;
90: }
91: }
|