View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 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.support;
14  
15  import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
16  import com.eviware.soapui.model.settings.Settings;
17  import com.eviware.soapui.model.support.TestSuiteListenerAdapter;
18  import com.eviware.soapui.model.testsuite.TestCase;
19  import com.eviware.soapui.model.testsuite.TestStep;
20  import com.eviware.soapui.model.testsuite.TestSuiteListener;
21  import com.eviware.soapui.support.UISupport;
22  
23  /***
24   * ModelItem for TestSteps node
25   * 
26   * @author ole.matzura
27   */
28  
29  public class WsdlTestStepsModelItem extends EmptyModelItem
30  {
31  	private TestCase testCase;
32  	private TestSuiteListener listener = new InternalTestSuiteListener();
33  	
34  	public WsdlTestStepsModelItem( TestCase testCase )
35  	{
36  		super( createLabel( testCase ),  UISupport.createImageIcon("/teststeps.gif") );
37  		this.testCase = testCase;
38  		
39  		testCase.getTestSuite().addTestSuiteListener( listener );
40  	}
41  
42  	private static String createLabel( TestCase testCase )
43  	{
44  		return "Test Steps (" + testCase.getTestStepCount() + ")";
45  	}
46  
47  	public Settings getSettings()
48  	{
49  		return testCase.getSettings();
50  	}
51  	
52  	@Override
53  	public String getName()
54  	{
55  		return createLabel(testCase);
56  	}
57  
58  	public WsdlTestCase getTestCase()
59  	{
60  		return ( WsdlTestCase ) testCase;
61  	}
62  	
63  	@Override
64  	public void release()
65  	{
66  		super.release();
67  		testCase.getTestSuite().removeTestSuiteListener( listener );
68  	}
69  	
70  	public void updateLabel()
71  	{
72  		setName( createLabel( testCase ) ); 
73  	}
74  	
75  	public class InternalTestSuiteListener extends TestSuiteListenerAdapter implements TestSuiteListener
76  	{
77  		@Override
78  		public void testStepAdded( TestStep testStep, int index )
79  		{
80  			if( testStep.getTestCase() == testCase )
81  				updateLabel();
82  		}
83  		
84  		@Override
85  		public void testStepRemoved( TestStep testStep, int index )
86  		{
87  			if( testStep.getTestCase() == testCase )
88  				updateLabel();
89  		}
90  		
91  		@Override
92  		public void testCaseRemoved( TestCase testCase )
93  		{
94  			if( testCase == WsdlTestStepsModelItem.this.testCase )
95  			{
96  				testCase.getTestSuite().removeTestSuiteListener( listener );
97  			}
98  		}
99  	}
100 	
101 }