Coverage details for net.sourceforge.demetrix.ui.ProcessChainNodeTreeModel

LineHitsSource
1 /*******************************************************************************
2  * Demetrix process modelling system
3  *
4  * Copyright (c) 2003, 2004 Dimitri A. Pissarenko
5  *
6  * This file is part of Demetrix.
7  *
8  * Demetrix is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
13  * Demetrix is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Demetrix; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  *
22  * For further information you may
23  *
24  * - send an e-mail in Russian, German or English to dimitri.pissarenko@gmx.net
25  * - look at http://sourceforge.net/projects/demetrix/
26  * - look at http://demetrix.sourceforge.net/
27  * - look at http://members.inode.at/d.pissarenko/
28  *
29  *****************************************************************************/
30 /*
31  * Created on 23.01.2004
32  */
33 package net.sourceforge.demetrix.ui;
34  
35 import java.util.Hashtable;
36 import java.util.Iterator;
37  
38 import javax.swing.tree.DefaultMutableTreeNode;
39 import javax.swing.tree.DefaultTreeModel;
40 import javax.swing.tree.TreeNode;
41  
42 import org.apache.log4j.Logger;
43  
44 import net.sourceforge.demetrix.model.ProcessChain;
45 import net.sourceforge.demetrix.model.ProcessChainNode;
46 import net.sourceforge.demetrix.model.Resource;
47 import net.sourceforge.demetrix.model.Task;
48  
49 /**
50  * @author Dimitri Pissarenko
51  *
52  */
53 public class ProcessChainNodeTreeModel extends DefaultTreeModel implements CurrentProcessChainObserver {
54     private Logger logger=Logger.getLogger(getClass());
55     private Hashtable treeNodesByUserObject;
56     public ProcessChainNodeTreeModel(DefaultMutableTreeNode root)
57     {
5817        super(null);
5917        this.setRoot(root);
6017        CurrentProcessChainSingleton.getInstance().attach(this);
6117    }
62  
63     private void addTaskSubGraphNodes(DefaultMutableTreeNode root, ProcessChain processChain)
64     {
6546        DefaultMutableTreeNode taskNode=null;
6646        DefaultMutableTreeNode resourceNode=null;
6746        Task task=null;
6846        Resource resource=null;
6946        Iterator tasks=null;
7046        Iterator resources=null;
71         
72  
7346        if (processChain!=null)
74         {
7534            tasks=processChain.getTasks().iterator();
7654            while (tasks.hasNext())
77             {
7820                task=(Task)tasks.next();
7920                taskNode=new DefaultMutableTreeNode(task);
8020                root.add(taskNode);
8120                this.treeNodesByUserObject.put(task, taskNode);
8220                this.addTaskSubGraphNodes(taskNode, (ProcessChain)task.getSubGraph());
83             }
8434            resources=processChain.getResources().iterator();
8551            while (resources.hasNext())
86             {
8717                resource=(Resource)resources.next();
8817                resourceNode=new DefaultMutableTreeNode(resource);
8917                root.add(resourceNode);
9017                this.treeNodesByUserObject.put(resource, resourceNode);
91             }
92         }
9346    }
94  
95     /* (non-Javadoc)
96      * @see net.sourceforge.demetrix.ui.CurrentProcessChainObserver#currentGraphParentChanged()
97      */
98     public void currentGraphParentChanged() {
9923        if (CurrentProcessChainSingleton.getInstance().isTopLevelProcessChain())
100         {
10115            if (this.getRoot()!=null)
102             {
10314                ((DefaultMutableTreeNode)this.getRoot()).removeAllChildren();
104             }
10515            this.setRoot(new DefaultMutableTreeNode(CurrentProcessChainSingleton.getInstance().getCurrentGraphParent()));
106         
107         }
10823    }
109     /* (non-Javadoc)
110      * @see javax.swing.tree.DefaultTreeModel#setRoot(javax.swing.tree.TreeNode)
111      */
112     public void setRoot(TreeNode rootNode) {
11332        Object userObject=null;
11432        ProcessChainNode processChainNode=null;
11532        ProcessChain taskSubGraph=null;
11632        DefaultMutableTreeNode root=null;
117  
11832        super.setRoot(rootNode);
11932        root=(DefaultMutableTreeNode)rootNode;
120     
12132        this.treeNodesByUserObject=new Hashtable();
12232        if (root==null)
123         {
1241            return;
125         }
126         
127         
12831        userObject=root.getUserObject();
12931        if (userObject!=null)
130         {
13128            this.treeNodesByUserObject.put(userObject, root);
13228            if (userObject instanceof ProcessChainNode)
133             {
13426                processChainNode=(ProcessChainNode)userObject;
13526                if (processChainNode instanceof Task)
136                 {
13726                    taskSubGraph=(ProcessChain)processChainNode.getSubGraph();
13826                    this.addTaskSubGraphNodes((DefaultMutableTreeNode)this.getRoot(), taskSubGraph);
139                 }
140             }
141         }
142         
14331    }
144     public void removeTreeNodeCorrespongingToUserObject(Object userObject)
145     {
1469        DefaultMutableTreeNode node=null;
1479        node=this.getTreeNodeByUserObject(userObject);
1489        if (node!=null)
149         {
1503            this.removeNodeFromParent(node);
1513            this.treeNodesByUserObject.remove(userObject);
152         }
1539    }
154     public DefaultMutableTreeNode getTreeNodeByUserObject(Object userObject)
155     {
156     
15775        return (DefaultMutableTreeNode)this.treeNodesByUserObject.get(userObject);
158     }
159 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.