1 19 20 21 package ca.mcgill.sable.graph.testing; 22 import org.eclipse.ui.*; 23 import org.eclipse.jface.action.*; 24 import org.eclipse.jface.viewers.*; 25 import ca.mcgill.sable.graph.*; 26 import ca.mcgill.sable.graph.model.*; 27 import org.eclipse.core.runtime.*; 28 import java.util.*; 29 import java.lang.reflect.*; 30 31 32 public class GraphGenerator implements IWorkbenchWindowActionDelegate { 33 34 private ArrayList children = new ArrayList(); 35 private Graph graph; 36 37 38 public GraphGenerator() { 39 } 40 41 public void run(IAction action){ 42 IWorkbenchPage page = GraphPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage(); 43 try{ 44 setGraph(new Graph()); 45 IEditorPart part = page.openEditor(graph, "ca.mcgill.sable.graph.GraphEditor"); 46 handleChildren(); 47 } 48 catch (PartInitException e3){ 49 e3.printStackTrace(); 50 } 51 catch (Exception e2){ 52 e2.printStackTrace(); 53 } 54 } 55 56 public void buildModel(){ 57 58 GraphPlugin.getDefault().setGenerator(this); 59 TestNode p1 = new TestNode(); 60 p1.setData("P1"); 61 62 TestNode p2 = new TestNode(); 63 p2.setData("P2"); 64 65 66 p1.addOutput(p2); 67 68 TestNode c1 = new TestNode(); 69 TestNode c2 = new TestNode(); 70 TestNode c3 = new TestNode(); 71 72 p1.addChild(c1); 73 p1.addChild(c2); 74 p1.addChild(c3); 75 76 c1.addOutput(c2); 77 c1.addOutput(c3); 78 c1.addOutput(p2); 79 c3.addOutput(p2); 80 81 c1.setData("C1"); 82 c2.setData("C2"); 83 c3.setData("C3"); 84 85 TestNode c4 = new TestNode(); 86 TestNode c5 = new TestNode(); 87 p2.addChild(c4); 88 p2.addChild(c5); 89 90 c4.addOutput(c5); 91 c1.addOutput(c4); 92 c3.addOutput(c4); 93 p1.addOutput(c4); 94 95 c4.setData("C4"); 96 c5.setData("C5"); 97 98 99 getChildren().add(p1); 100 getChildren().add(p2); 101 102 handleChildren(); 103 } 104 105 HashMap map; 106 107 private void handleChildren(){ 108 getGraph().removeAllChildren(); 109 map = new HashMap(); 110 Iterator it = getChildren().iterator(); 111 while (it.hasNext()){ 112 TestNode tn = (TestNode)it.next(); 113 114 115 SimpleNode sn = new SimpleNode(); 116 getGraph().addChild(sn); 117 sn.setData(tn.getData()); 118 sn.setChildren(tn.getChildren()); 119 120 map.put(tn, sn); 121 } 122 123 Iterator it2 = getChildren().iterator(); 124 while (it2.hasNext()){ 125 TestNode tn = (TestNode)it2.next(); 126 127 128 SimpleNode src = (SimpleNode)map.get(tn); 129 Iterator eIt = tn.getOutputs().iterator(); 130 131 while (eIt.hasNext()){ 132 Object endTn = eIt.next(); 133 SimpleNode tgt = (SimpleNode)map.get(endTn); 134 if (tgt != null){ 135 Edge e = new Edge(src, tgt); 136 } 137 } 138 } 139 } 140 141 public void expandGraph(SimpleNode node){ 142 Iterator it = getChildren().iterator(); 143 TestNode tn = null; 144 while (it.hasNext()){ 145 tn = (TestNode)it.next(); 146 if (map.get(tn).equals(node)) break; 147 } 148 if (tn != null){ 149 if (tn.getChildren().size() > 0){ 150 getChildren().remove(tn); 151 } 152 } 153 Iterator childIt = node.getChildren().iterator(); 154 while (childIt.hasNext()){ 155 TestNode test = (TestNode)childIt.next(); 156 getChildren().add(test); 157 } 158 handleChildren(); 159 } 160 161 public void dispose(){ 162 } 163 164 public void selectionChanged(IAction action, ISelection sel){ 165 } 166 167 public void init(IWorkbenchWindow window){ 168 } 169 172 public ArrayList getChildren() { 173 return children; 174 } 175 176 179 public void setChildren(ArrayList list) { 180 children = list; 181 } 182 183 186 public Graph getGraph() { 187 return graph; 188 } 189 190 193 public void setGraph(Graph graph) { 194 this.graph = graph; 195 } 196 197 } 198 | Popular Tags |