01: package org.osbl.riskmanagement.gui;
02:
03: import org.osbl.client.wings.form.GenericObjectTreeNode;
04: import org.osbl.client.wings.form.ObjectContext;
05: import org.osbl.riskmanagement.logic.RiskManagementLogic;
06: import org.osbl.riskmanagement.model.Classification;
07: import org.osbl.riskmanagement.model.RiskType;
08: import org.osbl.persistence.LoadCommand;
09:
10: import java.util.*;
11:
12: /**
13: * @author hengels
14: * @version $Revision$
15: */
16: public class ClassificationTreeNode extends
17: GenericObjectTreeNode<Classification> {
18: public ClassificationTreeNode() {
19: }
20:
21: public ClassificationTreeNode(Classification object) {
22: setObject(object);
23: }
24:
25: public ClassificationsTreeNode getParent() {
26: return (ClassificationsTreeNode) parent;
27: }
28:
29: protected void loadChildren() {
30: RiskTypeTreeModel model = (RiskTypeTreeModel) getModel();
31: RiskManagementLogic logic = model.getTreeLogic();
32: List<RiskType> groups = logic.roots(object.getId());
33: children = new ArrayList<GenericObjectTreeNode>(groups.size());
34: for (Iterator<RiskType> iterator = groups.iterator(); iterator
35: .hasNext();) {
36: RiskType riskType = iterator.next();
37: RiskTypeTreeNode child = new RiskTypeTreeNode(riskType);
38: children.add(child);
39: child.setParent(this );
40: }
41: sortChildren();
42: }
43:
44: public boolean getAllowsChildren() {
45: return true;
46: }
47:
48: public boolean isLeaf() {
49: return false;
50: }
51:
52: public Class getObjectType() {
53: return Classification.class;
54: }
55:
56: public Class[] getChildTypes() {
57: return new Class[] { RiskType.class };
58: }
59:
60: protected void installContext(ObjectContext context) {
61: context.putObject("classification", loadObject());
62: }
63:
64: public Classification loadObject() {
65: Classification object = getObject();
66: if (object == null)
67: return null;
68:
69: LoadCommand loadCommand = (LoadCommand) ((RiskTypeTreeModel) getModel())
70: .getPersistence().createCommand("load");
71: loadCommand.setType(Classification.class);
72: loadCommand.setId(object.getId());
73: object = (Classification) loadCommand.execute();
74: return object;
75: }
76: }
|