1 package junit.swingui; 2 3 import java.util.Vector ; 4 5 import javax.swing.Icon ; 6 import javax.swing.JTabbedPane ; 7 import javax.swing.JTree ; 8 import javax.swing.event.TreeSelectionEvent ; 9 import javax.swing.event.TreeSelectionListener ; 10 import javax.swing.tree.TreePath ; 11 12 import junit.framework.Test; 13 import junit.framework.TestResult; 14 15 20 public class TestHierarchyRunView implements TestRunView { 21 TestSuitePanel fTreeBrowser; 22 TestRunContext fTestContext; 23 24 public TestHierarchyRunView(TestRunContext context) { 25 fTestContext= context; 26 fTreeBrowser= new TestSuitePanel(); 27 fTreeBrowser.getTree().addTreeSelectionListener( 28 new TreeSelectionListener () { 29 public void valueChanged(TreeSelectionEvent e) { 30 testSelected(); 31 } 32 } 33 ); 34 } 35 36 public void addTab(JTabbedPane pane) { 37 Icon treeIcon= TestRunner.getIconResource(getClass(), "icons/hierarchy.gif"); 38 pane.addTab("Test Hierarchy", treeIcon, fTreeBrowser, "The test hierarchy"); 39 } 40 41 public Test getSelectedTest() { 42 return fTreeBrowser.getSelectedTest(); 43 } 44 45 public void activate() { 46 testSelected(); 47 } 48 49 public void revealFailure(Test failure) { 50 JTree tree= fTreeBrowser.getTree(); 51 TestTreeModel model= (TestTreeModel)tree.getModel(); 52 Vector vpath= new Vector (); 53 int index= model.findTest(failure, (Test)model.getRoot(), vpath); 54 if (index >= 0) { 55 Object [] path= new Object [vpath.size()+1]; 56 vpath.copyInto(path); 57 Object last= path[vpath.size()-1]; 58 path[vpath.size()]= model.getChild(last, index); 59 TreePath selectionPath= new TreePath (path); 60 tree.setSelectionPath(selectionPath); 61 tree.makeVisible(selectionPath); 62 } 63 } 64 65 public void aboutToStart(Test suite, TestResult result) { 66 fTreeBrowser.showTestTree(suite); 67 result.addListener(fTreeBrowser); 68 } 69 70 public void runFinished(Test suite, TestResult result) { 71 result.removeListener(fTreeBrowser); 72 } 73 74 protected void testSelected() { 75 fTestContext.handleTestSelected(getSelectedTest()); 76 } 77 } 78 | Popular Tags |