Coverage details for net.sourceforge.demetrix.model.SubGraphCreationHelper

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 22.01.2004
32  */
33 package net.sourceforge.demetrix.model;
34  
35 import java.util.Date;
36 import java.util.Iterator;
37 import java.util.LinkedHashSet;
38 import java.util.Set;
39  
40 import net.sourceforge.demetrix.ui.CurrentlySelectedNodeSingleton;
41  
42 import org._3pq.jgrapht.graph.ListenableDirectedGraph;
43 import org.apache.log4j.Logger;
44 import org.jgraph.JGraph;
45 import org.jgraph.graph.DefaultEdge;
46 import org.jgraph.graph.DefaultGraphCell;
47  
48 /**
49  * @author Dimitri Pissarenko
50  *
51  */
52 public class SubGraphCreationHelper {
53     private static SubGraphCreationHelper instance;
54     private Logger logger=Logger.getLogger(getClass());
55     private SubGraphCreationHelper()
561    {
571    }
58     public static SubGraphCreationHelper getInstance()
59     {
605        if (instance==null)
61         {
621            instance=new SubGraphCreationHelper();
63         }
645        return instance;
65     }
66     public void createSubGraph(ProcessChain graph, JGraph jgraph)
67     {
680        ListenableDirectedGraph subGraph=null;
690        Set vertexSet=null;
700        Set edgeSet=null;
710        Task newTask=null;
720        Iterator iterator=null;
730        Object[] nodes=null;
74         
75         
760        nodes=CurrentlySelectedNodeSingleton.getInstance().getCurrentlySelectedCells();
77         /**
78          * create a subgraph with selected graph objects
79          */
800        vertexSet=this.getVertexSet(nodes);
810        edgeSet=this.getEdgeSet(nodes);
820        subGraph=this.createTaskSubGraph(vertexSet, edgeSet);
83         
84         /**
85          * create a task in current graph and attach the subgraph to it
86          */
870        newTask=new Task();
880        newTask.getProperty("name").setValue("task " + new Date());
890        newTask.setSubGraph(subGraph);
900        graph.addTask(newTask);
91         
92         /**
93          * remove all those objects from current graph, which are part of the subgraph
94          */
950        iterator=edgeSet.iterator();
960        while (iterator.hasNext())
97         {
980            graph.removeLink((Link)iterator.next());
99         }
100  
1010        iterator=vertexSet.iterator();
1020        while (iterator.hasNext())
103         {
1040            graph.removeTaskOrResource(iterator.next());
105         }
1060    }
107     public ProcessChain createTaskSubGraph(Set vertexSubset, Set edgeSubset)
108     {
1091        ProcessChain subGraph=null;
1101        Iterator iterator=null;
1111        DefaultGraphCell cell=null;
1121        Object object=null;
1131        subGraph=new ProcessChain();
114         
1151        iterator=vertexSubset.iterator();
1163        while (iterator.hasNext())
117         {
1182            object=iterator.next();
1192            subGraph.addTaskOrResource((ProcessChainNode)object);
120         }
1211        iterator=edgeSubset.iterator();
1222        while (iterator.hasNext())
123         {
1241            object=iterator.next();
1251            subGraph.addLink((Link)object);
126         }
1271        return subGraph;
128     }
129     public Set getVertexSet(Object[] nodes)
130     {
1312        LinkedHashSet set=null;
1322        DefaultGraphCell cell=null;
1332        Object userObject=null;
134         
1352        set=new LinkedHashSet();
136         
1379        for (int i=0; i < nodes.length; i++)
138         {
1397            if (nodes[i] instanceof DefaultGraphCell)
140             {
1413                cell=(DefaultGraphCell)nodes[i];
1423                userObject=cell.getUserObject();
1433                if (userObject!=null)
144                 {
1453                    if (userObject instanceof ProcessChainNode)
146                     {
1472                        set.add(userObject);
148                     }
149                 }
150             }
1514            else if (!(nodes[i] instanceof Link))
152             {
1532                set.add(nodes[i]);
154             }
155         }
1562        return set;
157     }
158     public Set getEdgeSet(Object[] nodes)
159     {
1602        LinkedHashSet set=null;
1612        Object userObject=null;
162         
1632        set=new LinkedHashSet();
164         
1656        for (int i=0; i < nodes.length; i++)
166         {
1674            if (nodes[i] instanceof Link)
168             {
1691                set.add(nodes[i]);
170             }
1713            else if (nodes[i] instanceof DefaultEdge)
172             {
1731                userObject=((DefaultEdge)nodes[i]).getUserObject();
174                 
1751                if ((userObject!=null) && (userObject instanceof Link))
176                 {
1771                     set.add(userObject);
178                 }
179             }
180         }
181     
1822        return set;
183     }
184     
185 }

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.