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.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  	public WsdlTestCase getTestCase()
    53  	{
    54  		return ( WsdlTestCase ) testCase;
    55  	}
    56
    57  	@Override
    58  	public void release()
    59  	{
    60  		super.release();
    61  		testCase.getTestSuite().removeTestSuiteListener( listener );
    62  	}
    63
    64  	public void updateLabel()
    65  	{
    66  		setName( createLabel( testCase ) );
    67  	}
    68
    69  	public class InternalTestSuiteListener extends TestSuiteListenerAdapter implements TestSuiteListener
    70  	{
    71  		@Override
    72  		public void testStepAdded( TestStep testStep, int index )
    73  		{
    74  			if( testStep.getTestCase() == testCase )
    75  				updateLabel();
    76  		}
    77
    78  		@Override
    79  		public void testStepRemoved( TestStep testStep, int index )
    80  		{
    81  			if( testStep.getTestCase() == testCase )
    82  				updateLabel();
    83  		}
    84
    85  		@Override
    86  		public void testCaseRemoved( TestCase testCase )
    87  		{
    88  			if( testCase == WsdlTestStepsModelItem.this.testCase )
    89  			{
    90  				testCase.getTestSuite().removeTestSuiteListener( listener );
    91  			}
    92  		}
    93  	}
    94
    95  }