View Javadoc

1   /*
2    *  soapUI, copyright (C) 2006 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.model.tree.nodes;
14  
15  import java.util.ArrayList;
16  import java.util.List;
17  
18  import com.eviware.soapui.model.testsuite.LoadTest;
19  import com.eviware.soapui.model.testsuite.TestCase;
20  import com.eviware.soapui.model.testsuite.TestStep;
21  import com.eviware.soapui.model.testsuite.TestSuite;
22  import com.eviware.soapui.model.testsuite.TestSuiteListener;
23  import com.eviware.soapui.model.tree.AbstractModelItemTreeNode;
24  import com.eviware.soapui.model.tree.SoapUITreeModel;
25  import com.eviware.soapui.model.tree.SoapUITreeNode;
26  import com.eviware.soapui.settings.UISettings;
27  
28  /***
29   * SoapUITreeNode for TestSuite implementations
30   * 
31   * @author Ole.Matzura
32   */
33  
34  public class TestSuiteTreeNode extends AbstractModelItemTreeNode<TestSuite>
35  {
36  	private InternalTestSuiteListener internalTestSuiteListener = new InternalTestSuiteListener();;
37     private ReorderPropertyChangeListener propertyChangeListener = new ReorderPropertyChangeListener();
38  	private List<TestCaseTreeNode> testCaseNodes = new ArrayList<TestCaseTreeNode>();
39  
40  	public TestSuiteTreeNode(TestSuite testSuite, SoapUITreeModel treeModel )
41     {
42        super( testSuite, testSuite.getProject(), treeModel );
43        
44  		testSuite.addTestSuiteListener( internalTestSuiteListener );
45  		
46  		for( int c = 0; c < testSuite.getTestCaseCount(); c++ )
47  		{
48  			TestCase testCase = testSuite.getTestCaseAt( c );
49  			testCase.addPropertyChangeListener( TestCase.NAME_PROPERTY, propertyChangeListener );
50  			testCaseNodes.add( new TestCaseTreeNode( testCase, getTreeModel() ));
51  		}
52  		
53  		initOrdering( testCaseNodes, UISettings.ORDER_TESTCASES );
54  		
55  		getTreeModel().mapModelItems( testCaseNodes );
56     }
57  	
58  	public void release()
59  	{
60  		super.release();
61  		
62  		getTestSuite().removeTestSuiteListener( internalTestSuiteListener );
63  		
64  		for( TestCaseTreeNode treeNode : testCaseNodes )
65  			treeNode.release();
66  	}
67  	
68     public TestSuite getTestSuite()
69     {
70        return (TestSuite) getModelItem();
71     }
72     
73     private class InternalTestSuiteListener implements TestSuiteListener
74     {
75        public void testCaseAdded(TestCase testCase)
76        {
77        	TestCaseTreeNode testCaseTreeNode = new TestCaseTreeNode( testCase, getTreeModel() );
78        	testCaseNodes.add( testCaseTreeNode );
79        	reorder( false );
80        	
81        	testCase.addPropertyChangeListener( TestCase.NAME_PROPERTY, propertyChangeListener );
82        	getTreeModel().notifyNodeInserted( testCaseTreeNode );
83        }
84  
85        public void testCaseRemoved(TestCase testCase)
86        {
87        	SoapUITreeNode treeNode = getTreeModel().getTreeNode( testCase );
88        	if( testCaseNodes.contains( treeNode ))
89        	{
90        		getTreeModel().notifyNodeRemoved( treeNode );
91        		testCaseNodes.remove( treeNode );
92        		testCase.removePropertyChangeListener(  propertyChangeListener );
93        	}
94        	else throw new RuntimeException( "Removing unknown TestCase" );
95        }
96  
97        public void testStepAdded(TestStep testStep, int index)
98        {
99        	TestCaseTreeNode testCaseTreeNode = (TestCaseTreeNode) getTreeModel().getTreeNode( testStep.getTestCase() );
100       	testCaseTreeNode.testStepInserted( testStep, index );
101       }
102 
103       public void testStepRemoved(TestStep testStep, int index)
104       {
105       	TestCaseTreeNode testCaseTreeNode = (TestCaseTreeNode) getTreeModel().getTreeNode( testStep.getTestCase() );
106       	testCaseTreeNode.testStepRemoved( testStep, index );
107       }
108 
109 		public void loadTestAdded(LoadTest loadTest)
110 		{
111       	TestCaseTreeNode testCaseTreeNode = (TestCaseTreeNode) getTreeModel().getTreeNode( loadTest.getTestCase() );
112       	testCaseTreeNode.loadTestInserted( loadTest );
113 		}
114 
115 		public void loadTestRemoved(LoadTest loadTest)
116 		{
117       	TestCaseTreeNode testCaseTreeNode = (TestCaseTreeNode) getTreeModel().getTreeNode( loadTest.getTestCase() );
118       	testCaseTreeNode.loadTestRemoved( loadTest );
119 		}
120 
121 		public void testStepMoved(TestStep testStep, int fromIndex, int offset)
122 		{
123       	TestCaseTreeNode testCaseTreeNode = (TestCaseTreeNode) getTreeModel().getTreeNode( testStep.getTestCase() );
124       	testCaseTreeNode.testStepMoved( testStep, fromIndex, offset );
125 		}
126    }
127 }