001: package org.osbl.riskmanagement.gui.report;
002:
003: import org.osbl.client.wings.form.GenericObjectTreeNode;
004: import org.osbl.riskmanagement.model.Risk;
005: import org.osbl.riskmanagement.gui.RiskTypeTreeModel;
006: import org.osbl.persistence.LoadCommand;
007: import org.wingx.treetable.XTreeTableNode;
008:
009: import java.util.*;
010: import java.math.BigDecimal;
011:
012: /**
013: * Created by IntelliJ IDEA.
014: * User: hengels
015: * Date: Feb 15, 2007
016: * Time: 2:52:12 PM
017: * To change this template use File | Settings | File Templates.
018: */
019: public class RiskTreeTableNode extends GenericObjectTreeNode<Risk>
020: implements XTreeTableNode {
021: boolean expanded;
022: private int depth = -1;
023:
024: public RiskTreeTableNode() {
025: }
026:
027: public RiskTreeTableNode(Risk object) {
028: this .object = object;
029: }
030:
031: protected void loadChildren() {
032: children = Collections.EMPTY_LIST;
033: }
034:
035: public boolean getAllowsChildren() {
036: return false;
037: }
038:
039: public boolean isLeaf() {
040: return true;
041: }
042:
043: public Class getObjectType() {
044: return Risk.class;
045: }
046:
047: public Class[] getChildTypes() {
048: return new Class[] {};
049: }
050:
051: public Object getValueAt(int column) {
052: Risk risk = getObject();
053: BigDecimal coverage = risk.getCoverage();
054: BigDecimal amount = risk.getAmount();
055: BigDecimal probability = risk.getProbability();
056:
057: switch (column) {
058: case 0:
059: return risk.getKey();
060: case 1:
061: return amount;
062: case 2:
063: return probability;
064: case 3:
065: if (amount != null && probability != null)
066: return amount.multiply(probability).divide(
067: new BigDecimal(100));
068: else
069: return null;
070: case 4:
071: return coverage;
072: case 5:
073: return risk.getCriticality();
074:
075: default:
076: return null;
077: }
078: }
079:
080: public void setValueAt(Object value, int column) {
081: }
082:
083: public Class getNodeClass() {
084: return getObjectType();
085: }
086:
087: public boolean isExpanded() {
088: return expanded;
089: }
090:
091: public void setExpanded(boolean expanded) {
092: this .expanded = expanded;
093: }
094:
095: public int getDepth() {
096: if (depth < 0) {
097: XTreeTableNode parent = (XTreeTableNode) getParent();
098: depth = (parent != null) ? parent.getDepth() + 1 : 0;
099: }
100: return this .depth;
101: }
102:
103: public Risk loadObject() {
104: LoadCommand loadCommand = (LoadCommand) ((RiskTypeTreeModel) getModel())
105: .getPersistence().createCommand("revert");
106: Risk object = getObject();
107: loadCommand.setId(object.getId());
108: loadCommand.execute();
109: return object;
110: }
111: }
|