1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.model.tree.nodes;
14
15 import com.eviware.soapui.model.testsuite.*;
16 import com.eviware.soapui.model.tree.AbstractModelItemTreeNode;
17 import com.eviware.soapui.model.tree.SoapUITreeModel;
18 import com.eviware.soapui.model.tree.SoapUITreeNode;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 /***
24 * SoapUITreeNode for TestSuite implementations
25 *
26 * @author Ole.Matzura
27 */
28
29 public class TestSuiteTreeNode extends AbstractModelItemTreeNode<TestSuite>
30 {
31 private InternalTestSuiteListener internalTestSuiteListener = new InternalTestSuiteListener();;
32 private ReorderPropertyChangeListener propertyChangeListener = new ReorderPropertyChangeListener();
33 private List<TestCaseTreeNode> testCaseNodes = new ArrayList<TestCaseTreeNode>();
34 private PropertiesTreeNode<?> propertiesTreeNode;
35
36 public TestSuiteTreeNode(TestSuite testSuite, SoapUITreeModel treeModel )
37 {
38 super( testSuite, testSuite.getProject(), treeModel );
39
40 testSuite.addTestSuiteListener( internalTestSuiteListener );
41
42 for( int c = 0; c < testSuite.getTestCaseCount(); c++ )
43 {
44 TestCase testCase = testSuite.getTestCaseAt( c );
45 testCase.addPropertyChangeListener( TestCase.NAME_PROPERTY, propertyChangeListener );
46 testCaseNodes.add( new TestCaseTreeNode( testCase, getTreeModel() ));
47 }
48
49 getTreeModel().mapModelItems( testCaseNodes );
50
51 propertiesTreeNode = PropertiesTreeNode.createDefaultPropertiesNode( testSuite, getTreeModel() );
52 getTreeModel().mapModelItem( propertiesTreeNode );
53 }
54
55 public void release()
56 {
57 super.release();
58
59 getTestSuite().removeTestSuiteListener( internalTestSuiteListener );
60
61 for( TestCaseTreeNode treeNode : testCaseNodes )
62 {
63 treeNode.getModelItem().removePropertyChangeListener( TestCase.NAME_PROPERTY, propertyChangeListener );
64 treeNode.release();
65 }
66
67 propertiesTreeNode.release();
68 }
69
70 @Override
71 public int getChildCount()
72 {
73 int propMod = getTreeModel().isShowProperties() ? 1 : 0;
74 return testCaseNodes.size() + propMod;
75 }
76
77 @Override
78 public SoapUITreeNode getChildNode( int index )
79 {
80 int propMod = getTreeModel().isShowProperties() ? 1 : 0;
81 return index == 0 && propMod == 1 ? propertiesTreeNode : testCaseNodes.get( index-propMod );
82 }
83
84 @Override
85 public int getIndexOfChild( Object child )
86 {
87 int propMod = getTreeModel().isShowProperties() ? 1 : 0;
88 if( propMod == 1 && child == propertiesTreeNode )
89 return 0;
90
91 int ix = testCaseNodes.indexOf( child );
92 return ix == -1 ? ix : ix+propMod;
93 }
94
95 public TestSuite getTestSuite()
96 {
97 return (TestSuite) getModelItem();
98 }
99
100 private class InternalTestSuiteListener implements TestSuiteListener
101 {
102 public void testCaseAdded(TestCase testCase)
103 {
104 TestCaseTreeNode testCaseTreeNode = new TestCaseTreeNode( testCase, getTreeModel() );
105 testCaseNodes.add( testCase.getTestSuite().getIndexOfTestCase(testCase), testCaseTreeNode );
106
107 testCase.addPropertyChangeListener( TestCase.NAME_PROPERTY, propertyChangeListener );
108 getTreeModel().notifyNodeInserted( testCaseTreeNode );
109 }
110
111 public void testCaseRemoved(TestCase testCase)
112 {
113 SoapUITreeNode treeNode = getTreeModel().getTreeNode( testCase );
114 if( testCaseNodes.contains( treeNode ))
115 {
116 getTreeModel().notifyNodeRemoved( treeNode );
117 testCaseNodes.remove( treeNode );
118 testCase.removePropertyChangeListener( propertyChangeListener );
119 }
120 else throw new RuntimeException( "Removing unknown TestCase" );
121 }
122
123 public void testStepAdded(TestStep testStep, int index)
124 {
125 TestCaseTreeNode testCaseTreeNode = (TestCaseTreeNode) getTreeModel().getTreeNode( testStep.getTestCase() );
126 testCaseTreeNode.testStepInserted( testStep, index );
127 }
128
129 public void testStepRemoved(TestStep testStep, int index)
130 {
131 TestCaseTreeNode testCaseTreeNode = (TestCaseTreeNode) getTreeModel().getTreeNode( testStep.getTestCase() );
132 testCaseTreeNode.testStepRemoved( testStep, index );
133 }
134
135 public void loadTestAdded(LoadTest loadTest)
136 {
137 TestCaseTreeNode testCaseTreeNode = (TestCaseTreeNode) getTreeModel().getTreeNode( loadTest.getTestCase() );
138 testCaseTreeNode.loadTestInserted( loadTest );
139 }
140
141 public void loadTestRemoved(LoadTest loadTest)
142 {
143 TestCaseTreeNode testCaseTreeNode = (TestCaseTreeNode) getTreeModel().getTreeNode( loadTest.getTestCase() );
144 testCaseTreeNode.loadTestRemoved( loadTest );
145 }
146
147 public void testStepMoved(TestStep testStep, int fromIndex, int offset)
148 {
149 TestCaseTreeNode testCaseTreeNode = (TestCaseTreeNode) getTreeModel().getTreeNode( testStep.getTestCase() );
150 testCaseTreeNode.testStepMoved( testStep, fromIndex, offset );
151 }
152
153 public void testCaseMoved( TestCase testCase, int index, int offset )
154 {
155 testCaseRemoved( testCase );
156 testCaseAdded( testCase );
157 }
158 }
159 }