Line | Hits | Source |
---|---|---|
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 | { | |
58 | 17 | super(null); |
59 | 17 | this.setRoot(root); |
60 | 17 | CurrentProcessChainSingleton.getInstance().attach(this); |
61 | 17 | } |
62 | ||
63 | private void addTaskSubGraphNodes(DefaultMutableTreeNode root, ProcessChain processChain) | |
64 | { | |
65 | 46 | DefaultMutableTreeNode taskNode=null; |
66 | 46 | DefaultMutableTreeNode resourceNode=null; |
67 | 46 | Task task=null; |
68 | 46 | Resource resource=null; |
69 | 46 | Iterator tasks=null; |
70 | 46 | Iterator resources=null; |
71 | ||
72 | ||
73 | 46 | if (processChain!=null) |
74 | { | |
75 | 34 | tasks=processChain.getTasks().iterator(); |
76 | 54 | while (tasks.hasNext()) |
77 | { | |
78 | 20 | task=(Task)tasks.next(); |
79 | 20 | taskNode=new DefaultMutableTreeNode(task); |
80 | 20 | root.add(taskNode); |
81 | 20 | this.treeNodesByUserObject.put(task, taskNode); |
82 | 20 | this.addTaskSubGraphNodes(taskNode, (ProcessChain)task.getSubGraph()); |
83 | } | |
84 | 34 | resources=processChain.getResources().iterator(); |
85 | 51 | while (resources.hasNext()) |
86 | { | |
87 | 17 | resource=(Resource)resources.next(); |
88 | 17 | resourceNode=new DefaultMutableTreeNode(resource); |
89 | 17 | root.add(resourceNode); |
90 | 17 | this.treeNodesByUserObject.put(resource, resourceNode); |
91 | } | |
92 | } | |
93 | 46 | } |
94 | ||
95 | /* (non-Javadoc) | |
96 | * @see net.sourceforge.demetrix.ui.CurrentProcessChainObserver#currentGraphParentChanged() | |
97 | */ | |
98 | public void currentGraphParentChanged() { | |
99 | 23 | if (CurrentProcessChainSingleton.getInstance().isTopLevelProcessChain()) |
100 | { | |
101 | 15 | if (this.getRoot()!=null) |
102 | { | |
103 | 14 | ((DefaultMutableTreeNode)this.getRoot()).removeAllChildren(); |
104 | } | |
105 | 15 | this.setRoot(new DefaultMutableTreeNode(CurrentProcessChainSingleton.getInstance().getCurrentGraphParent())); |
106 | ||
107 | } | |
108 | 23 | } |
109 | /* (non-Javadoc) | |
110 | * @see javax.swing.tree.DefaultTreeModel#setRoot(javax.swing.tree.TreeNode) | |
111 | */ | |
112 | public void setRoot(TreeNode rootNode) { | |
113 | 32 | Object userObject=null; |
114 | 32 | ProcessChainNode processChainNode=null; |
115 | 32 | ProcessChain taskSubGraph=null; |
116 | 32 | DefaultMutableTreeNode root=null; |
117 | ||
118 | 32 | super.setRoot(rootNode); |
119 | 32 | root=(DefaultMutableTreeNode)rootNode; |
120 | ||
121 | 32 | this.treeNodesByUserObject=new Hashtable(); |
122 | 32 | if (root==null) |
123 | { | |
124 | 1 | return; |
125 | } | |
126 | ||
127 | ||
128 | 31 | userObject=root.getUserObject(); |
129 | 31 | if (userObject!=null) |
130 | { | |
131 | 28 | this.treeNodesByUserObject.put(userObject, root); |
132 | 28 | if (userObject instanceof ProcessChainNode) |
133 | { | |
134 | 26 | processChainNode=(ProcessChainNode)userObject; |
135 | 26 | if (processChainNode instanceof Task) |
136 | { | |
137 | 26 | taskSubGraph=(ProcessChain)processChainNode.getSubGraph(); |
138 | 26 | this.addTaskSubGraphNodes((DefaultMutableTreeNode)this.getRoot(), taskSubGraph); |
139 | } | |
140 | } | |
141 | } | |
142 | ||
143 | 31 | } |
144 | public void removeTreeNodeCorrespongingToUserObject(Object userObject) | |
145 | { | |
146 | 9 | DefaultMutableTreeNode node=null; |
147 | 9 | node=this.getTreeNodeByUserObject(userObject); |
148 | 9 | if (node!=null) |
149 | { | |
150 | 3 | this.removeNodeFromParent(node); |
151 | 3 | this.treeNodesByUserObject.remove(userObject); |
152 | } | |
153 | 9 | } |
154 | public DefaultMutableTreeNode getTreeNodeByUserObject(Object userObject) | |
155 | { | |
156 | ||
157 | 75 | return (DefaultMutableTreeNode)this.treeNodesByUserObject.get(userObject); |
158 | } | |
159 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |