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.project;
14  
15  import java.awt.event.ActionEvent;
16  import java.io.IOException;
17  
18  import javax.swing.AbstractAction;
19  import javax.swing.Action;
20  
21  import com.eviware.soapui.SoapUI;
22  import com.eviware.soapui.impl.wsdl.WsdlProject;
23  import com.eviware.soapui.model.testsuite.TestSuite;
24  import com.eviware.soapui.support.UISupport;
25  
26  /***
27   * Removes a WsdlProject from the workspace
28   * 
29   * @author Ole.Matzura
30   */
31  
32  public class RemoveProjectAction extends AbstractAction
33  {
34     private final WsdlProject project;
35  
36  	public RemoveProjectAction( WsdlProject project)
37     {
38        super( "Remove" );
39  		this.project = project;
40        putValue( Action.SHORT_DESCRIPTION, "Removes this project from the workspace" );
41        putValue( Action.ACCELERATOR_KEY, UISupport.getKeyStroke( "DELETE" ));
42     }
43     
44     public void actionPerformed(ActionEvent e)
45  	{
46     	if( hasRunningTests())
47     	{
48     		UISupport.showErrorMessage( "Cannot remove Interface due to running tests" );
49     		return;
50     	}
51     	
52     	Boolean retval = UISupport.confirmOrCancel( "Save project [" + project.getName() + "] before removing?", "Remove Project" );
53     	if( retval == null )
54     		return;
55     	
56     	if( retval.booleanValue() )
57        {
58           try
59  			{
60  				project.save();
61  			}
62  			catch( IOException e1 )
63  			{
64  				UISupport.showErrorMessage( e1 );
65  			}
66        }
67  
68        project.getWorkspace().removeProject( project );
69     }
70  
71  	private boolean hasRunningTests()
72  	{
73  		for( int c = 0; c < project.getTestSuiteCount(); c++ )
74  		{
75  			TestSuite testSuite = project.getTestSuiteAt( c );
76  			for( int i = 0; i < testSuite.getTestCaseCount(); i++ )
77  			{
78  				if( SoapUI.getTestMonitor().hasRunningTest( testSuite.getTestCaseAt( i )))
79  				{
80  					return true;
81  				}
82  			}
83  		}
84  
85  		return false;
86  	}
87  }