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.impl.wsdl.actions.loadtest;
14  
15  import java.awt.event.ActionEvent;
16  
17  import javax.swing.AbstractAction;
18  import javax.swing.Action;
19  
20  import com.eviware.soapui.impl.wsdl.loadtest.WsdlLoadTest;
21  import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
22  import com.eviware.soapui.model.support.LoadTestRunListenerAdapter;
23  import com.eviware.soapui.model.testsuite.LoadTestRunContext;
24  import com.eviware.soapui.model.testsuite.LoadTestRunner;
25  import com.eviware.soapui.support.UISupport;
26  
27  /***
28   * Removes a WsdlLoadTest from its WsdlTestSuite
29   * 
30   * @author Ole.Matzura
31   */
32  
33  public class RemoveLoadTestAction extends AbstractAction
34  {
35  	private final WsdlLoadTest loadTest;
36  	private final InternalLoadTestRunListener internalLoadTestRunListener = new InternalLoadTestRunListener();
37  	
38  	public RemoveLoadTestAction( WsdlLoadTest loadTest )
39     {
40        super( "Remove" );
41  		this.loadTest = loadTest;
42        putValue( Action.SHORT_DESCRIPTION, "Removes this Test Schedule from the test-case" );
43        putValue( Action.ACCELERATOR_KEY, UISupport.getKeyStroke( "DELETE" ));
44        
45  		loadTest.addLoadTestRunListener( internalLoadTestRunListener);
46     }
47     
48     public void actionPerformed(ActionEvent e)
49  	{
50        if( UISupport.confirm( "Remove LoadTest [" + loadTest.getName() + "] from test-casee", "Remove LoadTest" ))
51        {
52        	((WsdlTestCase)loadTest.getTestCase()).removeLoadTest( loadTest );
53        }
54     }
55     
56     private final class InternalLoadTestRunListener extends LoadTestRunListenerAdapter
57  	{
58  		public void beforeLoadTest(LoadTestRunner loadTestRunner, LoadTestRunContext context)
59  		{
60  			setEnabled( false );
61  		}
62  
63  		public void afterLoadTest(LoadTestRunner loadTestRunner, LoadTestRunContext context)
64  		{
65  			setEnabled( true );
66  		}
67  	}
68  }