View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 eviware.com
    3    *
    4    *  soapUI is free software; you can redistribute it and/or modify it under the
    5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
    6    *  the Free Software Foundation.
    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
    27  /***
    28   * SoapUITreeNode for TestSuite implementations
    29   *
    30   * @author Ole.Matzura
    31   */
    32
    33  public class TestSuiteTreeNode extends AbstractModelItemTreeNode<TestSuite>
    34  {
    35  	private InternalTestSuiteListener internalTestSuiteListener = new InternalTestSuiteListener();;
    36     private ReorderPropertyChangeListener propertyChangeListener = new ReorderPropertyChangeListener();
    37  	private List<TestCaseTreeNode> testCaseNodes = new ArrayList<TestCaseTreeNode>();
    38
    39  	public TestSuiteTreeNode(TestSuite testSuite, SoapUITreeModel treeModel )
    40     {
    41        super( testSuite, testSuite.getProject(), treeModel );
    42
    43  		testSuite.addTestSuiteListener( internalTestSuiteListener );
    44
    45  		for( int c = 0; c < testSuite.getTestCaseCount(); c++ )
    46  		{
    47  			TestCase testCase = testSuite.getTestCaseAt( c );
    48  			testCase.addPropertyChangeListener( TestCase.NAME_PROPERTY, propertyChangeListener );
    49  			testCaseNodes.add( new TestCaseTreeNode( testCase, getTreeModel() ));
    50  		}
    51
    52  		getTreeModel().mapModelItems( testCaseNodes );
    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( propertyChangeListener );
    64  			treeNode.release();
    65  		}
    66  	}
    67
    68     @Override
    69  	public int getChildCount()
    70  	{
    71  		return testCaseNodes.size();
    72  	}
    73
    74  	@Override
    75  	public SoapUITreeNode getChildNode( int index )
    76  	{
    77  		return testCaseNodes.get( index );
    78  	}
    79
    80  	@Override
    81  	public int getIndexOfChild( Object child )
    82  	{
    83  		return testCaseNodes.indexOf( child );
    84  	}
    85
    86  	public TestSuite getTestSuite()
    87     {
    88        return (TestSuite) getModelItem();
    89     }
    90
    91     private class InternalTestSuiteListener implements TestSuiteListener
    92     {
    93        public void testCaseAdded(TestCase testCase)
    94        {
    95        	TestCaseTreeNode testCaseTreeNode = new TestCaseTreeNode( testCase, getTreeModel() );
    96        	testCaseNodes.add( testCase.getTestSuite().getIndexOfTestCase(testCase), testCaseTreeNode );
    97
    98        	testCase.addPropertyChangeListener( TestCase.NAME_PROPERTY, propertyChangeListener );
    99        	getTreeModel().notifyNodeInserted( testCaseTreeNode );
    100       }
    101
    102       public void testCaseRemoved(TestCase testCase)
    103       {
    104       	SoapUITreeNode treeNode = getTreeModel().getTreeNode( testCase );
    105       	if( testCaseNodes.contains( treeNode ))
    106       	{
    107       		getTreeModel().notifyNodeRemoved( treeNode );
    108       		testCaseNodes.remove( treeNode );
    109       		testCase.removePropertyChangeListener(  propertyChangeListener );
    110       	}
    111       	else throw new RuntimeException( "Removing unknown TestCase" );
    112       }
    113
    114       public void testStepAdded(TestStep testStep, int index)
    115       {
    116       	TestCaseTreeNode testCaseTreeNode = (TestCaseTreeNode) getTreeModel().getTreeNode( testStep.getTestCase() );
    117       	testCaseTreeNode.testStepInserted( testStep, index );
    118       }
    119
    120       public void testStepRemoved(TestStep testStep, int index)
    121       {
    122       	TestCaseTreeNode testCaseTreeNode = (TestCaseTreeNode) getTreeModel().getTreeNode( testStep.getTestCase() );
    123       	testCaseTreeNode.testStepRemoved( testStep, index );
    124       }
    125
    126 		public void loadTestAdded(LoadTest loadTest)
    127 		{
    128       	TestCaseTreeNode testCaseTreeNode = (TestCaseTreeNode) getTreeModel().getTreeNode( loadTest.getTestCase() );
    129       	testCaseTreeNode.loadTestInserted( loadTest );
    130 		}
    131
    132 		public void loadTestRemoved(LoadTest loadTest)
    133 		{
    134       	TestCaseTreeNode testCaseTreeNode = (TestCaseTreeNode) getTreeModel().getTreeNode( loadTest.getTestCase() );
    135       	testCaseTreeNode.loadTestRemoved( loadTest );
    136 		}
    137
    138 		public void testStepMoved(TestStep testStep, int fromIndex, int offset)
    139 		{
    140       	TestCaseTreeNode testCaseTreeNode = (TestCaseTreeNode) getTreeModel().getTreeNode( testStep.getTestCase() );
    141       	testCaseTreeNode.testStepMoved( testStep, fromIndex, offset );
    142 		}
    143
    144 		public void testCaseMoved( TestCase testCase, int index, int offset )
    145 		{
    146 			testCaseRemoved( testCase );
    147 			testCaseAdded( testCase );
    148 		}
    149    }
    150 }