| 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 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() | |
| 56 | 1 | { |
| 57 | 1 | } |
| 58 | public static SubGraphCreationHelper getInstance() | |
| 59 | { | |
| 60 | 5 | if (instance==null) |
| 61 | { | |
| 62 | 1 | instance=new SubGraphCreationHelper(); |
| 63 | } | |
| 64 | 5 | return instance; |
| 65 | } | |
| 66 | public void createSubGraph(ProcessChain graph, JGraph jgraph) | |
| 67 | { | |
| 68 | 0 | ListenableDirectedGraph subGraph=null; |
| 69 | 0 | Set vertexSet=null; |
| 70 | 0 | Set edgeSet=null; |
| 71 | 0 | Task newTask=null; |
| 72 | 0 | Iterator iterator=null; |
| 73 | 0 | Object[] nodes=null; |
| 74 | ||
| 75 | ||
| 76 | 0 | nodes=CurrentlySelectedNodeSingleton.getInstance().getCurrentlySelectedCells(); |
| 77 | /** | |
| 78 | * create a subgraph with selected graph objects | |
| 79 | */ | |
| 80 | 0 | vertexSet=this.getVertexSet(nodes); |
| 81 | 0 | edgeSet=this.getEdgeSet(nodes); |
| 82 | 0 | subGraph=this.createTaskSubGraph(vertexSet, edgeSet); |
| 83 | ||
| 84 | /** | |
| 85 | * create a task in current graph and attach the subgraph to it | |
| 86 | */ | |
| 87 | 0 | newTask=new Task(); |
| 88 | 0 | newTask.getProperty("name").setValue("task " + new Date()); |
| 89 | 0 | newTask.setSubGraph(subGraph); |
| 90 | 0 | graph.addTask(newTask); |
| 91 | ||
| 92 | /** | |
| 93 | * remove all those objects from current graph, which are part of the subgraph | |
| 94 | */ | |
| 95 | 0 | iterator=edgeSet.iterator(); |
| 96 | 0 | while (iterator.hasNext()) |
| 97 | { | |
| 98 | 0 | graph.removeLink((Link)iterator.next()); |
| 99 | } | |
| 100 | ||
| 101 | 0 | iterator=vertexSet.iterator(); |
| 102 | 0 | while (iterator.hasNext()) |
| 103 | { | |
| 104 | 0 | graph.removeTaskOrResource(iterator.next()); |
| 105 | } | |
| 106 | 0 | } |
| 107 | public ProcessChain createTaskSubGraph(Set vertexSubset, Set edgeSubset) | |
| 108 | { | |
| 109 | 1 | ProcessChain subGraph=null; |
| 110 | 1 | Iterator iterator=null; |
| 111 | 1 | DefaultGraphCell cell=null; |
| 112 | 1 | Object object=null; |
| 113 | 1 | subGraph=new ProcessChain(); |
| 114 | ||
| 115 | 1 | iterator=vertexSubset.iterator(); |
| 116 | 3 | while (iterator.hasNext()) |
| 117 | { | |
| 118 | 2 | object=iterator.next(); |
| 119 | 2 | subGraph.addTaskOrResource((ProcessChainNode)object); |
| 120 | } | |
| 121 | 1 | iterator=edgeSubset.iterator(); |
| 122 | 2 | while (iterator.hasNext()) |
| 123 | { | |
| 124 | 1 | object=iterator.next(); |
| 125 | 1 | subGraph.addLink((Link)object); |
| 126 | } | |
| 127 | 1 | return subGraph; |
| 128 | } | |
| 129 | public Set getVertexSet(Object[] nodes) | |
| 130 | { | |
| 131 | 2 | LinkedHashSet set=null; |
| 132 | 2 | DefaultGraphCell cell=null; |
| 133 | 2 | Object userObject=null; |
| 134 | ||
| 135 | 2 | set=new LinkedHashSet(); |
| 136 | ||
| 137 | 9 | for (int i=0; i < nodes.length; i++) |
| 138 | { | |
| 139 | 7 | if (nodes[i] instanceof DefaultGraphCell) |
| 140 | { | |
| 141 | 3 | cell=(DefaultGraphCell)nodes[i]; |
| 142 | 3 | userObject=cell.getUserObject(); |
| 143 | 3 | if (userObject!=null) |
| 144 | { | |
| 145 | 3 | if (userObject instanceof ProcessChainNode) |
| 146 | { | |
| 147 | 2 | set.add(userObject); |
| 148 | } | |
| 149 | } | |
| 150 | } | |
| 151 | 4 | else if (!(nodes[i] instanceof Link)) |
| 152 | { | |
| 153 | 2 | set.add(nodes[i]); |
| 154 | } | |
| 155 | } | |
| 156 | 2 | return set; |
| 157 | } | |
| 158 | public Set getEdgeSet(Object[] nodes) | |
| 159 | { | |
| 160 | 2 | LinkedHashSet set=null; |
| 161 | 2 | Object userObject=null; |
| 162 | ||
| 163 | 2 | set=new LinkedHashSet(); |
| 164 | ||
| 165 | 6 | for (int i=0; i < nodes.length; i++) |
| 166 | { | |
| 167 | 4 | if (nodes[i] instanceof Link) |
| 168 | { | |
| 169 | 1 | set.add(nodes[i]); |
| 170 | } | |
| 171 | 3 | else if (nodes[i] instanceof DefaultEdge) |
| 172 | { | |
| 173 | 1 | userObject=((DefaultEdge)nodes[i]).getUserObject(); |
| 174 | ||
| 175 | 1 | if ((userObject!=null) && (userObject instanceof Link)) |
| 176 | { | |
| 177 | 1 | set.add(userObject); |
| 178 | } | |
| 179 | } | |
| 180 | } | |
| 181 | ||
| 182 | 2 | return set; |
| 183 | } | |
| 184 | ||
| 185 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |