RiskTypeTreeNode.java :  » Workflow-Engines » osbl-1_0 » org » osbl » riskmanagement » gui » Java Open Source

Java Open Source » Workflow Engines » osbl 1_0 
osbl 1_0 » org » osbl » riskmanagement » gui » RiskTypeTreeNode.java
package org.osbl.riskmanagement.gui;

import org.osbl.client.wings.form.GenericObjectTreeNode;
import org.osbl.riskmanagement.logic.RiskManagementLogic;
import org.osbl.riskmanagement.model.RiskType;
import org.osbl.persistence.LoadCommand;

import java.util.ArrayList;
import java.util.List;

/**
 * @author hengels
 * @version $Revision$
 */
public class RiskTypeTreeNode
    extends GenericObjectTreeNode<RiskType>
{
    public RiskTypeTreeNode() {
    }

    public RiskTypeTreeNode(RiskType object) {
        this.object = object;
    }

    protected void loadChildren() {
        RiskType riskType = object;
        if (riskType == null || riskType.getId() == null) {
            children = new ArrayList<GenericObjectTreeNode>();
            return;
        }

        RiskTypeTreeModel model = (RiskTypeTreeModel)getModel();
        RiskManagementLogic logic = model.getTreeLogic();
        List<RiskType> riskTypes = logic.children(riskType.getTree().getId(), riskType.getId());

        children = new ArrayList<GenericObjectTreeNode>(riskTypes.size());
        for (RiskType childRiskType : riskTypes) {
            RiskTypeTreeNode child = new RiskTypeTreeNode(childRiskType);
            children.add(child);
            child.setParent(this);
        }

        sortChildren();
    }

    public boolean getAllowsChildren() {
        return true;
    }

    public boolean isLeaf() {
        return false;
    }

    public Class getObjectType() {
        return RiskType.class;
    }

    public Class[] getChildTypes() {
        return new Class[] { RiskType.class };
    }

    public RiskType loadObject() {
        RiskType object = getObject();
        LoadCommand loadCommand = (LoadCommand)((RiskTypeTreeModel)getModel()).getPersistence().createCommand("load");
        loadCommand.setType(RiskType.class);
        loadCommand.setId(object.getId());
        object = (RiskType)loadCommand.execute();
        return object;
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.