01: package org.osbl.orga.gui;
02:
03: import org.osbl.orga.model.*;
04: import org.osbl.client.wings.form.GenericObjectTreeNode;
05: import org.osbl.persistence.LoadCommand;
06: import org.hibernate.Hibernate;
07:
08: import java.util.*;
09:
10: /**
11: * @author hengels
12: * @version $Revision$
13: */
14: public class MembershipTreeNode extends
15: GenericObjectTreeNode<Membership> {
16: public MembershipTreeNode() {
17: }
18:
19: public MembershipTreeNode(Membership membership) {
20: this .object = membership;
21: }
22:
23: public GroupTreeNode getParent() {
24: return (GroupTreeNode) parent;
25: }
26:
27: protected void loadChildren() {
28: children = Collections.emptyList();
29: }
30:
31: public void connect() {
32: Membership membership = getObject();
33: Group group = (Group) parent.getObject();
34: List<Membership> memberships = group.getMemberships();
35: if (membership.getGroup() == null) {
36: if (memberships == null)
37: group.setMemberships(new ArrayList<Membership>());
38: memberships.add(membership);
39: membership.setGroup(group);
40: } else {
41: Long id = membership.getId();
42: for (Iterator<Membership> iterator = memberships.iterator(); iterator
43: .hasNext();) {
44: Membership child = iterator.next();
45: if (child.getId().equals(id)) {
46: int index = memberships.indexOf(child);
47: memberships.set(index, membership);
48: break;
49: }
50: }
51: }
52: }
53:
54: public boolean getAllowsChildren() {
55: return false;
56: }
57:
58: public boolean isLeaf() {
59: return true;
60: }
61:
62: public Class getObjectType() {
63: return Membership.class;
64: }
65:
66: public Class[] getChildTypes() {
67: return new Class[0];
68: }
69:
70: public Membership loadObject() {
71: Membership object = getObject();
72: LoadCommand loadCommand = (LoadCommand) ((OrgaTreeModel) getModel())
73: .getPersistence().createCommand("load");
74: loadCommand.setType(Membership.class);
75: loadCommand.setId(object.getId());
76: object = (Membership) loadCommand.execute();
77: Hibernate.initialize(object.getMember());
78: Hibernate.initialize(object.getGroup());
79: return object;
80: }
81: }
|