1 19 package org.netbeans.test.editor.app.core; 20 21 import java.beans.*; 22 import java.util.Vector ; 23 24 import org.w3c.dom.Element ; 25 26 import java.beans.PropertyChangeListener ; 27 import java.beans.PropertyChangeEvent ; 28 import java.util.Set ; 30 import java.util.Vector ; 31 import java.util.Iterator ; 32 import java.util.Collections ; 33 import java.io.IOException ; 34 import java.io.InputStream ; 35 import java.net.URL ; 36 import java.lang.reflect.Constructor ; 37 import java.lang.reflect.InvocationTargetException ; 38 39 import java.beans.beancontext.BeanContext ; 40 41 import org.w3c.dom.Element ; 42 import java.util.Collection ; 43 import javax.swing.tree.TreeNode ; 44 import org.netbeans.test.editor.app.Main; 45 import org.netbeans.test.editor.app.core.actions.ActionRegistry; 46 import org.netbeans.test.editor.app.gui.actions.TreeNewType; 47 import org.netbeans.test.editor.app.gui.tree.TestGroupNodeDelegate; 48 import org.netbeans.test.editor.app.gui.tree.TestNodeDelegate; 49 import org.netbeans.test.editor.app.util.ParsingUtils; 50 51 56 public abstract class TestGroup extends TestNode { 57 58 public final static String CHANGE_CHILD = "Change child"; 59 public final static String REMOVE_CHILD = "Remove node"; 60 public final static String REMOVE_CHILDS = "Remove nodes"; 61 public final static String ADD_CHILD = "Add child"; 62 public final static String ADD_CHILDS = "Add childs"; 63 public final static String UP_CHILD = "Up child"; 64 public final static String DOWN_CHILD = "Down child"; 65 66 private Vector nodes; 67 private boolean performFinished = false; 68 69 70 public TestGroup(String name) { 71 super(name); 72 nodes=new Vector (); 73 registerNewTypes(); 74 } 75 76 public TestGroup(Element node) { 77 super(node); 78 nodes = new Vector (); 79 addNodes(ParsingUtils.loadSubNodes(node)); 80 registerNewTypes(); 81 } 82 83 public Element toXML(Element node) { 84 node = super.toXML(node); 85 return ParsingUtils.saveSubNodes(node, nodes); 86 } 87 88 public void addNode(TestNode node) { 89 node.owner = this; 90 nodes.add(node); 91 super.firePropertyChange(ADD_CHILD,null,node); 92 } 93 94 public void addNodes(TestNode[] n) { 95 for (int i=0;i < n.length;i++) { 96 nodes.add(n[i]); 97 n[i].owner=this; 98 } 99 firePropertyChange(ADD_CHILDS,null,n); 100 } 101 102 public void addNodes(Vector n) { 103 for (int i=0;i < n.size();i++) { 104 TestNode element = (TestNode) n.get(i); 105 nodes.add(element); 106 element.owner=this; 107 } 108 firePropertyChange(ADD_CHILDS,null,n.toArray(new TestNode[] {})); 109 } 110 111 public Vector getChildNodes() { 112 return nodes; 113 } 114 115 public TestNode get(int i) { 116 return (TestNode)nodes.elementAt(i); 117 } 118 119 public int getChildCount() { 120 return nodes.size(); 121 } 122 123 public TestNode remove(int i) { 124 TestNode result = (TestNode) nodes.remove(i); 125 firePropertyChange(REMOVE_CHILD,null,result); 126 return result; 127 } 128 129 public void remove(TestNode node) { 130 nodes.remove(node); 131 firePropertyChange(REMOVE_CHILD,null,node); 132 } 133 134 public void removeNodes(TestNode[] n) { 135 for (int i=0;i < n.length;i++) { 136 nodes.remove(n[i]); 137 } 138 firePropertyChange(REMOVE_CHILDS,null,n); 139 } 140 141 public void removeNodes(Vector n) { 142 for (int i=0;i < n.size();i++) { 143 TestNode element = (TestNode) n.get(i); 144 nodes.remove(element); 145 } 146 firePropertyChange(REMOVE_CHILDS,null,n.toArray(new TestNode[] {})); 147 } 148 149 public void removeAll() { 150 Vector old=nodes; 151 nodes=new Vector (); firePropertyChange(REMOVE_CHILDS,null,old.toArray(new TestNode[] {})); 153 } 154 155 public void upNode(TestNode n) { 156 TestNode upper; 157 158 for (int i=0;i < nodes.size();i++) { 159 if (((TestNode)nodes.get(i)) == n && i > 0) { 160 upper=(TestNode)(nodes.remove(i-1)); 161 nodes.insertElementAt(upper,i); 162 firePropertyChange(UP_CHILD,null,n); 163 break; 164 } 165 } 166 } 167 168 public void downNode(TestNode n) { 169 TestNode down; 170 for (int i=0;i < nodes.size();i++) { 171 if (((TestNode)nodes.get(i)) == n && i < nodes.size()-1) { 172 down=(TestNode)(nodes.remove(i+1)); 173 nodes.insertElementAt(down,i); 174 firePropertyChange(DOWN_CHILD,null,n); 175 break; 176 } 177 } 178 } 179 180 public TestNode[] getChilds() { 181 int i,c; 182 TestNode[] ret; 183 184 c=nodes.size(); 185 ret=new TestNode[c]; 186 for(i=0;i < c;i++) { 187 ret[i]=get(i); 188 } 189 return ret; 190 } 191 192 public boolean isParent() { 193 return true; 194 } 195 196 public void perform(String what) { 197 int point = what.indexOf('.'); 198 199 if (point == -1) { 200 for (int cntr = 0; cntr < getChildCount(); cntr++) { 202 final TestNode node = get(cntr); 203 performFinished = false; 204 205 if (node instanceof TestCallAction && node.getName().equals(what)) { 206 System.err.println("CallAction "+node.getName()+" is automatically performed."); 207 ((TestCallAction)node).performAndWait(); 208 System.err.println("CallAction "+node.getName()+" after performing."); 209 return; 210 } 211 } 212 System.err.println("Call action: " + what + " not found."); 213 return; 214 } 215 216 String step = what.substring(0, point); 217 218 for (int cntr = 0; cntr < getChildCount(); cntr++) { 219 TestNode node = get(cntr); 220 221 if (node instanceof TestGroup && node.getName().equals(step)) { 222 ((TestGroup)node).perform(what.substring(point + 1)); 223 return; 224 } 225 } 226 System.err.println("SubTest: " + step + " not found."); 227 } 228 229 public Vector getPerformedActions(String what) { 230 int point = what.indexOf('.'); 231 232 if (point == (-1)) { 233 for (int cntr = 0; cntr < getChildCount(); cntr++) { 235 final TestNode node = get(cntr); 236 performFinished = false; 237 238 if (node instanceof TestCallAction && node.getName().equals(what)) { 239 return ((TestCallAction)node).getPerformedActions(); 240 }; 241 }; 242 return null; 243 }; 244 String step = what.substring(0, point); 245 246 for (int cntr = 0; cntr < getChildCount(); cntr++) { 247 TestNode node = get(cntr); 248 if (node instanceof TestGroup && node.getName().equals(step)) { 249 return ((TestGroup)node).getPerformedActions(what.substring(point + 1)); 250 }; 251 }; 252 return null; 253 } 254 255 protected abstract void registerNewTypes(); 256 257 public static final void createNewTypes() { 258 ActionRegistry.getDefault().registerNewType(TestSubTest.class,new TreeNewType() { 259 public void create(TestGroup group) { 260 TestSubTest st; 261 if (Main.question("Create new Logger for new Sub Test?")) { 262 st=new TestSubTest(getNameCounter(),new Logger(Main.frame.getEditor())); 263 } else { 264 st=new TestSubTest(getNameCounter(),((Test)group).getLogger()); 265 } 266 group.addNode(st); 267 } 268 269 public String getName() { 270 return "Sub Test"; 271 } 272 273 public String getHelpCtx() { 274 return "Create new Sub Test (Test Suite)"; 275 } 276 }); 277 278 ActionRegistry.getDefault().registerNewType(TestStep.class,new TreeNewType() { 279 public void create(TestGroup group) { 280 group.addNode(new TestStep(getNameCounter())); 281 } 282 283 public String getName() { 284 return "Test Step"; 285 } 286 287 public String getHelpCtx() { 288 return "Add test step - test case."; 289 } 290 }); 291 292 ActionRegistry.getDefault().registerNewType(TestCallAction.class,new TreeNewType() { 293 public void create(TestGroup group) { 294 group.addNode(new TestCallAction(getNameCounter())); 295 } 296 297 public String getName() { 298 return "Call Action"; 299 } 300 301 public String getHelpCtx() { 302 return "Add Call action - test case definition."; 303 } 304 }); 305 306 ActionRegistry.getDefault().registerNewType(TestLogAction.class,new TreeNewType() { 307 public void create(TestGroup group) { 308 group.addNode(new TestLogAction(getNameCounter())); 309 } 310 311 public String getName() { 312 return "Log Action"; 313 } 314 315 public String getHelpCtx() { 316 return "Add Log Action (Action Event)"; 317 } 318 }); 319 320 ActionRegistry.getDefault().registerNewType(TestSetKitAction.class,new TreeNewType() { 321 public void create(TestGroup group) { 322 group.addNode(new TestSetKitAction(getNameCounter())); 323 } 324 325 public String getName() { 326 return "Set Kit Action"; 327 } 328 329 public String getHelpCtx() { 330 return "Add Editor Kit Setting Action"; 331 } 332 }); 333 ActionRegistry.getDefault().registerNewType(TestSetIEAction.class,new TreeNewType() { 334 public void create(TestGroup group) { 335 group.addNode(new TestSetIEAction(getNameCounter())); 336 } 337 338 public String getName() { 339 return "Set IE Action"; 340 } 341 342 public String getHelpCtx() { 343 return "Add Indentation Engine Setting Action"; 344 } 345 }); 346 ActionRegistry.getDefault().registerNewType(TestSetJavaIEAction.class,new TreeNewType() { 347 public void create(TestGroup group) { 348 group.addNode(new TestSetJavaIEAction(getNameCounter())); 349 } 350 351 public String getName() { 352 return "Set Java IE Action"; 353 } 354 355 public String getHelpCtx() { 356 return "Add Java Indentation Engine Setting Action"; 357 } 358 }); 359 ActionRegistry.getDefault().registerNewType(TestStringAction.class,new TreeNewType() { 360 public void create(TestGroup group) { 361 group.addNode(new TestStringAction(getNameCounter())); 362 } 363 364 public String getName() { 365 return "String Action"; 366 } 367 368 public String getHelpCtx() { 369 return "Add String Action - packed Lock Actions"; 370 } 371 }); 372 ActionRegistry.getDefault().registerNewType(TestCompletionAction.class,new TreeNewType() { 373 public void create(TestGroup group) { 374 group.addNode(new TestCompletionAction(getNameCounter())); 375 } 376 377 public String getName() { 378 return "Completion Action"; 379 } 380 381 public String getHelpCtx() { 382 return "Add Completion Action - invoked on completion panel."; 383 } 384 }); 385 ActionRegistry.getDefault().registerNewType(TestSetCompletionAction.class,new TreeNewType() { 386 public void create(TestGroup group) { 387 group.addNode(new TestSetCompletionAction(getNameCounter())); 388 } 389 390 public String getName() { 391 return "Set Completion Action"; 392 } 393 394 public String getHelpCtx() { 395 return "Add Set Completion Action."; 396 } 397 }); 398 ActionRegistry.getDefault().registerNewType(TestAddAbbreviationAction.class,new TreeNewType() { 399 public void create(TestGroup group) { 400 group.addNode(new TestAddAbbreviationAction(getNameCounter())); 401 } 402 403 public String getName() { 404 return "Add Abbreviation Action"; 405 } 406 407 public String getHelpCtx() { 408 return "Add New Abbreviation Action."; 409 } 410 }); 411 } 412 413 public TreeNode createNodeDelegate() { 414 TestGroupNodeDelegate ret=new TestGroupNodeDelegate(this); 415 TestNodeDelegate nd; 416 for (int i=0;i < nodes.size();i++) { 418 nd=(TestNodeDelegate)(((TestNode)(nodes.get(i))).getNodeDelegate()); 419 ret.add(nd); 420 } 421 return ret; 422 } 423 } | Popular Tags |