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.persistence.LoadCommand;
07:
08: import java.util.ArrayList;
09: import java.util.List;
10:
11: /**
12: * @author hengels
13: * @version $Revision$
14: */
15: public class CostTypeTreeNode extends GenericObjectTreeNode<CostType> {
16: public CostTypeTreeNode() {
17: }
18:
19: public CostTypeTreeNode(CostType object) {
20: this .object = object;
21: }
22:
23: @Override
24: protected void loadChildren() {
25: CostType costType = object;
26: if (costType == null || costType.getId() == null) {
27: children = new ArrayList<GenericObjectTreeNode>();
28: return;
29: }
30:
31: CostTypeTreeModel model = (CostTypeTreeModel) getModel();
32: InventoryLogic logic = model.getTreeLogic();
33: List<CostType> costTypes = logic.children(costType.getTree()
34: .getId(), costType.getId());
35:
36: children = new ArrayList<GenericObjectTreeNode>(costTypes
37: .size());
38: for (CostType childCostType : costTypes) {
39: CostTypeTreeNode child = new CostTypeTreeNode(childCostType);
40: children.add(child);
41: child.setParent(this );
42: }
43:
44: sortChildren();
45: }
46:
47: public boolean getAllowsChildren() {
48: return true;
49: }
50:
51: public boolean isLeaf() {
52: return false;
53: }
54:
55: public Class getObjectType() {
56: return CostType.class;
57: }
58:
59: public Class[] getChildTypes() {
60: return new Class[] { CostType.class };
61: }
62:
63: public CostType loadObject() {
64: CostType object = getObject();
65: if (object == null)
66: return null;
67:
68: LoadCommand loadCommand = (LoadCommand) ((CostTypeTreeModel) getModel())
69: .getPersistence().createCommand("load");
70: loadCommand.setType(CostType.class);
71: loadCommand.setId(object.getId());
72: object = (CostType) loadCommand.execute();
73: return object;
74: }
75: }
|