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